Deck 2: Java Fundamentals

Full screen (f)
exit full mode
Question
Both character and string literals can be assigned to a char variable.
Use Space or
up arrow
down arrow
to flip the card.
Question
Which of the following is a value that is written into the code of a program?

A) a literal
B) an assignment statement
C) an operator
D) a variable
Question
Which of the following is a named storage location in the computer's memory?

A) a literal
B) an operator
C) a constant
D) a variable
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
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 is the result of the following expression?
10 + 5 * 3 - 20

A) -5
B) -50
C) 5
D) 25
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
The System.out.printf method allows you to format output in a variety of ways.
Question
The Java API provides a class named Math that contains numerous methods which are useful for performing complex mathematical operations.
Question
Unlike a console program, a program that uses the JOptionPane does not automatically stop executing when the end of the main method is reached.
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 the 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
Programming style includes techniques for consistently putting spaces and indentation in a program to help create visual cues.
Question
Which of the following is not a valid Java comment?

A) /** Comment one */
B) */ Comment two /*
C) // Comment three
D) /* Comment four */
Question
Variables are classified according to their

A) names
B) values
C) locations
D) data types
Question
What is the result of the following expression?
17 % 3 * 2 - 12 + 15

A) 105
B) 12
C) 7
D) 8
Question
Named constants are initialized with a value and that value cannot change during the execution of the program.
Question
If you use a flag in a format specifier, you must write the flag before the field width and the precision.
Question
A Java source file must be saved with the extension

A) .java
B) .javac
C) .src
D) .class
Question
A message dialog is a quick and simple way to ask the user to enter data.
Question
A variable's scope is the part of the program that has access to that variable.
Question
What would be displayed as a result of executing 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.
Question
The boolean data type may contain which of 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
The __________ method is used to display a message dialog.

A) showMessageDialog
B) messageDialog
C) messageDialogShow
D) showDialog
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
What is the value of z after the following code is executed?
int x = 5, y = 28;
Float z;
Z = (float) (y / x);

A) 5.6
B) 3.0
C) 5.0
D) 5.60
Question
If you want 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
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
What would be displayed as a result of executing the following code?
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
The simplest way to 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
Question
A Java program must have at least one of the following:

A) a comment
B) a class definition
C) a System.out.println(); statement
D) a variable declaration
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
What would be displayed as a result of executing the following code?
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
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
What is 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
Which 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
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 = <float>y;
C) x = (float)y;
D) x = y;
Question
To print "Hello, world" on the monitor, which of the following Java statements should be used?

A) System.out.println("Hello, world");
B) System Print = "Hello, world";
C) SystemOutPrintln('Hello, world');
D) system.out.println(Hello, world);
Question
The primitive data types only allow a(n) __________ to hold a single value.

A) class
B) literal
C) object
D) variable
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 Scanner class method reads a String?

A) nextLine
B) charAt
C) nextString
D) getLine
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
Both character and string literals can be assigned to a char variable.
False
2
Which of the following is a value that is written into the code of a program?

A) a literal
B) an assignment statement
C) an operator
D) a variable
A
3
Which of the following is a named storage location in the computer's memory?

A) a literal
B) an operator
C) a constant
D) a variable
D
4
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
5
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
6
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
7
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
8
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
9
The Java API provides a class named Math that contains numerous methods which are useful for performing complex mathematical operations.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
10
Unlike a console program, a program that uses the 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
11
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 the 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
12
Programming style includes techniques for consistently putting spaces and indentation in a program to help create visual cues.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
13
Which of the following is not a valid Java comment?

A) /** Comment one */
B) */ Comment two /*
C) // Comment three
D) /* Comment four */
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
14
Variables are classified according to their

A) names
B) values
C) locations
D) data types
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
15
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
16
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
17
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
18
A Java source file must be saved with the extension

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
19
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
20
A variable's scope is the part of the program that has access to that variable.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
21
What would be displayed as a result of executing 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.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
22
The boolean data type may contain which of 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
23
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
24
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
25
What is the value of z after the following code is executed?
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
26
If you want 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
27
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
28
What would be displayed as a result of executing the following code?
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
29
The simplest way to 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
30
A Java program must have at least one of the following:

A) a comment
B) a class definition
C) a System.out.println(); statement
D) a variable declaration
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
31
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
32
What would be displayed as a result of executing the following code?
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
33
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
34
What is 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
35
Which 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
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 = <float>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
37
To print "Hello, world" on the monitor, which of the following Java statements should be used?

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
38
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
39
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
40
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
locked card icon
Unlock Deck
Unlock for access to all 40 flashcards in this deck.