Java is a statically typed language: the compiler checks which kinds of values your variables and methods accept before the program runs. It is used for services, desktop applications, build tools and command-line programs. You can learn its core language without installing a web framework or creating an account anywhere.
Course baseline: Java 21. Every complete example uses features available without preview flags in Java 21. This is a compatibility target, not a claim about the newest Java release. Use a maintained JDK distribution that supports this baseline, and install its security updates. Newer JDKs can compile these examples with --release 21.
Work through four foundations lessons, then objects and collections, files and streams, concurrency and testing, and finally HTTP and a persistent command-line project. Each lesson names its source file. Save examples in separate folders so their compiled classes cannot accidentally interfere.
Understand the tools
The JDK, or Java Development Kit, contains the compiler and development tools. The JVM, or Java Virtual Machine, executes compiled Java bytecode. A JRE means the runtime needed to execute applications; installing only a runtime is insufficient for this course because you need javac.
The usual path is source text in a .java file, compilation into .class bytecode, then execution by the JVM. The runtime may compile frequently executed bytecode into machine instructions. Portability still has boundaries: files, installed libraries and operating-system behavior must also suit the target machine.
Install a JDK for your operating system and processor architecture using the official setup instructions. Configure your terminal's PATH to include that JDK's bin directory; JAVA_HOME, when tools require it, points to the JDK root. Open a fresh terminal and check:
java --version
javac --version
Both commands should identify the intended JDK. Exact patch numbers vary. If one command is missing or reports a different major version, resolve the installation or path mismatch before proceeding. An editor's selected JDK and your terminal's JDK can differ.
Your first complete program
Save this as Hello.java. Java names are case-sensitive, and the public class name must match the file name.
public class Hello {
public static void main(String[] args) {
String name = args.length == 0 ? "learner" : args[0];
System.out.println("Hello, " + name + "!");
}
}
Compile and run from the folder containing that file:
javac --release 21 Hello.java
java -cp . Hello Mira
java Hello
The first run prints Hello, Mira!; the second prints Hello, learner!. Successful compilation normally prints nothing. -cp . puts the current folder on the classpath, the places Java searches for application classes.
public makes the entry method accessible; static lets the runtime call it without first creating an object. void means it returns no value. String[] args holds command-line arguments, excluding the class name. The conditional expression chooses a default before accessing the first element. You will unpack these details in the next lessons.
For a quick experiment, java Hello.java Mira compiles and runs the single source file without leaving a normal application class file. Do not confuse that source-file launch mode with java Hello, which runs previously compiled bytecode. JShell is another option: run jshell, enter 2 + 3, then enter /exit.
Package and troubleshoot
A JAR is an archive for classes and related resources. After compilation:
jar --create --file hello.jar --main-class Hello Hello.class
java -jar hello.jar Mira
This prints the same greeting. A JAR does not automatically bundle a JVM or external dependencies. Larger projects usually introduce packages such as com.example.tasks, with matching source directories, and a build tool to repeat compilation and testing reliably.
Common mistakes include saving Hello.java.txt, running from the wrong folder, and compiling with a newer target than the installed runtime can load. --release 21 checks both language features and the documented platform API available for that target. Read the first compiler error first; later errors may be consequences.
Exercise and solution guidance
Change the greeting to accept an optional second argument for a city. With Mira Pune, print Hello, Mira from Pune!; with no arguments, preserve the original default. Predict the one-argument output before running it.
Guard the second array access with args.length > 1, build the optional city suffix, and keep one final print statement. Test zero, one and two arguments. Recompile after changing the source; otherwise java Hello can quietly execute an older class file.
Official references
- OpenJDK project: the open-source JDK implementation and projects.
- Java 21 compiler manual: compilation and
--release. - Java 21 launcher manual: classpath, JAR and source-file execution.
Next: Variables and Types in Java.

