What is a String used for?
To store text.
What does x += 5; do?
Adds 5 to x (same as x = x + 5).
What operator is used for multiplication in Java?
*
What symbol ends most lines in Java?
A semicolon;
What does // mean in Java?
A single-line comment.
Declare an int named age.
int age;
What will this print: System.out.println("Hello");?
Hello
What does % return?
The remainder of a division operation.
True or False: Java is case-sensitive.
True
Give an example of a valid variable name.
studentName, age, totalScore (any legal identifier).
What is the value of x after: x = 5 + 3 * 2;
11, because 3 * 2 is evaluated first.
Write code to assign 3.14 to a variable named pi.
double pi = 3.14;
What is the result of: 7 % 3?
1
What will happen if you forget a semicolon in your code?
You’ll get a syntax error during compilation.
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).
What does boolean store?
true or false
What happens if you divide an int by 0?
You get an ArithmeticException (runtime error).
What does x *= 2 do if x = 4?
x becomes 8.
What are the curly braces { } used for?
To group code into blocks (like inside methods or loops).
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 $.
What’s the difference between int and double?
int stores whole numbers; double stores decimals.
Write a line that prints your name and age on the same line.
System.out.println("My name is Sam and I am 17.");
What is operator precedence, and how does it affect 5 + 2 * 3?
Multiplication happens before addition; result is 11.
How do you start a Java program?
With public static void main(String[] args) { }
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.