AlgoMaster Logo

Introduction to Java - Quiz

Last Updated: December 6, 2025

Introduction to Java Exercises

31 quizzes

1
Code Completion

Store the length of the text in the length variable

java
1
int length = message.();

Click an option to fill the blank:

2
Code Completion

Create a new StringBuilder to efficiently build a log message

java
1
StringBuilder builder = new ();

Click an option to fill the blank:

3
Code Completion

Print a message to the console when the program starts

java
1
.out.println("Java started");

Click an option to fill the blank:

4
Multiple Choice

Which best describes Java as a programming language?

5
Multiple Choice

Which keyword starts the definition of a new class in Java?

6
Multiple Choice

Why did Java gain popularity on the early Internet?

7
Multiple Choice

Which Java feature directly supports 'write once, run anywhere'?

8
Multiple Choice

Which component must you install to both compile and run Java programs?

9
Multiple Choice

What is the role of the JRE?

10
Multiple Choice

Which statement about the main method in a Java application is true?

11
Multiple Choice

Which Java feature automatically reclaims memory for objects that are no longer used?

12
Multiple Choice

In the JVM, which component loads .class files into memory?

13
Multiple Choice

Which of these is NOT a core OOP principle emphasized by Java?

14
Multiple Choice

Why is setting PATH to include the JDK's bin directory useful?

15
Sequencing

Order the steps to write, compile, and run a simple Java program from the command line.

Drag and drop to reorder, or use the arrows.

16
Sequencing

Order the stages of how the JVM handles a Java class at runtime.

Drag and drop to reorder, or use the arrows.

17
Output Prediction

What is the output of this code?

1public class Main {
2    public static void main(String[] args) {
3        int a = 5;
4        int b = 3;
5        System.out.println(a + b * 2);
6    }
7}
18
Output Prediction

What is the output of this code?

1public class VersionCheck {
2    public static void main(String[] args) {
3        String name = "Java";
4        int year = 1995;
5        System.out.println(name + " was released in " + year);
6    }
7}
19
Output Prediction

What is the output of this code?

1public class FeatureCount {
2    public static void main(String[] args) {
3        int features = 3;
4        features++;
5        System.out.println("Features: " + features);
6    }
7}
20
Output Prediction

What is the output of this code?

1public class WoraDemo {
2    public static void main(String[] args) {
3        boolean jvmInstalled = true;
4        System.out.println("Can run Java: " + jvmInstalled);
5    }
6}
21
Output Prediction

What is the output of this code?

1public class JvmSteps {
2    public static void main(String[] args) {
3        String step1 = "load";
4        String step2 = "verify";
5        System.out.println(step1.toUpperCase() + "-" + step2.toUpperCase());
6    }
7}
22
Bug Spotting

Find the bug in this Java program that is intended to print Hello, World!

Click on the line(s) that contain the bug.

java
1
public class HelloWorld {
2
    public static void main(String[] args) {
3
        System.out.println("Hello, World!")
4
    }
5
}
23
Bug Spotting

Find the bug preventing this program from running its main method.

Click on the line(s) that contain the bug.

java
1
public class Starter {
2
    public void main(String[] args) {
3
        System.out.println("Starting application");
4
    }
5
}
24
Matching

Match each Java component with its primary responsibility.

Click an item on the left, then click its match on the right. Click a matched item to unmatch.

25
Matching

Match each Java history milestone with its description.

Click an item on the left, then click its match on the right. Click a matched item to unmatch.

26
Fill in the Blanks

Complete the code to define the main entry point of a Java program.

java
1
public class App {
2
public static void (String[] ) {
3
System.out.println("Running App");
4
}
5
}

Click an option to fill blank 1:

27
Fill in the Blanks

Complete the code to compile and run a class named Demo from the command line, shown as comments.

java
1
// Compile the program
2
// Demo.java
3
// Run the program
4
// Demo

Click an option to fill blank 1:

28
Fill in the Blanks

Complete the code to demonstrate automatic garbage collection.

java
1
public class GcDemo {
2
public static void main(String[] args) {
3
String temp = new String("Hello");
4
temp = ;
5
System.out.println();
6
}
7
}

Click an option to fill blank 1:

29
Fill in the Blanks

Complete the code to show a simple object-oriented structure with a method call.

java
1
public class Greeter {
2
public void sayHello() {
3
System.out.println("Hello from object");
4
}
5
6
public static void main(String[] args) {
7
Greeter g = new ();
8
g.();
9
}
10
}

Click an option to fill blank 1:

30
Hotspot Selection

Click the line that defines the Java application's entry point.

Click on the line to select.

java
1
public class Starter {
2
    public static void main(String[] args) {
3
        System.out.println("Init");
4
    }
5
}
31
Hotspot Selection

Click the line where the JVM executes the bytecode's behavior (the main action).

Click on the line to select.

java
1
public class Lifecycle {
2
    public static void main(String[] args) {
3
        System.out.println("Bytecode is running");
4
    }
5
}

Premium Content

Subscribe to unlock full access to this content and more premium articles.