What is the default value of an int variable in Java?
To find the length of a String, you use the __________ method.
.length()
What is the result of the following expression if a = 5 and b = 10?
a<b
true
What is the primary purpose of a for loop in Java?
To repeat a block of code a specific number of times.
What is the purpose of a class in Java?
A class is a blueprint for creating objects, defining their properties (fields) and behaviors (methods).
What is the smallest integer data type in Java?
byte
How do you concatenate two String objects in Java?
Using the + operator or the .concat() method.
What will be the output of the following code if x = 3?
if (x > 2) {
System.out.println("Yes");
} else {
System.out.println("No");
}
yes
What is the condition that causes an infinite loop in Java?
When the loop condition never becomes false or there is no exit condition
What is the difference between instance variables and local variables in a class?
Instance variables are declared within the class and are associated with an object, while local variables are declared inside methods and are only accessible within those methods.
What is autoboxing in Java?
Autoboxing is the automatic conversion of a primitive type to its corresponding wrapper class.
What does the .substring(3) method return when called on the String "apple"?
"le"
What is the output of the following code?
boolean result = (5 > 3) && (2 < 6);
System.out.println(result);
true
In a for loop, what are the three components (in order) inside the parentheses?
Initialization, condition, and update.
What does the this keyword refer to in a constructor?
The this keyword refers to the current instance of the class, allowing access to instance variables or methods.
How does type casting work in Java?
Type casting allows you to convert one data type into another.
How do you compare two String objects for equality in Java?
.equals()
What is the result of the following expression if x = 7 and y = 3?
true
What will happen if the loop's termination condition is not met in a while loop?
The loop will run indefinitely (infinite loop) unless there is a break or the condition is modified within the loop.
What is method overloading in Java?
Method overloading occurs when multiple methods in a class have the same name but differ in the number or type of their parameters.
What is it called when you convert a double to an int?
casting
What is the purpose of the Integer.parseInt(String s) method?
It converts a String representation of a number into an int.
Which of the following statements is true?
What is the difference between a while loop and a do-while loop in terms of execution?
A while loop checks the condition before executing the code block, while a do-while loop executes the code block at least once before checking the condition.
What is the difference between public, private, and protected access modifiers in Java?
public allows access from any other class.
private restricts access to the class itself.
protected allows access within the same package and subclasses.