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)
Reading settings
These settings are remembered on this device only.
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.