Foundation

01 — Getting Started

Previous: 00 Index · Next: 02 Variables & Types

New here? If you have not installed the JDK, downloaded the project, or set up an IDE yet, complete Environment Setup first — everything you need is on this site.


What you need

Tool Purpose
JDK 21+ Compiler (javac) + runtime (java)
Terminal Run commands
This project All lessons with runnable examples

Check your install:

bash
1java -version2javac -version

You should see version 21 or higher (25 works too).


Your first program

Every Java app starts with a class and a main method — the entry point.

java
1public class Hello {2    public static void main(String[] args) {3        System.out.println("Hello, Java!");4    }5}

▶️ java pkg0intro/intro1AboutJava.java · java pkg1core/core1HelloWorld.java

bash
1java pkg0intro/intro1AboutJava.java2java pkg1core/core1HelloWorld.java

💡 Key idea: The file name must match the public class name (Hello.javaclass Hello).


How this project is organized

code
1pkg0intro     → What is Java? (start here)2pkg1core      → Language fundamentals (core1 → core28)3pkg2versions  → Java 5 through 21 features4pkg3–pkg4     → Data structures & algorithms5pkg5leetcode  → Interview coding problems6pkg6–pkg20    → JVM, concurrency, I/O, databases, testing…7docs/02-learn/   → These tutorials (read in order)8docs/03-interview/ → Interview Q&A (use later)

Each class is self-contained — open one file, run it, learn one concept.


Two ways to run code

1. Single-file launch (easiest)

bash
1java pkg1core/core1HelloWorld.java

No javac step — Java compiles and runs in one command (Java 11+).

2. Compile then run (classic)

bash
1javac -d out pkg1core/core1HelloWorld.java2java -cp out pkg1core.core1HelloWorld

Note: package name in the -cp command (pkg1core.core1HelloWorld).


The compile → run pipeline

code
1YourCode.java  ──javac──►  YourCode.class (bytecode)23                           java (JVM)45                           Program output

Read the full picture in 01-orientation/01-TutorialAndHistory.md.


⚠️ Common mistakes

Mistake Fix
java Hello without compiling (classic mode) Use java Hello.java or compile first
File name ≠ class name Rename file or class to match
Wrong directory Run from project root JavaMastery/
Missing semicolon ; Every statement ends with ;

Practice

  1. Run intro1AboutJava, intro2HistoryOfJava, intro3Objectives.
  2. Run core1HelloWorld and change the printed message.
  3. Add a second System.out.println line.

Next → 02 Variables & Types