Java Programming Intermediate Guide: Mastering OOP, Collections, Exceptions, and MultithreadingNew
• Updated 3/13/2026 • javajava intermediatejava oopjava collectionsjava multithreadingjava exception handlinglearn javacompilequest
Java Programming – Intermediate Guide
This tutorial is designed for learners who already understand basic Java concepts like variables, loops, arrays, and simple classes. Now we will explore more powerful features that make Java suitable for building real-world applications.
In this guide, we will focus on deeper Object-Oriented Programming concepts, collections, exception handling, file operations, and multithreading.
1. Deep Dive into Object-Oriented Programming
Object-Oriented Programming (OOP) is the heart of Java. It allows programs to be organized using objects and classes.
Encapsulation
Encapsulation means hiding data inside a class and controlling access using methods.
class Student {
private String name;
public void setName(String n) {
name = n;
}
public String getName() {
return name;
}
}
The variable name is private so it cannot be accessed directly.
Inheritance
Inheritance allows a class to reuse properties and methods from another class.
class Animal {
void eat() {
System.out.println("Animal is eating");
}
}
class Dog extends Animal {
void bark() {
System.out.println("Dog is barking");
}
}
The Dog class inherits the eat() method from the Animal class.
Polymorphism
Polymorphism means "many forms". The same method name can behave differently.
Method Overloading
class MathUtils {
int add(int a, int b) {
return a + b;
}
int add(int a, int b, int c) {
return a + b + c;
}
}
Method Overriding
class Animal {
void sound() {
System.out.println("Animal sound");
}
}
class Cat extends Animal {
void sound() {
System.out.println("Cat meows");
}
}
2. Abstract Classes and Interfaces
Abstract Class
An abstract class cannot be instantiated directly.
abstract class Shape {
abstract void draw();
}
Interface
An interface defines behavior that classes must implement.
interface Vehicle {
void start();
}
class Car implements Vehicle {
public void start() {
System.out.println("Car started");
}
}
3. Packages and Access Modifiers
Packages help organize classes into groups.
package com.example.utilities;
Access Modifiers
- public – accessible everywhere
- private – accessible only within the class
- protected – accessible within the package and subclasses
- default – accessible within the package
4. Exception Handling
Exceptions are runtime errors that occur while the program is running.
Using try and catch
try {
int result = 10 / 0;
} catch (Exception e) {
System.out.println("An error occurred");
}
Finally Block
try {
int a = 5;
} finally {
System.out.println("This block always executes");
}
Custom Exception
class InvalidAgeException extends Exception {
public InvalidAgeException(String message) {
super(message);
}
}
5. Java Collections Framework
The Collections Framework helps manage groups of objects efficiently.
ArrayList
import java.util.ArrayList;
ArrayList<String> names = new ArrayList<>();
names.add("Alice");
names.add("Bob");
System.out.println(names);
LinkedList
import java.util.LinkedList;
LinkedList<Integer> numbers = new LinkedList<>();
numbers.add(10);
numbers.add(20);
HashSet
A HashSet stores unique values.
import java.util.HashSet;
HashSet<Integer> set = new HashSet<>();
set.add(1);
set.add(2);
set.add(2);
HashMap
import java.util.HashMap;
HashMap<String, Integer> ages = new HashMap<>();
ages.put("John", 25);
ages.put("Anna", 22);
6. Iterators
An iterator is used to loop through collections.
import java.util.Iterator;
Iterator<String> it = names.iterator();
while(it.hasNext()) {
System.out.println(it.next());
}
7. String Handling
String Class
String message = "Hello Java";
System.out.println(message.length());
System.out.println(message.toUpperCase());
StringBuilder
Used for modifying strings efficiently.
StringBuilder sb = new StringBuilder("Hello");
sb.append(" World");
System.out.println(sb);
8. File Handling
Java can read and write files using classes from the java.io package.
Reading a File
import java.io.File;
import java.util.Scanner;
File file = new File("data.txt");
Scanner sc = new Scanner(file);
while(sc.hasNextLine()) {
System.out.println(sc.nextLine());
}
Writing to a File
import java.io.FileWriter;
FileWriter writer = new FileWriter("data.txt");
writer.write("Hello File");
writer.close();
9. Multithreading
Multithreading allows Java to run multiple tasks at the same time.
Creating a Thread
class MyThread extends Thread {
public void run() {
System.out.println("Thread running");
}
}
Running the Thread
MyThread t = new MyThread();
t.start();
Runnable Interface
class MyTask implements Runnable {
public void run() {
System.out.println("Task running");
}
}
Thread t = new Thread(new MyTask());
t.start();
10. Synchronization
Synchronization ensures that only one thread accesses a resource at a time.
synchronized void printNumbers() {
for(int i = 1; i <= 5; i++) {
System.out.println(i);
}
}
Conclusion
At the intermediate level, Java becomes much more powerful. You now understand deeper OOP concepts, collections, file handling, and multithreading.
These skills are important for building real-world applications like web systems, desktop software, and backend services.
In the next stage, you will explore advanced topics such as Streams API, Lambda expressions, JDBC, networking, and modern frameworks like Spring.

