(1) Primitive Types
(2) Using Objects
(3) Boolean Expressions and if Statements
(4) Iteration
(5) Writing Classes
100

What is the default value of an int variable in Java?

0
100

To find the length of a String, you use the __________ method.

.length()

100

What is the result of the following expression if a = 5 and b = 10?

a<b

true

100

What is the primary purpose of a for loop in Java?

To repeat a block of code a specific number of times.

100

What is the purpose of a class in Java?

A class is a blueprint for creating objects, defining their properties (fields) and behaviors (methods).

200

What is the smallest integer data type in Java?

byte

200

How do you concatenate two String objects in Java?

Using the + operator or the .concat() method.

200

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

200

What is the condition that causes an infinite loop in Java?

When the loop condition never becomes false or there is no exit condition

200

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.

300

What is autoboxing in Java?

Autoboxing is the automatic conversion of a primitive type to its corresponding wrapper class.

300

What does the .substring(3) method return when called on the String "apple"?

"le"

300

What is the output of the following code?

boolean result = (5 > 3) && (2 < 6);
System.out.println(result);


true

300

In a for loop, what are the three components (in order) inside the parentheses?

Initialization, condition, and update.

300

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.

400

How does type casting work in Java?

Type casting allows you to convert one data type into another.

400

How do you compare two String objects for equality in Java?

.equals()

400

What is the result of the following expression if x = 7 and y = 3?

!(x < y)

true

400

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.

400

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.

500

What is it called when you convert a double to an int?

casting

500

What is the purpose of the Integer.parseInt(String s) method?

It converts a String representation of a number into an int.

500

Which of the following statements is true?

  • A) !(5 < 3) && (2 == 2)
  • B) (7 != 7) || (8 > 10)
  • C) !(true || false)
  • A) !(5 < 3) && (2 == 2)
500

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.

500

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.