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