JAVA basics

Descripción

Introductory JAVA concepts
Joseph Jimenez
Test por Joseph Jimenez, actualizado hace más de 1 año
Joseph Jimenez
Creado por Joseph Jimenez hace más de 7 años
165
1

Resumen del Recurso

Pregunta 1

Pregunta
System.out.println or next.Int( ) or close( ) are examples of:
Respuesta
  • syntax
  • variable
  • method
  • object

Pregunta 2

Pregunta
In the following sample code, how do you best describe the "Scanner": public class squares { public static void main(String[] args) { java.util.Scanner scanner = new java.util.Scanner(System.in); int num = 0; System.out.print("Please enter a number: "); num = scanner.nextInt(); scanner.close();
Respuesta
  • statement
  • method
  • object
  • argument

Pregunta 3

Pregunta
In the sample code below, what best describes num ? public static void main(String[] args) { java.util.Scanner scanner = new java.util.Scanner(System.in); int num = 0; int result = 0; System.out.print("Please enter a number: "); num = scanner.nextInt(); result = num * num; scanner.close(); } }
Respuesta
  • string
  • statement
  • variable
  • object

Pregunta 4

Pregunta
All is (are) true of pseudocode except:
Respuesta
  • comments that are understood by people
  • recognized by the compiler
  • a tool programmers use when creating a model of the program

Pregunta 5

Pregunta
string literals. – char literals are enclosed in [blank_start]single[blank_end] quotes. - [blank_start]String[blank_end] literals are enclosed in double quotes
Respuesta
  • single
  • String

Pregunta 6

Pregunta
How do you assign a variable?
Respuesta
  • use an = sign
  • In order to store a value in a variable, an assignment statement must be used
  • Both are correct

Pregunta 7

Pregunta
This program asks to simply input a word or "string" and the output is the first character of the word (so an input of agents, the program's output is "a") java.util.Scanner scanner = [blank_start]new java.util.Scanner(System.in);[blank_end] [blank_start]System.out.print[blank_end]("Enter a character: "); char inputChar = [blank_start]scanner.next().charAt(0);[blank_end] System.out.println("You have entered: "+inputChar); [blank_start]scanner.close();[blank_end]
Respuesta
  • new java.util.Scanner(System.in);
  • System.out.print
  • scanner.next().charAt(0);
  • scanner.close();

Pregunta 8

Pregunta
What is wrong with the following code: System.out.println("The quick brown fox" + "jumped over the \n" "slow moving hen.");
Respuesta
  • there are extra " " between \n and slow
  • use of the "+" is not correct
  • nothing is wrong with the code and should print "jump over the \n slow moving hen

Pregunta 9

Pregunta
which is NOT a valid statement
Respuesta
  • */comment 3/*
  • //comment 1
  • /**comment 4*/

Pregunta 10

Pregunta
Which of the following will fix the code below: final int x = 22, y = 4; y += x; System.out.println("x = " + x + ", y = " + y);
Respuesta
  • change y+=x; to y = y + x
  • remove "final" because this makes the "int x" a constant
  • nothing is wrong with the code

Pregunta 11

Pregunta
How can you output quotation marks around green ("green") in the System.out.println() method:
Respuesta
  • System.out.println("\green\")
  • System.out.println(\"green\")
  • System.out.println(\\"green"\\)

Pregunta 12

Pregunta
In the JAVA language, fill in what best coincides with the given term Classes: [blank_start]PascalCase[blank_end] [blank_start]Methods/Variables[blank_end]: camelCase [blank_start]Constants[blank_end]: CAPS_UNDERSCORE
Respuesta
  • PascalCase
  • Methods/Variables
  • Constants

Pregunta 13

Pregunta
How do you define a method?
Respuesta
  • public.java.util.scanner = scanner()
  • public returnType methodName(arg1Type, arg2Type,...) { }
  • import java util.*;

Pregunta 14

Pregunta
In the following code, System.out.println(num) is an example of: double num = 5.4; System.out.println(num); num = 0.0;
Respuesta
  • class method
  • value returning method
  • void method

Pregunta 15

Pregunta
If method A calls method B, and method B calls method C, and method C calls method D, when method D finishes, what happens?
Respuesta
  • the program terminates
  • control is returned to C
  • control is returned to A

Pregunta 16

Pregunta
When an argument is passed to a method:
Respuesta
  • values may not be passed to the method
  • its value is copied into the method's parameter variable
  • its value may not be changed within the call method

Pregunta 17

Pregunta
In the following code, Integer.parseInt(str), is an example of: int num; string str = "555"; num = Integer.parseInt(str) + 5;
Respuesta
  • void method
  • value returning method
  • complex method

Pregunta 18

Pregunta
If chr is a character variable, which of the following if statements is written correctly?
Respuesta
  • if(char = 'a')
  • if (char == 'a')
  • If(char=="a")

Pregunta 19

Pregunta
[blank_start]Short-circuit evaluation[blank_end] works like this: If the expression on the left side of the && operator is false, the expression the right side will not be checked.
Respuesta
  • Short-circuit evaluation

Pregunta 20

Pregunta
To do a case insensitive compare which of the following could be used to test the equality of two strings, str1 and str2?
Respuesta
  • str1.equalsIgnoreCase(str2)
  • str1.compareToIgnoreCase(str2) == 0
  • Both

Pregunta 21

Pregunta
What would be the value of x after the following statements were executed? int x = 10; switch (x) { case 10: x += 15; case 12: x -= 5; break; default: x *= 3; }
Respuesta
  • 20
  • 30
  • 15

Pregunta 22

Pregunta
What will be displayed to the screen with the following statements? System.out.print("$%,.4f", 4452.34246);
Respuesta
  • $4,452.34246
  • 4452.34246

Pregunta 23

Pregunta
What will be the value of x after the following code is executed? If the code has any kind of syntax error, please type in the answer “error”. int x = 10 if (x>5) { x /= 10; } if (x<5) { x += 5; } if (x > 10) { x -=4; } else { x+=4; }
Respuesta
  • 10
  • 0
  • 12

Pregunta 24

Pregunta
An if statement's alternative path is implemented with _______.
Respuesta
  • switch
  • else
  • if

Pregunta 25

Pregunta
The part of a method that is a collection of statements that are performed when the method is executed is called the method _______.
Respuesta
  • body
  • arguments

Pregunta 26

Pregunta
When a primitive data type argument is passed to a method, it is passed by _______.
Respuesta
  • reference
  • value

Pregunta 27

Pregunta
When an object, such as a String, is passed as an argument, it is passed by
Respuesta
  • value
  • reference

Pregunta 28

Pregunta
What will be the values of x and y as a result of the following code? int x = 25, y = 8; x += y++;
Respuesta
  • x = 33; y = 9
  • x=34; y = 9

Pregunta 29

Pregunta
What will be printed after the following code is executed? for (int number = 5; number <= 15; number +=3) System.out.print(number + ", ");
Respuesta
  • 5, 8, 11, 14, 17
  • 5, 8, 11, 14

Pregunta 30

Pregunta
UML diagrams does contain
Respuesta
  • field names
  • object names

Pregunta 31

Pregunta
Unified Modeling Language which is used in object oriented software engineering.
Respuesta
  • using the private access specifier on the class methods
  • using the private access specifier on the class fields

Pregunta 32

Pregunta
You should not define a class field that is dependent upon the values of other class fields:
Respuesta
  • in order to avoid having stale data
  • in order to keep it current

Pregunta 33

Pregunta
Instance methods do not have this key word in their headers:
Respuesta
  • public
  • protected
  • static

Pregunta 34

Pregunta
It is common practice to use a ________ variable as a size declarator
Respuesta
  • reference
  • final

Pregunta 35

Pregunta
What will be the value of x[8] after the following code has been executed? final int SUB = 12; int[] x = new int[SUB]; int y = 100; for(int i = 0; i < SUB; i++) { x[i] = y; y += 10; }
Respuesta
  • 200
  • 170
  • 180

Pregunta 36

Pregunta
Java performs ________, which means that it does not allow a statement to use a subscript that is outside the range of valid subscripts for the array.
Respuesta
  • array bounds checking
  • scope resolution binding

Pregunta 37

Pregunta
What will be the results of the following code? final int ARRAY_SIZE = 5; double[] x = new double[ARRAY_SIZE]; for(int i = 1; i <= ARRAY_SIZE; i++) { x[i] = 10.0; }
Respuesta
  • compilation error will occur
  • An error will occur when the program runs

Pregunta 38

Pregunta
What would be the results of the following code? int[] x = { 55, 33, 88, 22, 99, 11, 44, 66, 77 }; int a = 10; if(x[2] > x[5]) a = 5; else a = 8;
Respuesta
  • a=5
  • a=8

Pregunta 39

Pregunta
What would be the results of the following code? int[] array1 = new int[25]; … // Code that will put values in array1 int value = array1[0]; for (int a = 1; a < array1.length; a++) { if (array1[a] < value) value = array1[a]; }
Respuesta
  • Value contains the highest value in array1.
  • Value contains the lowest value in array1

Pregunta 40

Pregunta
What do you normally use with a partially-filled array?
Respuesta
  • An accompanying integer value that holds the number of items stored in the array
  • An accumulator

Pregunta 41

Pregunta
To return an array of long values from a method, use this as the return type for the method.
Respuesta
  • long[ARRAY_SIZE]
  • long[]

Pregunta 42

Pregunta
In order to do a binary search on an array:
Respuesta
  • the array must first be sorted in ascending order
  • there are no requirements

Pregunta 43

Pregunta
What is the value of scores[2][3] in the following array? int [] [] scores = { {88, 80, 79, 92}, {75, 84, 93, 80}, {98, 95, 92, 94}, {91, 84, 88, 96} };
Respuesta
  • 93
  • 94

Pregunta 44

Pregunta
The part of a method that is a collection of statements that are performed when the method is executed is called
Respuesta
  • argument
  • method body

Pregunta 45

Pregunta
An array has a/an __________ size
Respuesta
  • fixed
  • dynamic
  • both answers are acceptable

Pregunta 46

Pregunta
An ArrayList has a fixed or dynamic size
Respuesta
  • False
  • True (either or statement is true)

Pregunta 47

Pregunta
When trying to access an element of an array, Java performs array _____ checking to make sure the subscript of the element exists
Respuesta
  • method
  • bound

Pregunta 48

Pregunta
Given an array variable with the name kiwi, what is the code to get the amount of elements in kiwi?
Respuesta
  • kiwi.length
  • kiwi.length;

Pregunta 49

Pregunta
Given an ArrayList variable with the name kiwi, what is the code to get the amount of elements in kiwi?
Respuesta
  • kiwi.size;
  • kiwi.size()

Pregunta 50

Pregunta
Given a String variable with the name kiwi, what is the code to get the amount of characters in kiwi?
Respuesta
  • kiwi.length();
  • kiwi.size();

Pregunta 51

Pregunta
Classes have _______ which store data
Respuesta
  • objects
  • fields

Pregunta 52

Pregunta
What is the term used for the character that separates tokens?
Respuesta
  • tokenizer
  • delimiter

Pregunta 53

Pregunta
What will be the value of x after the following code is executed? int x, y = 2, z = 3; x = (++y)*(++z);
Respuesta
  • error, x is undefined
  • 12 (since ++y becomes 3 and ++z becomes 4)

Pregunta 54

Pregunta
How many times will the following do-while loop be executed? int x = 5; do { x*=2;} while (x > 10)
Respuesta
  • 10
  • 1

Pregunta 55

Pregunta
What will be the value of x after the following code is executed? If the code has any kind of syntax error, please type in the answer "error". int x = 1; while (x++ < 10) { x++; }
Respuesta
  • 9
  • 12

Pregunta 56

Pregunta
How many times will the following for loop be executed? for (int count = 1; count <= 7; count += 3) {System.out.println("Java is great!!!");}
Respuesta
  • two
  • three

Pregunta 57

Pregunta
What will the following code output to the console? int [ ] integers = new int [5]; System.out.println(integers[0]);
Respuesta
  • zero since this is the default value for int
  • one

Pregunta 58

Pregunta
What will the following code output to the console? ArrayList<Integer> integers = new ArrayList<>(5); System.out.println(integers.get(0));
Respuesta
  • 0
  • error since new array list is not defined

Pregunta 59

Pregunta
What is the output? ArrayList<Integer> integers = new ArrayList<>(); integers.add(5); integers.add(7); integers.add(1,18); integers.remove(0); System.out.println(integers.get(0));
Respuesta
  • 1
  • 18

Pregunta 60

Pregunta
What's the output? ArrayList<String> strings = new ArrayList<>(); strings.add("hi"); strings.add("bye"); strings.add("howdy"); strings.remove(0); System.out.println(strings.get(2));
Respuesta
  • howdy
  • error

Pregunta 61

Pregunta
What is the output? int[ ] integers = {1,2,3,4,5}; for (int i = 0; i< integers.length; i++) { integers [i]++; } System.out.println(integers[3]);
Respuesta
  • five
  • four

Pregunta 62

Pregunta
What is the output? int[]integers = new int[10]; final int AMOUNT_OF_RUNS = 20; final int ADD_ME = 5; for (int i = 0; i < AMOUNT_OF_RUNS; i++) { integers[i] += ADD_ME; } System.out.println(integers[3]);
Respuesta
  • error because it is asking to run an amount of 20 times when an array is only 10 long
  • 10

Pregunta 63

Pregunta
What is the output? int [ ] integers = new int [10]; final int ADD_ME = 5; for (int i = 0; i< integers.length; i++) { integers [i] += ADD_ME*1; } System.out.println(integers[4]);
Respuesta
  • error
  • 20

Pregunta 64

Pregunta
What is the output? int [ ] [ ] integers = { { 14, 5, 21}, {34, 54}, {3, 6, 7}}; int total = 0; for (int row = 0; row<integers.length; row++) { for (int col = 0; col<integers[0].length; col++) { total += integers[row][col]; } } System.out.println(total);
Respuesta
  • Error since this is a ragged array
  • 54

Pregunta 65

Pregunta
What is the output? int [ ] [ ] integers = { { 14, 5, 21}, {34, 54}, {3, 6, 7}}; int mysteryVariable = 0; for (int row = 0; row<integers.length; row++) { for (int col = 0; col<integers[row].length; col++) { mysteryVariable++; } } System.out.println(mysteryVariable);
Respuesta
  • error
  • 8

Pregunta 66

Pregunta
what is the output? int [] [] integers = {{14,5,21{, {34, 54}, {3,6,7}}; int mysteryVariableOne = integers [0][0]; int mysteryVariableTwo = integers [0][0]; for (int row = 0; row < integers.length; row++) { for (int col = 0; col <integes[row].length; col++) { if (mysteryVariableOne < integers[row][col]) { mysteryVariableOne = integers[row][col]; } if (mysteryVariableTwo> integers[row][col]) { mysterVariableTwo = integers[row][col]; }}} System.out.println(myseryVariableOne - mysteryVariableTwo);
Respuesta
  • 51 (since 54 is the highest, and 3 is the lowest then 54 - 3 = 51)
  • error

Pregunta 67

Pregunta
Output? static ArrayList<String> listOfStrings; public static void main (String[ ] args) { String [ ] strings = {"D", "Z", "G", "P", "M" }; for (String s : strings) listOfStrings.add(s); System.out.println(listOfStrings.get(2)); }
Respuesta
  • error
  • G

Pregunta 68

Pregunta
Output? static ArrayList<String> listOfStrings; public static void main (String[ ] args) { String [ ] strings = {"D", "Z", "G", "P", "M" }; ArrayList<String> listOfStrings = new ArrayList<>(); for (int i = strings.length-1; i>0; i--) { listOfStrings.add(strings[i] + strings[i-1]); System.out.println(listOfStrings.get(2));
Respuesta
  • Error
  • GZ
  • ZD
Mostrar resumen completo Ocultar resumen completo

Similar

Computing Hardware - CPU and Memory
ollietablet123
SFDC App Builder 2
Parker Webb-Mitchell
Data Types
Jacob Sedore
Intake7 BIM L1
Stanley Chia
Software Processes
Nurul Aiman Abdu
Design Patterns
Erica Solum
CCNA Answers – CCNA Exam
Abdul Demir
Abstraction
Shannon Anderson-Rush
Spyware
Sam2
HTTPS explained with Carrier Pigeons
Shannon Anderson-Rush
Data Analytics
anelvr