Deck 2: Java Fundamentals

Full screen (f)
exit full mode
Question
What would be displayed as a result of the following code? int x = 578; System.out.print("There are " +
X + 5 + "\n" +
"hens in the hen house.");

A) There are 583 hens in the hen house.
B) There are 5785 hens in the hen house.
C) There are x5\nhens in the hen house.
D) There are 5785 hens in the hen house.
Use Space or
up arrow
down arrow
to flip the card.
Question
Variables of the boolean data type are useful for

A) evaluating conditions that are either true or false.
B) working with small integers.
C) working with very large integers.
D) evaluating scientific notation.
Question
This is a value that is written into the code of a program.

A) Literal
B) Assignment statement
C) Operator
D) Variable
Question
Which of the following is not a valid Java comment?

A) /** Comment 1 */
B) */ Comment 2 /*
C) // Comment 3
D) /* Comment 4 */
Question
To print "Hello, world" on the monitor, use the following Java statement:

A) System.out.println("Hello, world");
B) System Print = "Hello, world";
C) SystemOutPrintln('Hello, world');
D) system.out.println{Hello, world};
Question
Which of the following statements will correctly convert the data type, if x is a float and y is a double?

A) x = float y;
B) x = y;
C) x = (float)y;
D) x = y;
Question
A Java program must have at least one

A) comment.
B) System.out.println(); statement.
C) class definition.
D) variable declaration.
Question
Variables are classified according to their

A) names.
B) values.
C) location in memory.
D) data type.
Question
Character literals are enclosed in ________, and string literals are enclosed in ________.

A) single quotes, double quotes
B) double quotes, single quotes
C) single quotes, single quotes
D) double quotes, double quotes
Question
What is the result of the following expression? 17 % 3 * 2 - 12 + 15

A) 105
B) 12
C) 7
D) 8
Question
What will be the displayed when the following code is executed?
Final int x = 22, y = 4;
Y += x;
System.out.println("x = " + x + ", y = " + y);

A) x = 22, y = 26
B) x = 22, y = 4
C) x = 22, y = 88
D) Nothing. There is an error in the code.
Question
This is a named storage location in the computer's memory.

A) Operator
B) Constant
C) Literal
D) Variable
Question
What is the result of the following expression? 10 + 5 * 3 - 20

A) -5
B) -50
C) 5
D) 25
Question
Which of the following statements is invalid?

A) double r = 9.4632E15;
B) double r = 9.4632e15;
C) double r = 2.9X106;
D) double r = 326.75;
Question
Which of the following is not a rule that must be followed when naming identifiers?

A) After the first character, you may use the letters a-z, A-Z, an underscore, a dollar sign, or digits 0-9.
B) Identifiers can contain spaces.
C) Uppercase and lowercase characters are distinct.
D) The first character must be one of the letters a-z, A-Z, an underscore or a dollar sign.
Question
What will be the value of z after the following statements have been executed? int x = 4, y = 33;
Double z;
Z = (double) (y / x);

A) 8.25
B) 4
C) 0
D) 8.0
Question
When saving a Java source file, save it with an extension of

A) )java.
B) )javac.
C) )src.
D) )class.
Question
The boolean data type may contain the following range of values:

A) -128 to +127.
B) true or false.
C) -2,147,483,648 to +2,147,483,647.
D) -32,768 to +32,767.
Question
In the following Java statement what value is stored in the variable name? String name = "John Doe";

A) "name"
B) the memory address where "John Doe" is located
C) the memory address where name is located
D) "John Doe"
Question
What output will be displayed as a result of executing the following code?
Int x = 5, y = 20;
X += 32;
Y /= 4;
System.out.println("x = " + x + ", y = " + y);

A) x = 160, y = 80
B) x = 32, y = 4
C) x = 37, y = 5
D) x = 9, y = 52
Question
Unlike a console program, a program that uses JOptionPane does not automatically stop executing when the end of the main method is reached.
Question
Which Scanner class method reads a String?

A) nextLine
B) charAt
C) nextString
D) getLine
Question
Named constants are initialized with a value, and that value cannot change during the execution of the program.
Question
The primitive data types only allow a(n) ________ to hold a single value.

A) class
B) literal
C) object
D) variable
Question
If you wish to use the System.out.printf method to print a string argument, use the ________ format specifier.

A) %d
B) %b
C) %f
D) %s
Question
If you use a flag in a format specifier, you must write the flag before the field width and the precision.
Question
What will be displayed after the following statements have been executed?
Int x = 15, y = 20, z = 32;
X += 12;
Y /= 6;
Z -= 14;
System.out.println("x = " + x +
", y = " + y +
", z = " + z);

A) x = 27, y = 3.333, z = 18
B) x = 27, y = 2, z = 18
C) x = 37, y = -14, z = 4
D) x = 27, y = 3, z = 18
Question
A variable's scope is the part of the program that has access to the variable.
Question
The System.out.printf method allows you to format output in a variety of ways.
Question
Which of the following statements correctly creates a Scanner object for keyboard input?

A) Scanner kbd = new Scanner(System.keyboard);
B) Scanner keyboard = new Scanner(System.in);
C) Scanner keyboard(System.in);
D) Keyboard scanner = new Keyboard(System.in);
Question
A(n) ________ is a dialog box that prompts the user for input.

A) input box
B) user prompt
C) adaptive dialog
D) input dialog
Question
Both character literals and string literals can be assigned to a char variable.
Question
A message dialog is a quick and simple way to ask the user to enter data.
Question
The ________ method is used to display a message dialog.

A) showMessageDialog
B) messageDialog
C) messageDialogShow
D) showDialog
Question
This statement tells the compiler where to find the JOptionPane class and makes it available to your program.

A) import javax.swing.JOptionPane;
B) import Java.Swing.JOptionPane;
C) import JOptionPane;
D) import javax.JOptionPane;
Question
When you call one of the Scanner class's methods to read a primitive value, such as nextInt or nextDouble, and then call the nextLine method to read a string, an annoying and hard-to-find problem can occur.
Question
What will be the value of z as a result of executing the following code?
Int x = 5, y = 28;
Float z;
Z = (float) (y / x);

A) 5.6
B) 3.0
C) 5.0
D) 5.60
Question
Programming style includes techniques for consistently putting spaces and indentation in a program so visual cues are created.
Question
The Java API provides a class named Math, which contains numerous methods that are useful for performing complex mathematical operations.
Question
The simplest way you can use the System.out.printf method is

A) with a format string, and one format specifier.
B) with only a format string, and no additional arguments.
C) with a format string, and one or more format specifiers.
D) with only one format specifier, and no format string.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/40
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 2: Java Fundamentals
1
What would be displayed as a result of the following code? int x = 578; System.out.print("There are " +
X + 5 + "\n" +
"hens in the hen house.");

A) There are 583 hens in the hen house.
B) There are 5785 hens in the hen house.
C) There are x5\nhens in the hen house.
D) There are 5785 hens in the hen house.
B
2
Variables of the boolean data type are useful for

A) evaluating conditions that are either true or false.
B) working with small integers.
C) working with very large integers.
D) evaluating scientific notation.
A
3
This is a value that is written into the code of a program.

A) Literal
B) Assignment statement
C) Operator
D) Variable
A
4
Which of the following is not a valid Java comment?

A) /** Comment 1 */
B) */ Comment 2 /*
C) // Comment 3
D) /* Comment 4 */
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
5
To print "Hello, world" on the monitor, use the following Java statement:

A) System.out.println("Hello, world");
B) System Print = "Hello, world";
C) SystemOutPrintln('Hello, world');
D) system.out.println{Hello, world};
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
6
Which of the following statements will correctly convert the data type, if x is a float and y is a double?

A) x = float y;
B) x = y;
C) x = (float)y;
D) x = y;
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
7
A Java program must have at least one

A) comment.
B) System.out.println(); statement.
C) class definition.
D) variable declaration.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
8
Variables are classified according to their

A) names.
B) values.
C) location in memory.
D) data type.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
9
Character literals are enclosed in ________, and string literals are enclosed in ________.

A) single quotes, double quotes
B) double quotes, single quotes
C) single quotes, single quotes
D) double quotes, double quotes
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
10
What is the result of the following expression? 17 % 3 * 2 - 12 + 15

A) 105
B) 12
C) 7
D) 8
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
11
What will be the displayed when the following code is executed?
Final int x = 22, y = 4;
Y += x;
System.out.println("x = " + x + ", y = " + y);

A) x = 22, y = 26
B) x = 22, y = 4
C) x = 22, y = 88
D) Nothing. There is an error in the code.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
12
This is a named storage location in the computer's memory.

A) Operator
B) Constant
C) Literal
D) Variable
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
13
What is the result of the following expression? 10 + 5 * 3 - 20

A) -5
B) -50
C) 5
D) 25
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
14
Which of the following statements is invalid?

A) double r = 9.4632E15;
B) double r = 9.4632e15;
C) double r = 2.9X106;
D) double r = 326.75;
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
15
Which of the following is not a rule that must be followed when naming identifiers?

A) After the first character, you may use the letters a-z, A-Z, an underscore, a dollar sign, or digits 0-9.
B) Identifiers can contain spaces.
C) Uppercase and lowercase characters are distinct.
D) The first character must be one of the letters a-z, A-Z, an underscore or a dollar sign.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
16
What will be the value of z after the following statements have been executed? int x = 4, y = 33;
Double z;
Z = (double) (y / x);

A) 8.25
B) 4
C) 0
D) 8.0
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
17
When saving a Java source file, save it with an extension of

A) )java.
B) )javac.
C) )src.
D) )class.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
18
The boolean data type may contain the following range of values:

A) -128 to +127.
B) true or false.
C) -2,147,483,648 to +2,147,483,647.
D) -32,768 to +32,767.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
19
In the following Java statement what value is stored in the variable name? String name = "John Doe";

A) "name"
B) the memory address where "John Doe" is located
C) the memory address where name is located
D) "John Doe"
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
20
What output will be displayed as a result of executing the following code?
Int x = 5, y = 20;
X += 32;
Y /= 4;
System.out.println("x = " + x + ", y = " + y);

A) x = 160, y = 80
B) x = 32, y = 4
C) x = 37, y = 5
D) x = 9, y = 52
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
21
Unlike a console program, a program that uses JOptionPane does not automatically stop executing when the end of the main method is reached.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
22
Which Scanner class method reads a String?

A) nextLine
B) charAt
C) nextString
D) getLine
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
23
Named constants are initialized with a value, and that value cannot change during the execution of the program.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
24
The primitive data types only allow a(n) ________ to hold a single value.

A) class
B) literal
C) object
D) variable
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
25
If you wish to use the System.out.printf method to print a string argument, use the ________ format specifier.

A) %d
B) %b
C) %f
D) %s
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
26
If you use a flag in a format specifier, you must write the flag before the field width and the precision.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
27
What will be displayed after the following statements have been executed?
Int x = 15, y = 20, z = 32;
X += 12;
Y /= 6;
Z -= 14;
System.out.println("x = " + x +
", y = " + y +
", z = " + z);

A) x = 27, y = 3.333, z = 18
B) x = 27, y = 2, z = 18
C) x = 37, y = -14, z = 4
D) x = 27, y = 3, z = 18
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
28
A variable's scope is the part of the program that has access to the variable.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
29
The System.out.printf method allows you to format output in a variety of ways.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
30
Which of the following statements correctly creates a Scanner object for keyboard input?

A) Scanner kbd = new Scanner(System.keyboard);
B) Scanner keyboard = new Scanner(System.in);
C) Scanner keyboard(System.in);
D) Keyboard scanner = new Keyboard(System.in);
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
31
A(n) ________ is a dialog box that prompts the user for input.

A) input box
B) user prompt
C) adaptive dialog
D) input dialog
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
32
Both character literals and string literals can be assigned to a char variable.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
33
A message dialog is a quick and simple way to ask the user to enter data.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
34
The ________ method is used to display a message dialog.

A) showMessageDialog
B) messageDialog
C) messageDialogShow
D) showDialog
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
35
This statement tells the compiler where to find the JOptionPane class and makes it available to your program.

A) import javax.swing.JOptionPane;
B) import Java.Swing.JOptionPane;
C) import JOptionPane;
D) import javax.JOptionPane;
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
36
When you call one of the Scanner class's methods to read a primitive value, such as nextInt or nextDouble, and then call the nextLine method to read a string, an annoying and hard-to-find problem can occur.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
37
What will be the value of z as a result of executing the following code?
Int x = 5, y = 28;
Float z;
Z = (float) (y / x);

A) 5.6
B) 3.0
C) 5.0
D) 5.60
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
38
Programming style includes techniques for consistently putting spaces and indentation in a program so visual cues are created.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
39
The Java API provides a class named Math, which contains numerous methods that are useful for performing complex mathematical operations.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
40
The simplest way you can use the System.out.printf method is

A) with a format string, and one format specifier.
B) with only a format string, and no additional arguments.
C) with a format string, and one or more format specifiers.
D) with only one format specifier, and no format string.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 40 flashcards in this deck.