This punctuation mark must end most Java statements.
What is a semicolon?
This primitive type stores whole numbers like 5 or -42.
What is int?
This keyword creates a new object from a class.
What is new?
This Java keyword is used to handle exceptions.
What is try?
String name;
System.out.println(name);
Error: Using a variable before initializing it.
String name = "Pi";
This method is always the starting point of a Java program.
What is main?
The line of code to declare an integer with the name age that is given the value 15.
What is int age = 15;?
These are variables that belong to an object and define its state.
What are instance variables?
This block of code runs only if an exception is thrown.
What is catch?
while (true) {
System.out.println("Looping...");
}
Error: infinite loop create, the program will never end.
This keyword stops a loop immediately.
What is break?
This non-primitive type stores text.
What is String?
This keyword refers to the current object within a class.
What is this?
This type of error is found by the compiler before the program runs.
What is a compile-time error?
int x = 5;
if (x = 10) {
System.out.println("x is 10");
}
Error: Using assignment = instead of comparison == in the if condition.
Fix: Change x = 10 to x == 10.
This method checks if two strings have exactly the same characters.
What is equals()?
This method returns the number of characters in a string.
What is length()?
This keyword allows a class to use fields and methods from another class.
What is extends?
This exception occurs when you try to use an array index that doesn’t exist.
What is ArrayIndexOutOfBoundsException?
for (int i = 1; i < 10; i--) {
System.out.println(i);
}
Error: Loop counter is decreasing (i--) but condition expects increasing (i < 10), causing an infinite loop.
Fix: Change i-- to i++.
This keyword is used to indicate that a method will not return any value.
What is void?
This is the default value for an uninitialized boolean variable in a class.
What is false?
This keyword is used so that a subclass can call its parent class’s constructor or methods.
What is super?
This type of error happens while the program is running.
What is a runtime error?
public class MyClass {
public void myMethod() {
int x = 10;
}
System.out.println(x);
}
Error: Trying to access a local variable x outside its scope causes a compilation error.
Fix: Move System.out.println(x); inside the method or make x a class variable.