☕ Java — Learn From Zero

Playground: Replit Java | JDoodle — click, type, run.

What is Java?

Java is a statically-typed, object-oriented language that runs on the JVM. Write once, run anywhere. Used in enterprise, Android, and big systems.

  • Android apps
  • Enterprise backends (Spring)
  • Big data (Hadoop, Spark)
  • Cross-platform tools

Run Online — No Install

Use the playground links above.

🟢 Beginner — Core Basics

Your First Program

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

Execution starts in main.

Variables & Types

java
int age = 36;
double height = 1.78;
boolean isStudent = true;
String name = "Ada";

Types are explicit: int, double, boolean, String.

If / Else

java
int age = 18;
if (age >= 18) System.out.println("Vote");
else System.out.println("Too young");

Curly braces group statements.

Loops

java
for (int i = 0; i < 5; i++) System.out.println(i);
int n = 3;
while (n-- > 0) System.out.println(n);

Same loop styles as C-style languages.

Methods

java
static int add(int a, int b) {
  return a + b;
}

Functions inside classes are called methods.

Arrays & Lists

java
String[] fruits = {"apple", "banana"};
java.util.List list = new java.util.ArrayList<>();

Prefer List over raw arrays.

🟡 Intermediate — Building Real Programs

Classes & Objects

java
class Person {
  String name;
  Person(String n) { name = n; }
}

Encapsulate data in classes.

OOP Principles

java
interface Animal { void speak(); }
class Dog implements Animal {
  public void speak() { System.out.println("Woof"); }
}

Use interface and implements.

Exceptions

java
try {
  int x = 1 / 0;
} catch (ArithmeticException e) {
  System.out.println("No divide by zero");
}

Catch errors with try/catch.

Collections

java
java.util.Map m = new java.util.HashMap<>();
m.put("Ada", 36);

Use Map, Set, List.

Streams

java
List nums = List.of(1,2,3,4);
long even = nums.stream().filter(n -> n % 2 == 0).count();

Functional pipelines with streams.

🔴 Advanced — Pro Concepts

Generics

java
class Box {
  T value;
  Box(T v) { value = v; }
}

Parameterize types safely.

Lambdas

java
Runnable r = () -> System.out.println("Hi");
new Thread(r).start();

Lambdas are anonymous functions.

Records (Java 16+)

java
record Point(int x, int y) {}
Point p = new Point(1, 2);

Compact immutable data classes.

Concurrency

java
ExecutorService ex = Executors.newFixedThreadPool(2);
ex.submit(() -> System.out.println("Task"));

Use executors, not raw threads.

What's Next?

  • Build a tiny project: Calculator, To-Do App, Weather Widget
  • Read the official docs and a good book
  • Solve Exercism exercises
  • Join a community & share your code

Practice daily for 20 minutes. Consistency > intensity.