Java Programming Cheatsheet – Collections, OOP, Exceptions
Introduction
Java is one of the most widely used programming languages in engineering courses, software development, and technical interviews. Whether you are preparing for semester exams, a coding test, or placement interviews, a well-structured Java cheatsheet helps you quickly revise key concepts without getting lost in bulky textbooks.
This article provides a comprehensive Java programming cheatsheet focusing on three crucial areas:
- Collections Framework – Lists, Sets, Maps, Queues
- Object-Oriented Programming (OOP) – Inheritance, Polymorphism, Abstraction, Encapsulation
- Exception Handling – Try-catch, throws, custom exceptions
By the end of this guide, you’ll have a handy resource for revision, projects, and coding practice.

Why Use a Java Cheatsheet?
- Quick Revision: Summarizes core concepts for last-minute study.
- Exam-Oriented: Covers the most frequently asked questions.
- Interview Preparation: Short notes on collections, OOP, and exceptions are often tested.
- Practical Coding: Ready reference while working on projects.
Java Basics (Before We Dive In)
Before jumping into collections, OOP, and exceptions, let’s quickly recap the foundation:
- Data Types: int, double, float, char, boolean, String
- Control Structures: if-else, switch, loops (for, while, do-while)
- Operators: Arithmetic (+, -, *), Relational (==, !=, >), Logical (&&, ||)
- Methods:
public static void main(String[] args)
is always the entry point

Java Collections Framework Cheatsheet
The Collections Framework is one of the most powerful parts of Java. It provides built-in data structures for handling objects efficiently.
Key Interfaces
- Collection – Base interface for List, Set, Queue
- List – Ordered, allows duplicates (
ArrayList
,LinkedList
) - Set – Unordered, unique elements (
HashSet
,TreeSet
) - Queue – FIFO structure (
PriorityQueue
,LinkedList
) - Map – Key-value pairs (
HashMap
,TreeMap
)
Common Classes and Usage
ArrayList
- Resizable array, allows duplicates
import java.util.*;
class Demo {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>();
list.add("Java");
list.add("Python");
list.add("C++");
System.out.println(list);
}
}
HashSet
- Stores unique values, no order guarantee
HashSet<Integer> set = new HashSet<>();
set.add(10);
set.add(20);
set.add(10); // ignored
System.out.println(set);
HashMap
- Stores data as key-value pairs
HashMap<Integer, String> map = new HashMap<>();
map.put(1, "Java");
map.put(2, "Python");
System.out.println(map.get(1));

Object-Oriented Programming (OOP) Cheatsheet
Java is built on OOP principles. Here are the four pillars of OOP:
1. Encapsulation
- Wrapping data and methods in a single class
- Use
private
variables withgetter
andsetter
methods
class Student {
private String name;
public void setName(String name) { this.name = name; }
public String getName() { return name; }
}
2. Inheritance
- One class inherits another’s properties using
extends
class Animal { void eat(){ System.out.println("eating..."); } }
class Dog extends Animal { void bark(){ System.out.println("barking..."); } }
3. Polymorphism
- Compile-time (Method Overloading) and Run-time (Method Overriding)
class MathOps {
int add(int a, int b){ return a+b; }
double add(double a, double b){ return a+b; }
}
4. Abstraction
- Hiding implementation details
- Done using abstract classes or interfaces
abstract class Shape {
abstract void draw();
}
class Circle extends Shape {
void draw() { System.out.println("Drawing circle"); }
}

Exception Handling Cheatsheet
Errors are inevitable in programming. Java exceptions help handle runtime issues gracefully.
Exception Hierarchy
- Throwable
- Error (cannot be handled, e.g.,
OutOfMemoryError
) - Exception (can be handled, e.g.,
IOException
,ArithmeticException
)
- Error (cannot be handled, e.g.,
Try-Catch Block
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Cannot divide by zero");
}
Finally Block
- Executes regardless of exception
try { System.out.println("Try block"); }
catch(Exception e){ System.out.println("Exception"); }
finally { System.out.println("Always runs"); }
Throw vs Throws
throw
is used to throw an exception explicitlythrows
declares exceptions in method signature
void checkAge(int age) throws Exception {
if(age < 18) throw new Exception("Not eligible");
}
Custom Exception
class MyException extends Exception {
MyException(String msg){ super(msg); }
}

Quick Revision Table
Topic | Key Points |
---|---|
Collections | List, Set, Map, Queue |
OOP Pillars | Encapsulation, Inheritance, Polymorphism, Abstraction |
Exceptions | try-catch-finally, throw, throws, custom exceptions |
FAQs on Java Programming Cheatsheet
Q1. What is the difference between List and Set in Java?
A List allows duplicates and maintains order, while a Set does not allow duplicates and does not guarantee order.
Q2. What are checked vs unchecked exceptions?
Checked exceptions are handled at compile-time (e.g., IOException), whereas unchecked exceptions occur at runtime (e.g., NullPointerException).
Q3. Why use the Collections framework in Java?
It simplifies programming by providing built-in data structures and algorithms, reducing the need for custom implementations.
Q4. Can a Java class implement multiple interfaces?
Yes, Java supports multiple interface implementation, which helps achieve multiple inheritance.
Q5. What is the role of finally
in exception handling?
The finally
block ensures that important cleanup code runs whether an exception occurs or not.
Conclusion
This Java programming cheatsheet is designed to help BTech students and beginners revise essential concepts quickly. Whether it’s for exams, coding labs, or placement preparation, focusing on Collections, OOP principles, and Exception Handling ensures you are well-prepared.
Keep this guide bookmarked for revision before your next test or interview. Practice small coding exercises alongside this cheatsheet to strengthen your understanding.
[CTA BUTTON: Download Java Cheatsheet PDF — Link: https://btechcheatsheets.com/java-cheatsheet-pdf]