AI InterviewSearch…Search problems, topics, or pages…Ctrl KGet started
Skip to content

01 Java & the JVM / Checkpoint

Checkpoint — Java & the JVM

25 min · +25 XP · 3 exercises · 15 questions

Exercises0/3
Quiz · 70% to clear15 q

This checkpoint covers the whole module: what Java is, the JDK/JRE/JVM layers, the compile-and-run pipeline, the anatomy of a program, packages and imports, and console I/O.

How it works. Fifteen questions and two programs. You need 70% on the questions and both programs accepted to clear the module. You can retake it as often as you like; your best score counts.

Before you start, make sure you can answer these from memory:

  • What does javac produce, and what does java do with it?
  • Which layer contains the class library — JVM, JRE or JDK?
  • What is the difference between ClassNotFoundException and NoClassDefFoundError?
  • Where do local variables live, and where do objects live?
  • What does an import statement cost at run time?
  • Why does nextLine() after nextInt() return an empty string?

The two programs use the I/O template from the last lesson. Read the input format carefully — most failed submissions in this checkpoint are reading problems, not logic problems.

Common questions

What does javac produce, and what does java do with it?

javac compiles .java source files into .class files that contain bytecode. The java launcher starts a JVM, loads the named class and calls its main method.

What is the difference between ClassNotFoundException and NoClassDefFoundError?

ClassNotFoundException is a checked exception thrown when code asks for a class by name, as Class.forName does, and no class loader can find it. NoClassDefFoundError is an error thrown when a class that was present at compile time is missing at run time.

Why does nextLine() after nextInt() return an empty string?

nextInt() reads the number but leaves the line break after it in the input. The next nextLine() reads up to that line break and returns what is left of the line — nothing. Call nextLine() once to discard it before reading the next line.

Java Basics Quiz: JVM, javac and Console I/O Practice Test

Test your Java fundamentals with 15 questions and two programs on the JDK, JRE and JVM, compiling and running code, packages, imports and console I/O.

  • Course: Java study plan
  • Module: Java & the JVM
  • Kind: Checkpoint — cleared at 70%
  • Reading time: 25 min
  • Runtime: OpenJDK 18

Checkpoint — Java & the JVM is the checkpoint that closes the Java & the JVM module: a graded quiz and whole-program exercises, passed at 70%.

Instructions

This checkpoint covers the whole module: what Java is, the JDK/JRE/JVM layers, the compile-and-run pipeline, the anatomy of a program, packages and imports, and console I/O.

How it works. Fifteen questions and two programs. You need 70% on the questions and both programs accepted to clear the module. You can retake it as often as you like; your best score counts.

Before you start, make sure you can answer these from memory:

  • What does javac produce, and what does java do with it?
  • Which layer contains the class library — JVM, JRE or JDK?
  • What is the difference between ClassNotFoundException and NoClassDefFoundError?
  • Where do local variables live, and where do objects live?
  • What does an import statement cost at run time?
  • Why does nextLine() after nextInt() return an empty string?

The two programs use the I/O template from the last lesson. Read the input format carefully — most failed submissions in this checkpoint are reading problems, not logic problems.

Common questions

What does javac produce, and what does java do with it?

javac compiles .java source files into .class files that contain bytecode. The java launcher starts a JVM, loads the named class and calls its main method.

What is the difference between ClassNotFoundException and NoClassDefFoundError?

ClassNotFoundException is a checked exception thrown when code asks for a class by name, as Class.forName does, and no class loader can find it. NoClassDefFoundError is an error thrown when a class that was present at compile time is missing at run time.

Why does nextLine() after nextInt() return an empty string?

nextInt() reads the number but leaves the line break after it in the input. The next nextLine() reads up to that line break and returns what is left of the line — nothing. Call nextLine() once to discard it before reading the next line.

Exercises

Multiplication table

Read an integer n (1 ≤ n ≤ 12) and print the multiplication table for 1 through n: row i contains i×1, i×2, …, i×n, each number right-aligned in a field of width 4 (%4d), with no trailing text.

Example: n = 3 →

   1   2   3
   2   4   6
   3   6   9

Word count

Implement a tiny wc: read all of standard input until end of stream and print three lines — the number of lines, the number of words (whitespace-separated tokens) and the number of characters (every character including spaces and newlines).

Use readLine() in a loop until it returns null. Every line read counts as one line and contributes its length plus one for the newline.

Example input:

the quick brown
fox

Output:

lines=2
words=4
chars=20

FizzBuzz, your way

Read an integer n, two divisors a and b, and two words wa and wb. For each number from 1 to n print the number — or wa if it is divisible by a, wb if divisible by b, and wa followed by wb (no space) if divisible by both. Then print replaced: <how many numbers were replaced by words>.

Example: 6 2 3 Fizz Buzz →

1
Fizz
Buzz
Fizz
5
FizzBuzz
replaced: 4

In this module: Java & the JVM

← Reading input and printing output · The eight primitive types →