AlgoMaster Logo

Introduction to Java - Quiz

Last Updated: May 18, 2026

1 min read

Introduction to Java Exercises

26 quizzes

1
Multiple Choice

A teammate can run existing Java apps but needs to compile HelloShop.java on their laptop. What should they install?

2
Multiple Choice

You compile HelloShop.java on one operating system and send HelloShop.class to a colleague using a different operating system. What lets it run there?

3
Multiple Choice

After running javac HelloShop.java, you inspect HelloShop.class with javap -c and see instructions like ldc and invokevirtual. What are those instructions?

4
Multiple Choice

A tiny program uses String, System.out.println, and ArrayList. Besides the JVM, what must the runtime provide for those names to work?

5
Multiple Choice

A service method is called millions of times after the program starts. How is the JVM likely to speed it up?

6
Multiple Choice

A corrupted class file claims to pop values from the operand stack in an invalid way. Which JVM stage is responsible for rejecting it before normal execution?

7
Multiple Choice

You want to confirm that string concatenation in HelloShop.class became JVM instructions. Which tool from the JDK is designed for inspecting compiled bytecode?

8
Multiple Choice

On a machine, java -version works but javac -version fails with a command-not-found message. What is the most likely issue?

9
Sequencing

Order the steps from editing HelloShop.java to its main method running.

Drag and drop to reorder, or use the arrows.

10
Sequencing

Order the steps the JVM uses when a method becomes hot during execution.

Drag and drop to reorder, or use the arrows.

11
Output Prediction

What is the output when this class is run?

1public class HelloShop {
2    static {
3        System.out.print("loading ");
4    }
5    public static void main(String[] args) {
6        System.out.print("main");
7    }
8}
12
Bug Spotting

What bug can make this diagnostic report that Java is unavailable even while the program is running on a JVM?

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

java
1
public class JavaCheck {
2
    public static boolean hasJavaConfigured() {
3
        return System.getenv("JAVA_HOME") != null;
4
    }
5
}
13
Matching

Match each Java platform piece to the role it provides in a typical installation.

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

14
Matching

Match each JVM pipeline component to what it does when a class is run.

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

15
Fill in the Blanks

Complete the code that asks the current JDK for a compiler and uses it to compile one source file.

java
1
javax.tools.JavaCompiler compiler = javax.tools.ToolProvider.();
2
int exitCode = compiler.(null, null, null, "HelloShop.java");

Click an option to fill blank 1:

16
Fill in the Blanks

Complete the code that loads a class, finds its main method, and invokes it with an empty String array.

java
1
Class<?> appClass = Class.forName("HelloShop");
2
java.lang.reflect.Method main = appClass.("main", String[].class);
3
main.invoke(null, );

Click an option to fill blank 1:

17
Fill in the Blanks

Complete the code that reads the runtime name and the virtual machine name from system properties.

java
1
String runtimeName = System.getProperty();
2
String vmName = System.getProperty();

Click an option to fill blank 1:

18
Code Completion

Load the String class by its fully qualified name at runtime.

java
1
Class<?> stringClass = Class.("java.lang.String");

Click an option to fill the blank:

19
Code Completion

Print the current virtual machine implementation name from the standard system properties.

java
1
System.out.println(System.("java.vm.name"));

Click an option to fill the blank:

20
Hotspot Selection

Which line explicitly asks the JVM to load a class by name?

Click on the line to select.

java
1
public class LoaderDemo {
2
    public static void main(String[] args) throws Exception {
3
        System.out.println("before");
4
        Class<?> pluginType = Class.forName("com.myshop.Plugin");
5
        System.out.println(pluginType.getName());
6
    }
7
}
21
Multiple Choice

A developer coming from C++ writes Java code that creates many short-lived Product objects and asks where to call delete. What is the idiomatic Java answer?

22
Code Completion

Run the task on a separate thread instead of executing it on the current call stack.

java
1
new Thread(task).();

Click an option to fill the blank:

23
Hotspot Selection

Which line prevents the task from running on a new thread?

Click on the line to select.

java
1
public class ReportJob {
2
    public void launch(Runnable reportTask) {
3
        Thread worker = new Thread(reportTask);
4
        worker.run();
5
    }
6
}
24
Multiple Choice

After installing a JDK, a learner's already-open terminal still cannot find java, but a newly opened terminal can. What most likely changed?

25
Fill in the Blanks

Complete the standard entry point method for a simple Java program.

java
1
public class HelloShop {
2
public static main( args) {
3
System.out.println("Welcome to MyShop");
4
}
5
}

Click an option to fill blank 1:

26
Bug Spotting

This code is saved in a file named HelloShop.java. Why does compilation fail?

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

java
1
public class Helloshop {
2
    public static void main(String[] args) {
3
        System.out.println("Welcome to MyShop");
4
    }
5
}

Premium Content

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