🎓 A1Learner
🔍
0 of 48 lessons completed

Java Introduction

Java is a programming language for writing programs that run on many kinds of computer. A Java program runs on the Java Virtual Machine, so the same program can run on different computers.

The smallest Java program

This program has one class and one main method. The println line prints one greeting.

public class Main {
  public static void main(String[] args) {
    System.out.println("Hello, World!");
  }
}

Two lines in order

Programs run from top to bottom. The first println line runs before the second one.

public class Main {
  public static void main(String[] args) {
    System.out.println("Hello, World!");
    System.out.println("Welcome to Java");
  }
}

Example

public class Main {
  public static void main(String[] args) {
    System.out.println("Hello, World!");
    System.out.println("Java runs on the JVM");
    System.out.println("One program, many computers");
  }
}

Key points

  • The Java Virtual Machine is called the JVM.
  • The JVM runs Java programs on different computers.
  • Write once, run anywhere describes that reach.
  • Every Java program in this course has a class named Main.
  • The main method is where the program starts.
  • System.out.println prints one line of output.
  • Packages organise many files in big programs.

In this example, the program prints three lines in order. The first line is a greeting. The second line names the JVM. The third line states that one program can run on many computers.

Note

The JVM is a program that runs Java code.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

What runs a Java program on a computer?