Java for Beginners / Chapter 1 — Getting started (lessons 1–6) / Lesson 1

What Java is (the JVM and bytecode)

Time needed: about 4 min (estimate)

☆ Read later

You can try the opening of this lesson without an account.

A Java program runs in two stages

Running Java involves two commands.

javac is the compiler: it reads the Hello.java you wrote and produces Hello.class.

java Hello then runs that .class.

You write Hello without an extension — not java Hello.class or java Hello.java — because the instruction is "run the class called Hello".

Hello.java

// The smallest possible Java program. // The filename must be "ClassName.java" (this file is Hello.java). public class Hello { // The main method is the entry point. The JVM starts executing here. public static void main(String[] args) { System.out.println("Hello, Java!"); } }

Terminal

$ javac Hello.java $ java Hello Hello, Java! $ ls Hello.java Hello.class <- a file that was not there before compiling

Create a free account to keep reading

With an account you can read the rest of this lesson, take the quiz, and read every free lesson in this course. Lessons you answer correctly are recorded as complete.

Report a problem with this lesson

Log in to send a report.

Keyboard shortcuts

Keys available in a lesson
KeyAction
[ or Alt + ←Go to the previous lesson
] or Alt + →Go to the next lesson
?Open this list
EscClose this list

The keys do not work while the cursor is in a code editor or an input field.