Deck 2: Java Fundamentals

Full screen (f)
exit full mode
Question
Which of the following is not a valid Java comment?

A) /** Comment one */
B) */ Comment two /*
C) // Comment three
D) /* Comment four */
Use Space or
up arrow
down arrow
to flip the card.
Question
Both character and string literals can be assigned to a char variable.
Question
Java is not case sensitive.
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
The Java API provides a class named Math that contains numerous methods which are useful for performing complex mathematical operations.
Question
Programming style includes techniques for consistently putting spaces and indentation in a program to help create visual cues.
Question
A Java source file must be saved with the extension

A) .java
B) .javac
C) .src
D) .class
Question
Which of the following would contain the translated Java byte code for a program named Demo?

A) Demo.java
B) Demo.code
C) Demo.class
D) Demo.byte
Question
A variable's scope is the part of the program that has access to that variable.
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
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
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
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 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
To compile a program named First you would use which of the following commands?

A) java First.java
B) javac First
C) javac First.java
D) compile First.javac
Question
If the compiler encounters a statement that uses a variable before the variable is declared, an error will result.
Question
The System.out.printf method allows you to format output in a variety of ways.
Question
Class names and key words are examples of variables.
Question
A Java program will not compile unless it contains the correct line numbers.
Question
Named constants are initialized with a value and that value cannot change during the execution of the program.
Question
What is the result of the following expression?
10 + 5 * 3 - 20

A) -5
B) -50
C) 5
D) 25
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
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
Which Scanner class method reads a String?

A) nextLine
B) charAt
C) nextString
D) getLine
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
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
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
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
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
In Java, __________ must be declared before they can be used.

A) variables
B) literals
C) key words
D) comments
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
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
The primitive data types only allow a(n) __________ to hold a single value.

A) class
B) literal
C) object
D) variable
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
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
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
If the following Java statements are executed, what will be displayed? System.out.println("The top three winners are\n");
System.out.print("Jody, the Giant\n");
System.out.print("Buffy, the Barbarian");
System.out.println("Adelle, the Alligator");

A) The top three winners are
Jody, the Giant
Buffy, the Barbarian
Adelle, the Alligator
B) The top three winners are Jody, the Giant\nBuffy, the BarbarianAdelle, and the Albino
C) The top three winners are
Jody, the Giant\nBuffy, the BarbarianAdelle, the Alligator
D) The top three winners are
Jody, the Giant
Buffy, the BarbarianAdelle, the Alligator
Question
What is the result of the following expression?
17 % 3 * 2 - 12 + 15

A) 105
B) 12
C) 7
D) 8
Question
Variables are classified according to their

A) names
B) values
C) locations
D) data types
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
Which of the following is not a primitive data type?

A) short
B) long
C) float
D) string
Question
A value that is written into the code of a program is a(n) __________.

A) literal
B) assignment statement
C) variable
D) operator
Question
What will be displayed as a result of executing the following code?
public class test
{
Public static void main(String[ ] args)
{
Int value1 = 9;
System.out.println(value1);
Int value2 = 45;
System.out.println(value2);
System.out.println(value3);
Value = 16;
}
}

A) 9
45
16
B) 94516
C) 9 45 16
D) Nothing. This is an error
Question
If x has been declared an int, which of the following statements is invalid?

A) x = 0;
B) x = -59832;
C) x = 1,000;
D) x = 592
Question
Every Java application program must have

A) a class named MAIN
B) a method named main
C) at least two data types
D) integer variables
Question
What will be displayed as a result of executing the following code? int x = 6;
String msg = "I am enjoying this class.";
String msg1 = msg.toUpperCase();
String msg2 = msg.toLowerCase();
Char ltr = msg.charAt(x);
Int strSize = msg.length();
System.out.println(msg);
System.out.println(msg1);
System.out.println(msg2);
System.out.println("Character at index x = " + ltr);
System.out.println("msg has " + strSize + "characters.");

A) I am enjoying this class.
I AM ENJOYING THIS CLASS.
I am enjoying this class.
Character at index x = e
Msg has 24 characters.
B) I am enjoying this class.
I AM ENJOYING THIS CLASS.
I am enjoying this class.
Character at index x = e
Msg has 25 characters.
C) I am enjoying this class.
I AM ENJOYING THIS CLASS.
I am enjoying this class.
Character at index x = n
Msg has 24 characters.
D) I am enjoying this class.
I AM ENJOYING THIS CLASS.
I am enjoying this class.
Character at index x = n
Msg has 25characters.
Question
To display the output on the next line, you can use the println method or use the __________ escape sequence in the print method.

A) \n
B) \r
C) \t
D) \b
Question
Which of the following is not a rule that must be followed when naming identifiers?

A) The first character must be one of the letters a-z, A-Z, and underscore or a dollar sign.
B) Identifiers can contain spaces.
C) Uppercase and lowercase characters are distinct.
D) After the first character, you may use the letters a-z, A-Z, the underscore, a dollar sign, or digits 0-9.
Question
Which of the following cannot be used as identifiers in Java?

A) variable names
B) class names
C) key words
D) objects
Question
What would be printed out as a result of the following code? System.out.println("The quick brown fox" +
"jumped over the \n"
"slow moving hen.");

A) The quick brown fox jumped over the \nslow moving hen.
B) The quick brown fox jumped over the
Slow moving hen.
C) The quick brown fox
Jumped over the
Slow moving hen.
D) Nothing - this is an error
Question
Which of the following is valid?

A) float y;
Y = 54.9;
B) float y;
Double z;
Z = 934.21;
Y = z;
C) float w;
W = 1.0f;
D) float v;
V = 1.0
Question
When the + operator is used with strings, it is known as the

A) assignment operator
B) string concatenation operator
C) addition operator
D) combines assignment operator
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/52
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 2: Java Fundamentals
1
Which of the following is not a valid Java comment?

A) /** Comment one */
B) */ Comment two /*
C) // Comment three
D) /* Comment four */
B
2
Both character and string literals can be assigned to a char variable.
False
3
Java is not case sensitive.
False
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 52 flashcards in this deck.
Unlock Deck
k this deck
5
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 52 flashcards in this deck.
Unlock Deck
k this deck
6
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 52 flashcards in this deck.
Unlock Deck
k this deck
7
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 52 flashcards in this deck.
Unlock Deck
k this deck
8
Which of the following would contain the translated Java byte code for a program named Demo?

A) Demo.java
B) Demo.code
C) Demo.class
D) Demo.byte
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
9
A variable's scope is the part of the program that has access to that variable.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
10
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 52 flashcards in this deck.
Unlock Deck
k this deck
11
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
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
12
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 52 flashcards in this deck.
Unlock Deck
k this deck
13
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
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
14
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 52 flashcards in this deck.
Unlock Deck
k this deck
15
To compile a program named First you would use which of the following commands?

A) java First.java
B) javac First
C) javac First.java
D) compile First.javac
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
16
If the compiler encounters a statement that uses a variable before the variable is declared, an error will result.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
17
The System.out.printf method allows you to format output in a variety of ways.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
18
Class names and key words are examples of variables.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
19
A Java program will not compile unless it contains the correct line numbers.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
20
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 52 flashcards in this deck.
Unlock Deck
k this deck
21
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 52 flashcards in this deck.
Unlock Deck
k this deck
22
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 52 flashcards in this deck.
Unlock Deck
k this deck
23
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 52 flashcards in this deck.
Unlock Deck
k this deck
24
Which Scanner class method reads a String?

A) nextLine
B) charAt
C) nextString
D) getLine
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
25
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 52 flashcards in this deck.
Unlock Deck
k this deck
26
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 52 flashcards in this deck.
Unlock Deck
k this deck
27
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 52 flashcards in this deck.
Unlock Deck
k this deck
28
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 52 flashcards in this deck.
Unlock Deck
k this deck
29
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 52 flashcards in this deck.
Unlock Deck
k this deck
30
In Java, __________ must be declared before they can be used.

A) variables
B) literals
C) key words
D) comments
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
31
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 52 flashcards in this deck.
Unlock Deck
k this deck
32
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 52 flashcards in this deck.
Unlock Deck
k this deck
33
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 52 flashcards in this deck.
Unlock Deck
k this deck
34
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 52 flashcards in this deck.
Unlock Deck
k this deck
35
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 52 flashcards in this deck.
Unlock Deck
k this deck
36
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 52 flashcards in this deck.
Unlock Deck
k this deck
37
If the following Java statements are executed, what will be displayed? System.out.println("The top three winners are\n");
System.out.print("Jody, the Giant\n");
System.out.print("Buffy, the Barbarian");
System.out.println("Adelle, the Alligator");

A) The top three winners are
Jody, the Giant
Buffy, the Barbarian
Adelle, the Alligator
B) The top three winners are Jody, the Giant\nBuffy, the BarbarianAdelle, and the Albino
C) The top three winners are
Jody, the Giant\nBuffy, the BarbarianAdelle, the Alligator
D) The top three winners are
Jody, the Giant
Buffy, the BarbarianAdelle, the Alligator
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
38
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 52 flashcards in this deck.
Unlock Deck
k this deck
39
Variables are classified according to their

A) names
B) values
C) locations
D) data types
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
40
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 52 flashcards in this deck.
Unlock Deck
k this deck
41
Which of the following is not a primitive data type?

A) short
B) long
C) float
D) string
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
42
A value that is written into the code of a program is a(n) __________.

A) literal
B) assignment statement
C) variable
D) operator
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
43
What will be displayed as a result of executing the following code?
public class test
{
Public static void main(String[ ] args)
{
Int value1 = 9;
System.out.println(value1);
Int value2 = 45;
System.out.println(value2);
System.out.println(value3);
Value = 16;
}
}

A) 9
45
16
B) 94516
C) 9 45 16
D) Nothing. This is an error
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
44
If x has been declared an int, which of the following statements is invalid?

A) x = 0;
B) x = -59832;
C) x = 1,000;
D) x = 592
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
45
Every Java application program must have

A) a class named MAIN
B) a method named main
C) at least two data types
D) integer variables
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
46
What will be displayed as a result of executing the following code? int x = 6;
String msg = "I am enjoying this class.";
String msg1 = msg.toUpperCase();
String msg2 = msg.toLowerCase();
Char ltr = msg.charAt(x);
Int strSize = msg.length();
System.out.println(msg);
System.out.println(msg1);
System.out.println(msg2);
System.out.println("Character at index x = " + ltr);
System.out.println("msg has " + strSize + "characters.");

A) I am enjoying this class.
I AM ENJOYING THIS CLASS.
I am enjoying this class.
Character at index x = e
Msg has 24 characters.
B) I am enjoying this class.
I AM ENJOYING THIS CLASS.
I am enjoying this class.
Character at index x = e
Msg has 25 characters.
C) I am enjoying this class.
I AM ENJOYING THIS CLASS.
I am enjoying this class.
Character at index x = n
Msg has 24 characters.
D) I am enjoying this class.
I AM ENJOYING THIS CLASS.
I am enjoying this class.
Character at index x = n
Msg has 25characters.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
47
To display the output on the next line, you can use the println method or use the __________ escape sequence in the print method.

A) \n
B) \r
C) \t
D) \b
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
48
Which of the following is not a rule that must be followed when naming identifiers?

A) The first character must be one of the letters a-z, A-Z, and underscore or a dollar sign.
B) Identifiers can contain spaces.
C) Uppercase and lowercase characters are distinct.
D) After the first character, you may use the letters a-z, A-Z, the underscore, a dollar sign, or digits 0-9.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
49
Which of the following cannot be used as identifiers in Java?

A) variable names
B) class names
C) key words
D) objects
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
50
What would be printed out as a result of the following code? System.out.println("The quick brown fox" +
"jumped over the \n"
"slow moving hen.");

A) The quick brown fox jumped over the \nslow moving hen.
B) The quick brown fox jumped over the
Slow moving hen.
C) The quick brown fox
Jumped over the
Slow moving hen.
D) Nothing - this is an error
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
51
Which of the following is valid?

A) float y;
Y = 54.9;
B) float y;
Double z;
Z = 934.21;
Y = z;
C) float w;
W = 1.0f;
D) float v;
V = 1.0
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
52
When the + operator is used with strings, it is known as the

A) assignment operator
B) string concatenation operator
C) addition operator
D) combines assignment operator
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 52 flashcards in this deck.