Java Interview Cheat Sheet
JAVA INTERVIEW CHEAT SHEET
1. OOP Principles: Inheritance, Encapsulation, Polymorphism, Abstraction.
2. Important Java Concepts:
- Abstract Class vs Interface: Interface = 100% abstraction; Abstract class = Partial abstraction.
- '==' checks reference; '.equals()' checks content.
- final keyword: prevents change (variable), inheritance (class), overriding (method).
3. Collections Summary:
- List (ArrayList, LinkedList): Ordered, duplicates allowed.
- Set (HashSet, LinkedHashSet, TreeSet): Unordered (except Linked), no duplicates.
- Map (HashMap, TreeMap): Key-value pairs, unique keys.
- HashMap: Not synchronized. Hashtable: Synchronized.
4. Exception Handling:
- Checked: Must handle (e.g., IOException).
- Unchecked: Runtime errors (e.g., NullPointerException).
- finally always executes.
5. Multithreading:
- Thread vs Runnable: Runnable preferred.
- synchronized keyword for thread-safety.
- volatile keyword: Prevents caching issues.
- wait(), notify(), notifyAll() for thread communication.
6. Java 8 Features:
- Lambda: (args) -> {body}
- Functional Interface: Interface with only one abstract method (@FunctionalInterface).
- Stream API: For processing collections.
- Optional: Avoid NullPointerException.
7. Spring Boot Essentials:
- @Component, @Service, @Repository: Specialization of @Component.
- Dependency Injection: Injecting dependencies via constructor, setter, or field.
- REST APIs: CRUD operations with @RestController.
8. Hibernate Basics:
- ORM tool for Java.
- Session.beginTransaction(), session.save(), session.commit().
9. Important Coding Patterns:
- Reverse a string using StringBuilder or loop.
- Find missing number: Sum formula or XOR method.
- Use HashSet to detect duplicates.
REMEMBER: Clear explanation + Confidence > Fancy solutions.