Java Programming
Complete Notes
Basics to Advanced · OOP · Collections · Multithreading — All in Easy English
📋 Table of Contents — 15 Units
Introduction to Java
What is Java and why is it everywhere?
What is Java?
Java is a high-level, object-oriented programming language developed by James Gosling at Sun Microsystems (now Oracle) in 1995. It's designed to be platform-independent and follows the principle of "Write Once, Run Anywhere" (WORA).
Key Features of Java
How Java Works — JVM, JRE, JDK
| Component | Full Name | Purpose |
|---|---|---|
| JVM | Java Virtual Machine | Executes Java bytecode, provides platform independence |
| JRE | Java Runtime Environment | JVM + libraries needed to run Java programs |
| JDK | Java Development Kit | JRE + development tools (compiler, debugger) |
Java Program Execution Flow
Source Code (.java)
↓
javac compiler
↓
Bytecode (.class)
↓
JVM
↓
Machine Code (platform-specific)Your First Java Program
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } } // Output: Hello, World!
Java vs Other Languages
| Feature | Java | C++ | Python |
|---|---|---|---|
| Platform | Platform Independent | Platform Dependent | Platform Independent |
| Memory | Automatic (Garbage Collection) | Manual | Automatic |
| Speed | Fast | Faster | Slower |
| Syntax | Moderate | Complex | Simple |
| Use Case | Enterprise, Android | System software, games | AI, web, scripting |
Variables & Data Types
Storing and managing data in Java.
Variables in Java
A variable is a named container that stores data. In Java, you must declare the variable type before using it.
int age = 20; double price = 99.99; String name = "Ali"; boolean isStudent = true;
Data Types in Java
| Type | Size | Range/Values | Example |
|---|---|---|---|
| byte | 1 byte | -128 to 127 | byte b = 100; |
| short | 2 bytes | -32,768 to 32,767 | short s = 5000; |
| int | 4 bytes | -2³¹ to 2³¹-1 | int num = 12345; |
| long | 8 bytes | -2⁶³ to 2⁶³-1 | long l = 100000L; |
| float | 4 bytes | ~7 decimal digits | float f = 3.14f; |
| double | 8 bytes | ~15 decimal digits | double d = 3.14159; |
| char | 2 bytes | Unicode character | char c = 'A'; |
| boolean | 1 bit | true or false | boolean b = true; |
Type Casting
Widening (Automatic): byte → short → int → long → float → double
int i = 100; double d = i; // Automatic casting
Narrowing (Manual): double → float → long → int → short → byte
double d = 99.99; int i = (int) d; // i = 99 (decimal part lost)
Constants (final keyword)
final int MAX_AGE = 100; // MAX_AGE = 200; // Error! Cannot modify
Operators in Java
Performing operations on data — arithmetic, logical, and more.
Types of Operators
| Type | Operators | Example |
|---|---|---|
| Arithmetic | +, -, *, /, % | 5 + 3 = 8 |
| Relational | ==, !=, >, <, >=, <= | 5 > 3 → true |
| Logical | && (AND), || (OR), ! (NOT) | true && false → false |
| Assignment | =, +=, -=, *=, /= | x += 5 |
| Unary | ++, --, +, -, ! | x++ |
| Ternary | ? : | x > 5 ? "yes" : "no" |
Increment & Decrement
int x = 5; x++; // Post-increment: use then increment → x = 6 ++x; // Pre-increment: increment then use → x = 7 int a = 10; int b = a++; // b = 10, then a = 11 int c = ++a; // a = 12, then c = 12
🎉 Congratulations!
You've completed the Java Programming course! Keep practicing and building projects. Best of luck! ☕🌟

