Variables
Assignment & Output
Math & Operators
Syntax and Structure
Mixed Bag
100

What is a String used for?

To store text.

100

What does x += 5; do?

Adds 5 to x (same as x = x + 5).

100

What operator is used for multiplication in Java?

*

100

What symbol ends most lines in Java?

A semicolon;

100

What does // mean in Java?

A single-line comment.

200

Declare an int named age.

int age;

200

What will this print: System.out.println("Hello");?

Hello

200

What does % return?

The remainder of a division operation.

200

True or False: Java is case-sensitive.

True

200

Give an example of a valid variable name.

studentName, age, totalScore (any legal identifier).

300

What is the value of x after: x = 5 + 3 * 2;

11, because 3 * 2 is evaluated first.

300

Write code to assign 3.14 to a variable named pi.

double pi = 3.14;

300

What is the result of: 7 % 3?

1

300

What will happen if you forget a semicolon in your code?

You’ll get a syntax error during compilation.

300

What is the difference between = and == in Java?

= is the assignment operator (used to assign values), while == is the equality operator (used to compare values).

400

What does boolean store?

true or false

400

What happens if you divide an int by 0?

You get an ArithmeticException (runtime error).

400

What does x *= 2 do if x = 4?

x becomes 8.

400

What are the curly braces { } used for?

To group code into blocks (like inside methods or loops).

400

Can a variable name start with a number? Why or why not?

No, variable names can’t start with numbers—they must start with a letter, _, or $.

500

What’s the difference between int and double?

int stores whole numbers; double stores decimals.

500

Write a line that prints your name and age on the same line.

System.out.println("My name is Sam and I am 17.");

500

What is operator precedence, and how does it affect 5 + 2 * 3?

Multiplication happens before addition; result is 11.

500

How do you start a Java program?

With public static void main(String[] args) { }

500

What is the output of the following code?

int a = 4;

int b =2;

System.out.println(a + b + "is the sum");

6 is the sum — Because the addition happens first (both are int), then the result is concatenated with the string.