Java Interview Cheat Sheet
1. Core Java Concepts
- OOP Principles: Encapsulation, inheritance, polymorphism, and abstraction.
- Exception Handling: Try-catch blocks, custom exceptions, and handling unchecked vs checked exceptions.
- Collections Framework: Data structures like List, Set, Map, and their implementations (ArrayList, HashSet, HashMap).
- Streams and Lambda Expressions: Functional programming in Java, used for processing collections and data streams.
- Multithreading and Concurrency: Creating and managing threads, thread safety, and synchronization.
- Java Memory Model (Heap, Stack, GC): Understanding memory allocation, garbage collection, and memory leaks.
- JVM Internals (Classloader, JIT Compiler): How the JVM loads classes and optimizes code at runtime.
- Java 8+ Features (Optional, Functional Interfaces): New features like Optional for null safety, and functional interfaces
for lambda expressions.
2. Java Language Features
- Access Modifiers: Control visibility of classes, methods, and variables (public, private, protected, default).
- Data Types, Variables, and Operators: Primitive and reference data types, variable declaration, and operators like
arithmetic, logical.
- Control Flow Statements: If-else, switch-case, loops (for, while, do-while), and break/continue statements.
- Generics: Allows type-safe collections and methods, enabling code reusability.
- Annotations: Metadata for classes and methods, used by the compiler and runtime (e.g., @Override, @Deprecated).
- Enum Types: Special data type for a fixed set of constants, e.g., days of the week.
3. Common Java APIs
- java.lang: Core classes like Object, String, Math, and system-level classes.
- java.util: Utility classes like Collections, Date, Scanner, and various data structures.
- java.io and java.nio: Input/Output operations with streams, readers, and non-blocking IO.
- java.time (Date and Time API): Classes for date and time manipulation, introduced in Java 8.
- java.util.concurrent: Concurrency utilities like ExecutorService, CountDownLatch, and ConcurrentHashMap.
- java.math: Classes for performing arbitrary-precision arithmetic (BigInteger, BigDecimal).
4. Design Patterns
- Singleton: Ensures a class has only one instance and provides a global point of access to it.
- Factory: Creates objects without exposing the creation logic, using a common interface.
- Strategy: Encapsulates algorithms so that they can be swapped out without altering the client.
- Observer: Defines a dependency between objects, so that when one changes state, all dependents are notified.
- Dependency Injection: Increases decoupling by injecting dependencies rather than instantiating them within classes.
5. Best Practices
- Writing Clean Code: Readable, maintainable code with proper naming, formatting, and comments.
- Code Optimisation: Improving performance through efficient algorithms, avoiding unnecessary operations.
- Handling Null Safely: Using Optional, null checks, and avoiding NullPointerExceptions.
- Effective Java (Key Tips): Best practices like using interfaces, avoiding mutable objects, and understanding equals and
hashCode.