What file extension must all Java source code files end with?
.java
How is print different from println?
print does not move to a new line and println does
What is a variable?
A named storage location in memory
Identify the data type:
boolean
What method returns the number of characters in a String?
length()
Every Java application program must have what method?
A method named main
What escape sequence moves output to a new line?
\n
Is Sales the same variable name as sales?
No - Java is case-sensitive
What is the difference between a variable and a named constant?
A variable can change; a named constant cannot
How do you write a single-line comment in Java?
// comment
Identify the class name in this program:
public class Funk {
int fly;
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
Funk
What does '\t' do?
Prints a tab
What does this program not display the value of the variable?
number = 10
System.out.println("number is" + "number");
number isnumber
What keyword is used to declare a constant in Java?
final
How do you write a multi-line comment in Java?
/* comments
more comments
comment */
What symbol is used to mark the beginning and end of a code block in Java?
{}
What will this code display?
ABD
Identify the variables and literals in this program:
Variables: apples, price
Literals: 10, 1.5, "Total cost: "
What is the difference between a float and a double?
A double stores more precision and uses more memory than a float
What object is used to read user input from the keyboard?
Scanner
How is a Java source file named? (what comes before the .java?)
It is named after the public class with .java
What does this code print?
It won't compile because quotes are printed with \"
Which of the following is not a legal variable name:
$x
99bottles
_java_rocks_
FoxInSocks
99bottles
What is the value of answer?
double answer = 17/10;
1
What does this program do?
public class TestScope {
public static void main(String[] args) {
System.out.println(x);
int x = 5;
}
}
Nothing, it won't compile. x is used before it's declared.