Program Basics
Output and Escape Sequences
Variables & Naming
Data Types & Constants
Strings, Scope & Comments
100

What file extension must all Java source code files end with?

.java

100

How is print different from println?

print does not move to a new line and println does

100

What is a variable?

A named storage location in memory

100

Identify the data type:

true

boolean

100

What method returns the number of characters in a String?

length()

200

Every Java application program must have what method?

A method named main

200

What escape sequence moves output to a new line?

\n

200

Is Sales the same variable name as sales?

No - Java is case-sensitive

200

What is the difference between a variable and a named constant?

A variable can change; a named constant cannot

200

How do you write a single-line comment in Java?

// comment

300

Identify the class name in this program:

public class Funk {
    int fly;
    public static void main(String[] args) {
        System.out.println("Hello, world!");
    }
}

Funk

300

What does '\t' do?

Prints a tab

300

What does this program not display the value of the variable?

number = 10

System.out.println("number is" + "number");




number isnumber

300

What keyword is used to declare a constant in Java?

final

300

How do you write a multi-line comment in Java?

/* comments

more comments 

comment */

400

What symbol is used to mark the beginning and end of a code block in Java?

{}

400

What will this code display?

System.out.print("ABC\bD");



ABD

400

Identify the variables and literals in this program:

int apples = 10;
double price = 1.5;
System.out.println("Total cost: " + apples * price);



Variables: apples, price

Literals: 10, 1.5, "Total cost: "

400

What is the difference between a float and a double?

A double stores more precision and uses more memory than a float

400

What object is used to read user input from the keyboard?

Scanner

500

How is a Java source file named? (what comes before the .java?)

It is named after the public class with .java

500

What does this code print?

System.out.print("She said "Hi"");


It won't compile because quotes are printed with \"

500

Which of the following is not a legal variable name: 

$x

99bottles

_java_rocks_

FoxInSocks

99bottles

500

What is the value of answer?

double answer = 17/10;

1

500

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.