⬅ Menu

☕ Java Notes 2026

Complete Beginner to Pro Guide

1. Hello World Program

The first program — prints "Hello, World!" to verify your Java setup is working.
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

2. Data Types

Define what kind of data a variable can hold (numbers, text, boolean, etc.).
int age = 25;
double salary = 45000.50;
char grade = 'A';
boolean isPass = true;
String name = "Md";

3. Variables

Named storage for data values — can be changed (unless final).
int marks = 85;
marks = 92;           // value changed

final double PI = 3.14159;  // constant

4. Operators

Symbols for calculations, comparisons, and logic.
int a = 10, b = 3;
System.out.println(a + b);   // 13
System.out.println(a > b);   // true
System.out.println(a % b);   // 1

5. If-else & Switch

Decision making based on conditions.
int marks = 78;
if (marks >= 90) {
    System.out.println("A+");
} else if (marks >= 60) {
    System.out.println("Pass");
} else {
    System.out.println("Fail");
}

// Switch
int day = 3;
switch (day) {
    case 1: System.out.println("Monday"); break;
    default: System.out.println("Other");
}

6. Loops

Repeat code while condition is true.
for (int i = 1; i <= 5; i++) {
    System.out.println(i);
}

int count = 1;
while (count <= 5) {
    System.out.println(count);
    count++;
}

7. Arrays

Fixed-size collection of same-type elements.
int[] numbers = {10, 20, 30, 40};
System.out.println(numbers[1]);     // 20
System.out.println(numbers.length); // 4

8. Class & Object (OOP)

Class = blueprint, Object = instance created from class.
class Student {
    String name;
    int age;

    void show() {
        System.out.println(name + " is " + age);
    }
}

Student s = new Student();
s.name = "Md";
s.age = 22;
s.show();

9. Inheritance

Child class reuses code from parent class.
class Animal {
    void eat() { System.out.println("Eating..."); }
}

class Dog extends Animal {
    void bark() { System.out.println("Woof!"); }
}

Dog d = new Dog();
d.eat();
d.bark();

10. String Class

Built-in class for text manipulation with many methods.
String text = "Hello Java 2026";
System.out.println(text.length());          // 15
System.out.println(text.toUpperCase());     // HELLO JAVA 2026
System.out.println(text.substring(0, 5));   // Hello

11. ArrayList (Dynamic)

Resizable array from Collections framework.
import java.util.ArrayList;

ArrayList list = new ArrayList<>();
list.add("Apple");
list.add("Mango");
System.out.println(list.get(1));    // Mango
list.remove(0);

12. Exception Handling

Catch and manage runtime errors gracefully.
try {
    int x = 10 / 0;
} catch (ArithmeticException e) {
    System.out.println("Cannot divide by zero!");
} finally {
    System.out.println("Cleanup done");
}