Command Palette

Search for a command to run...

Back to the lesson: Topic 0.2 — What Java Is: JDK, JRE, JVM and Bytecode
Core Java · Example 2 of 3

The same answers on every JVM

The Java specification fixes the size of int and the rules of arithmetic, so these lines print exactly the same on Windows, macOS, Linux and in the browser.

Java is a programming language plus a platform to run it. The javac compiler turns your .java files into portable bytecode (.class files), and a Java Virtual Machine on each computer runs that same bytecode, which is why one compiled program works on Windows, macOS and Linux. The JDK is the toolbox for writing Java; the JVM is the engine that runs it.

Change the code and press Run (Ctrl+Enter). Try to predict the output first, then break it on purpose and read the error. Your edits are saved and match the lesson page.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write a program with two classes in one file: a Calculator class with a method that doubles a number, and Main, which prints the double of 21.

02

Write a program that uses Math.max, Math.min and Math.abs from the standard library and prints the results for 8 and -3.

03

Write a program that prints Integer.MAX_VALUE and Long.MAX_VALUE, each on its own line.

Explain it without notes

01

Explain the difference between the JDK, the JRE and the JVM.

02

What is bytecode, and why doesn't Java compile straight to machine code?

03

How does Java achieve "write once, run anywhere", and where does that promise stop?

04

What is OpenJDK, and why are there several JDK distributions?

The same answers on every JVM
Sign in to run this example in your browser.

Expected output

Biggest int: 2147483647
Biggest int + 1: -2147483648
0.1 + 0.2 = 0.30000000000000004
7 / 2 = 3
An int uses 4 bytes