Java is a statically typed, compiled-to-bytecode language. You write .java source. javac produces .class files of JVM bytecode. The Java Virtual Machine loads those classes and executes them (usually with a JIT that turns hot bytecode into native code).
Mental model: javac checks types and emits bytecode. The JVM checks class files, links them, and runs them. A compile error never becomes a runtime surprise of the same kind — a different check may still fail later (cast, NPE, missing class).
| Term | What it is | You need it to… |
|---|---|---|
| JVM | The process that loads bytecode and runs it | Execute a program |
| JRE | JVM + class libraries (historical packaging) | Run (modern JDKs ship a runtime) |
| JDK | Compiler, tools (javac, jar, javadoc) + runtime | Build |
java -version // runtime javac -version // compiler — missing if you only have a JRE
public class Hello {
public static void main(String[] args) {
System.out.println("hello");
}
}
Hello.java when the class is public.main is the entry point the launcher looks up by name and signature. It is not a language keyword.public static void main(String[] args). The parameter may be named anything; String... args is also accepted.javac Hello.java. Run: java Hello (class name, no .class).From Java 11 you can also java Hello.java for a single-file program (the launcher compiles it in memory). That is for sketches, not a project.
Wrong main: missing static, returning int, or Main with a capital M. The JVM will start, then report that it cannot find the method.
The lexer splits source into tokens. You must be able to name each kind.
| Kind | Examples | Rule |
|---|---|---|
| Identifier | count, StringBuilder | Letter or _ or $, then letters/digits/_/$. Cannot be a keyword. |
| Keyword | class, if, new, void | Reserved. var, yield, record are restricted identifiers (context-sensitive). |
| Literal | 42, 3.14, 'A', "hi", true, null | A value written in source. |
| Separator | ; ( ) { } [ ] , . | Structure. |
| Operator | + == && ? : | See Operators. |
1_000_000. Not at the ends, not next to a decimal point.null is a literal, not a keyword in older lists — it is still reserved.1st does not compile.// end of line /* block — may span lines */ /** Javadoc — documents the next type or member */
/* outer /* inner */ still-code */ is a classic exam trap.javadoc. Write it on public types and methods; skip restating the method name.// — that is not a comment.| Thing | Convention | Example |
|---|---|---|
| Class, interface, enum, record | PascalCase, noun | ArrayList, Runnable |
| Method | camelCase, verb | indexOf, isEmpty |
| Field / local | camelCase | itemCount |
Constant (static final) | UPPER_SNAKE | MAX_BUFFER |
| Package | lowercase, dotted | com.example.util |
The compiler does not enforce these. Reviewers and tools do. A class named doWork compiles and then confuses every reader.
public top-level type per file; its name equals the file name.package declaration, if present, is first (after comments). Then imports. Then types.package line) is for throwaway files. Libraries cannot import default-package types cleanly.// Incorrect: public class in the wrong file
// File: Demo.java
public class Hello { } // javac error
// Correct
// File: Hello.java
public class Hello { }
java Hello.class — the launcher wants a class name, not a file..class files (IDE vs terminal mismatch).main must live in a class with the same name as the project.System.out.println as “the way to return a value.” It writes to a stream; it does not return from main.java -version and javac -version on your PATH.main signature. Know why each word is there (public so the launcher can see it, static so no instance is required).~ Good luck with your revision! ~