← Java from Scratch Lesson 1 of 88 · 10 XP

Syntax

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

Java is a language released by Sun (now Oracle) in 1995. It's used to write servers, Android apps, Minecraft and banking systems. Its motto is "write once, run anywhere".

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}
  • all code lives inside a class; public class Main must be in a file called Main.java — the file name = the class name;
  • main is the entry point, and its signature is always public static void main(String[] args);
  • statements end with ;, blocks go in { }; case matters: Main and main are different names;
  • classes are named in PascalCase, methods and variables in camelCase.

What's under the hood. javac compiles Main.java not into machine code but into bytecode — the file Main.class. It's run by the JVM (the Java Virtual Machine): at first it interprets it, and it turns the "hot" spots into machine code on the fly (JIT). That's why one .class file works on Windows, Linux and macOS — each system has its own JVM. Here Java is compiled and run on the server, in a sandbox.

Task. Print Hello World.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.