Ch. 2 - Java Fundamentals
Character literals are enclosed in _____; string literals are enclosed in _____.
Single quotes; Double quotes
Given the declaration double r;, which of the following statements is invalid?
r = 2.9X106;
A Java program must have at least one of these:
Class definition
In Java, it is standard practice to capitalize the first letter of:
Class names
Which of the following is NOT a rule that must be followed when naming identifiers?
Identifiers can contain spaces.
Which of the following cannot be used as identifiers in Java?
Key words
This is a value that is written into the code of a program
Literal
Which of the following does NOT describe a valid comment in Java?
Multi-line comments, start with **/ and end with /**
This is a variable whose content is read only and cannot be changed during the program's execution.
Named constant
Which of the following statements correctly creates a Scanner object for keyboard input?
Scanner keyboard = new Scanner(System.in);
The term ___________ typically refers to the device that displays console output.
Standard output device
Which of the following is not a primitive data type?
String
When the (+) operator is used with strings, it is known as the:
String concatenation operator
Which of the following is a valid Java statement?
String str = "John Doe";
To print "Hello, world" on the monitor, use the following Java statement:
System.out.println("Hello, world");
In the following Java statement what value is stored in the variable name? String name = "John Doe";
The memory address where "John Doe" is located
TRUE/FALSE: A variable's scope is the part of the program that has access to the variable.
True
TRUE/FALSE: Although the dollar sign is a legal identifier character, you should not use it because it is normally used for special purposes.
True
TRUE/FALSE: If the compiler encounters a statement that uses a variable before the variable is declared, an error will result.
True
TRUE/FALSE: Named constants are initialized with a value, that value cannot be changed during the execution of the program.
True
TRUE/FALSE: Programming style includes techniques for consistently putting spaces and indentation in a program so visual cues are created.
True
The primitive data types only allow a(n) _____ to hold a single value.
Variable
This is a named storage location in the computer's memory.
Variable
In Java, ___________ must be declared before they can be used.
Variables
Which of the following is not a valid comment statement?
**/ comment 3 /**
When saving a Java source file, save it with an extension of:
.java
In Java, the beginning of a comment is marked with:
//
To display the output on the next line, you can use the println method or use this escape sequence in the print method.
\n
Every Java application program must have:
a method named "main"
What is the result of the following expression? 10 + 5 * 3 - 20
5
Variables are classified according to their:
Data type
Which one of the following would contain the translated Java byte code for a program named Demo?
Demo.class
Which one of the following methods would you use to convert a string to a double?
Double.ParseDouble
Variables of the boolean data type are useful for:
Evaluating true/false conditions
TRUE/FALSE: A Java program will not compile unless it contains the correct line numbers.
False
TRUE/FALSE: All Java statements end with semicolons.
False
TRUE/FALSE: Assuming that pay has been declared a double, the following statement is valid. pay = 2,583.44;
False
TRUE/FALSE: Both character literals and string literals can be assigned to a char variable.
False
TRUE/FALSE: Class names and key words are examples of variables.
False
TRUE/FALSE: In Java the variable named total is the same as the variable named Total.
False
TRUE/FALSE: Java is a case-insensitive language.
False
The boolean data type may contain values in the following range of values:
True or False
Which of the following is valid?
float w; w = 1.0*f*;
To compile a program named First, use the following command:
javac First.java
Which Scanner class method reads an int?
nextInt()
Which Scanner class method reads a String?
nextLine()
If x has been declared an int, which of the following statements is invalid?
x = 1,000; *NO COMMAS!*
What is the result of the following expression? 17 % 3 * 2 - 12 + 15
7
What is the result of the following expression? 25 / 4 + 4 * 10 % 3
7
What is the result of the following expression? 25 - 7 * 3 + 12 / 3
8