From zero to job-ready. Master Java development with plain-English guidance, real-world examples, and hands-on projects. Written for absolute beginners and aspiring developers.
Start typing to filter sections.
Java is a programming language that lets you write instructions for computers. Think of it as teaching a robot to perform tasksβyou write code, and the computer executes it. Java is used to build websites, mobile apps (Android), enterprise systems, and cloud applications.
Do I need a CS degree? No. Self-taught developers get hired if they build projects and pass interviews.
How long to become job-ready? 12-16 weeks with 15-20 hours/week of focused practice.
What tools do I need? JDK, IntelliJ IDEA (or Eclipse), Git, and a GitHub account.
Is Java still relevant in 2025? Yes. Java powers 90% of Fortune 500 backend systems.
Step 1: Download and install JDK (Java Development Kit) from Oracle or use OpenJDK.
Step 2: Install IntelliJ IDEA Community Edition (free) or Eclipse.
Step 3: Verify installation by typing java -version in terminal/command prompt.
Step 4: Create your first project: File β New Project β Java β Hello World.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Explanation:
public class HelloWorld β Defines a class named HelloWorld.public static void main β Entry point; program starts here.System.out.println β Prints text to console.Variables store data. Java has 8 primitive types:
| Type | Size | Example | Use Case |
|---|---|---|---|
| int | 4 bytes | int age = 25; | Whole numbers |
| double | 8 bytes | double price = 99.99; | Decimal numbers |
| boolean | 1 bit | boolean isActive = true; | True/false flags |
| char | 2 bytes | char grade = 'A'; | Single character |
| String | Object | String name = "John"; | Text/words |
int a = 10, b = 20; int sum = a + b; // Addition: 30 int diff = b - a; // Subtraction: 10 int product = a * b; // Multiplication: 200 int quotient = b / a; // Division: 2 int remainder = b % a; // Modulus: 0 boolean isEqual = (a == b); // false boolean isGreater = (b > a); // true
int score = 85;
if (score >= 90) {
System.out.println("Grade: A");
} else if (score >= 80) {
System.out.println("Grade: B");
} else if (score >= 70) {
System.out.println("Grade: C");
} else {
System.out.println("Grade: F");
}
// For loop - when you know iteration count
for (int i = 0; i < 5; i++) {
System.out.println("Count: " + i);
}
// While loop - condition-based
int count = 0;
while (count < 5) {
System.out.println("Count: " + count);
count++;
}
// Do-While - executes at least once
int num = 0;
do {
System.out.println("Number: " + num);
num++;
} while (num < 5);
public class Calculator {
// Method to add two numbers
public static int add(int a, int b) {
return a + b;
}
// Method with no return value
public static void greet(String name) {
System.out.println("Hello, " + name + "!");
}
public static void main(String[] args) {
int result = add(10, 20);
System.out.println("Sum: " + result);
greet("John");
}
}
Key Points:
public β Accessible from anywhere.static β Can be called without creating an object.int β Return type (use void for no return).(int a, int b).OOP is a programming style that organizes code into objectsβreal-world entities with properties (data) and behaviors (methods). Java is 100% object-oriented.
Four Pillars of OOP:
// Define a class
public class Car {
// Properties (fields)
String brand;
String model;
int year;
// Constructor
public Car(String brand, String model, int year) {
this.brand = brand;
this.model = model;
this.year = year;
}
// Method (behavior)
public void displayInfo() {
System.out.println(year + " " + brand + " " + model);
}
}
// Create objects
public class Main {
public static void main(String[] args) {
Car car1 = new Car("Toyota", "Camry", 2023);
Car car2 = new Car("Honda", "Accord", 2024);
car1.displayInfo(); // Output: 2023 Toyota Camry
car2.displayInfo(); // Output: 2024 Honda Accord
}
}
public class BankAccount {
private double balance; // Private = hidden from outside
// Constructor
public BankAccount(double initialBalance) {
this.balance = initialBalance;
}
// Getter
public double getBalance() {
return balance;
}
// Setter with validation
public void deposit(double amount) {
if (amount > 0) {
balance += amount;
}
}
public void withdraw(double amount) {
if (amount > 0 && amount <= balance) {
balance -= amount;
}
}
}
Why Encapsulation? Protects data from invalid changes. You control access via methods.
// Parent class
public class Animal {
public void eat() {
System.out.println("This animal eats food.");
}
}
// Child class inherits from Animal
public class Dog extends Animal {
public void bark() {
System.out.println("The dog barks.");
}
}
public class Main {
public static void main(String[] args) {
Dog myDog = new Dog();
myDog.eat(); // Inherited from Animal
myDog.bark(); // Defined in Dog
}
}
Use Case: Avoid code duplication. Common features go in parent class.
// Method Overriding
class Animal {
public void makeSound() {
System.out.println("Animal makes a sound");
}
}
class Cat extends Animal {
@Override
public void makeSound() {
System.out.println("Meow");
}
}
class Dog extends Animal {
@Override
public void makeSound() {
System.out.println("Bark");
}
}
public class Main {
public static void main(String[] args) {
Animal myAnimal = new Dog();
myAnimal.makeSound(); // Output: Bark (runtime polymorphism)
}
}
// Interface defines a contract
interface Payable {
void processPayment(double amount);
}
// Implement the interface
class CreditCard implements Payable {
@Override
public void processPayment(double amount) {
System.out.println("Processing $" + amount + " via Credit Card");
}
}
class PayPal implements Payable {
@Override
public void processPayment(double amount) {
System.out.println("Processing $" + amount + " via PayPal");
}
}
When to use: When multiple classes share the same behavior but implement it differently.
Collections are data structures that store groups of objects. Think of them as smart containers that automatically resize and provide useful methods.
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList fruits = new ArrayList<>();
// Add items
fruits.add("Apple");
fruits.add("Banana");
fruits.add("Orange");
// Access items
System.out.println(fruits.get(0)); // Apple
// Size
System.out.println("Size: " + fruits.size());
// Loop through
for (String fruit : fruits) {
System.out.println(fruit);
}
// Remove item
fruits.remove("Banana");
}
}
Use Case: When you need a list that grows/shrinks dynamically.
import java.util.HashMap;
public class Main {
public static void main(String[] args) {
HashMap ages = new HashMap<>();
// Add key-value pairs
ages.put("John", 25);
ages.put("Sarah", 30);
ages.put("Mike", 28);
// Get value by key
System.out.println(ages.get("Sarah")); // 30
// Check if key exists
if (ages.containsKey("John")) {
System.out.println("John's age: " + ages.get("John"));
}
// Loop through
for (String name : ages.keySet()) {
System.out.println(name + " is " + ages.get(name) + " years old");
}
}
}
Use Case: Store data as pairs (like a dictionary). Fast lookups.
import java.util.HashSet;
public class Main {
public static void main(String[] args) {
HashSet uniqueNames = new HashSet<>();
uniqueNames.add("Alice");
uniqueNames.add("Bob");
uniqueNames.add("Alice"); // Duplicate - won't be added
System.out.println(uniqueNames); // [Alice, Bob]
System.out.println("Size: " + uniqueNames.size()); // 2
}
}
Use Case: Remove duplicates automatically.
| Collection | Duplicates? | Ordered? | Best For |
|---|---|---|---|
| ArrayList | Yes | Yes | Lists, sequences |
| HashMap | Keys: No, Values: Yes | No | Key-value lookups |
| HashSet | No | No | Unique items |
| LinkedList | Yes | Yes | Frequent add/remove |
| TreeSet | No | Sorted | Sorted unique items |
Spring Boot is a framework that makes it easy to build production-ready web applications and REST APIs. It handles configuration automatically so you focus on business logic.
Why Spring Boot?
Step 1: Go to start.spring.io
Step 2: Select: Maven, Java 17, Spring Boot 3.x
Step 3: Add dependencies: Spring Web, Spring Data JPA, H2 Database
Step 4: Generate and download the project
Step 5: Open in IntelliJ, run DemoApplication.java
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("/api/users")
public class UserController {
private List users = new ArrayList<>();
// GET all users
@GetMapping
public List getAllUsers() {
return users;
}
// GET user by ID
@GetMapping("/{id}")
public User getUserById(@PathVariable Long id) {
return users.stream()
.filter(u -> u.getId().equals(id))
.findFirst()
.orElse(null);
}
// POST create new user
@PostMapping
public User createUser(@RequestBody User user) {
users.add(user);
return user;
}
// PUT update user
@PutMapping("/{id}")
public User updateUser(@PathVariable Long id, @RequestBody User updatedUser) {
User user = getUserById(id);
if (user != null) {
user.setName(updatedUser.getName());
user.setEmail(updatedUser.getEmail());
}
return user;
}
// DELETE user
@DeleteMapping("/{id}")
public String deleteUser(@PathVariable Long id) {
users.removeIf(u -> u.getId().equals(id));
return "User deleted";
}
}
| Annotation | Purpose | Example Use |
|---|---|---|
| @RestController | Marks class as REST API controller | Handle HTTP requests |
| @RequestMapping | Base URL for all endpoints | /api/users |
| @GetMapping | Handle GET requests | Fetch data |
| @PostMapping | Handle POST requests | Create new record |
| @PutMapping | Handle PUT requests | Update existing record |
| @DeleteMapping | Handle DELETE requests | Remove record |
| @PathVariable | Extract value from URL | /users/{id} |
| @RequestBody | Parse JSON from request | Receive user data |
Using Postman:
http://localhost:8080/api/users - Fetch all usershttp://localhost:8080/api/users - Send JSON bodyhttp://localhost:8080/api/users/1 - Update user with ID 1http://localhost:8080/api/users/1 - Delete userEvery real application needs to store data permanently. Java connects to databases using JDBC, JPA, and Hibernate.
Common Databases:
-- Create table
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100),
email VARCHAR(100),
age INT
);
-- Insert data
INSERT INTO users (name, email, age) VALUES ('John Doe', '[email protected]', 25);
-- Read data
SELECT * FROM users;
SELECT name, email FROM users WHERE age > 21;
-- Update data
UPDATE users SET age = 26 WHERE id = 1;
-- Delete data
DELETE FROM users WHERE id = 1;
-- Joins
SELECT orders.id, users.name
FROM orders
INNER JOIN users ON orders.user_id = users.id;
import java.sql.*;
public class DatabaseDemo {
public static void main(String[] args) {
String url = "jdbc:mysql://localhost:3306/mydb";
String user = "root";
String password = "password";
try {
// Connect to database
Connection conn = DriverManager.getConnection(url, user, password);
// Execute query
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users");
// Process results
while (rs.next()) {
System.out.println(rs.getString("name"));
}
// Close connection
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Instead of writing SQL manually, JPA (Java Persistence API) lets you work with objects.
import javax.persistence.*;
@Entity
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String email;
private int age;
// Getters and setters
}
// Repository interface
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserRepository extends JpaRepository {
List findByName(String name);
List findByAgeGreaterThan(int age);
}
// Usage in Service
@Service
public class UserService {
@Autowired
private UserRepository userRepository;
public List getAllUsers() {
return userRepository.findAll();
}
public User saveUser(User user) {
return userRepository.save(user);
}
}
Projects prove you can code. Recruiters want to see GitHub repos with working code, not just certificates.
Goal: Build 3-5 projects that demonstrate different skills.
Skills: Spring Boot, REST API, CRUD, MySQL
Features:
Tech Stack: Spring Boot + JPA + MySQL + Postman
Timeline: 3-5 days
Skills: Full CRUD, Relationships, Validation
Features:
Tech Stack: Spring Boot + JPA + H2/MySQL
Timeline: 5-7 days
Skills: Authentication, Pagination, File Upload
Features:
Tech Stack: Spring Boot + Spring Security + JWT + PostgreSQL
Timeline: 10-14 days
Skills: Full-stack, Relationships, Comments
Features:
Tech Stack: Spring Boot + React/Thymeleaf + MySQL
Timeline: 14-21 days
Java interviews have 3 rounds:
1. What is Java? Why is it platform-independent?
Java compiles to bytecode that runs on JVM (Java Virtual Machine). JVM is platform-specific but bytecode is universal.
2. Difference between JDK, JRE, and JVM?
3. What is OOP? Explain the 4 pillars.
Encapsulation, Inheritance, Polymorphism, Abstraction (see OOP section above).
4. Difference between == and .equals()?
5. What is a constructor?
Special method called when creating an object. Same name as class, no return type.
6. Difference between ArrayList and LinkedList?
7. What is a HashMap? How does it work?
Stores key-value pairs. Uses hashing to find values in O(1) time.
8. Difference between interface and abstract class?
9. What is exception handling? Try-catch example.
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Cannot divide by zero");
} finally {
System.out.println("Always executes");
}
10. What is multithreading?
Running multiple threads (tasks) concurrently. Use Thread class or Runnable interface.
Easy Problems (Start Here):
Medium Problems:
Practice Platforms:
1. What is Spring Boot? Why use it?
Framework to build production-ready apps fast. Auto-configuration, embedded server, less boilerplate.
2. Explain @RestController vs @Controller
3. What is Dependency Injection?
Spring creates and manages objects (beans). Use @Autowired to inject dependencies.
4. Difference between @Component, @Service, @Repository?
5. How to handle exceptions globally?
Use @ControllerAdvice and @ExceptionHandler.
| Level | Experience | Salary Range | Key Skills |
|---|---|---|---|
| Junior | 0-2 years | $70K - $85K | Core Java, SQL, Git |
| Mid-Level | 3-5 years | $95K - $125K | Spring Boot, Microservices, REST APIs |
| Senior | 6-8 years | $130K - $165K | System Design, Cloud (AWS), Architecture |
| Lead/Architect | 9+ years | $170K - $220K | Team Leadership, Multi-cloud, FinOps |
Note: Salaries vary by location. SF/NYC +25%, remote -10%, healthcare/finance +$10K-$15K premium.
Can I learn Java with no programming experience?
Yes. Java is beginner-friendly. Start with basics, practice daily, build projects. Most self-taught devs become job-ready in 12-16 weeks.
Do I need a computer science degree?
No. Many companies hire based on skills and projects. Build a strong GitHub portfolio and pass coding interviews.
What's the fastest way to learn Java?
Follow this path: 1) Java basics (4 weeks) β 2) OOP & Collections (3 weeks) β 3) Spring Boot (3 weeks) β 4) Build 3 projects (4 weeks) β 5) Interview prep (2 weeks).
Java vs Python - which to learn first?
Java for: Backend, enterprise, Android, higher salary. Python for: Data science, automation, AI/ML. Choose based on career goals.
Is Java still relevant in 2025?
Absolutely. Used by 90% of Fortune 500 companies. Banking, healthcare, e-commerce, government all run on Java.
How long until I'm job-ready?
12-16 weeks of focused learning (15-20 hours/week). Key milestones: basics β OOP β Spring Boot β 3 projects β interview prep.
Best IDE for Java?
IntelliJ IDEA (most popular), Eclipse (free), or VS Code with Java extensions.