Advanced Java Notes
1. JVM Architecture
- JVM (Java Virtual Machine) executes bytecode.
- Components:
• Class Loader → loads .class files into memory.
• Runtime Data Areas → Heap, Stack, Method Area, PC Register.
• Execution Engine → Interpreter + JIT Compiler.
• Garbage Collector → automatically frees unused objects.
2. Memory Management
- Heap Memory: Objects stored.
- Stack Memory: Local variables and method calls.
- GC Phases: Mark → Sweep → Compact.
- WeakReference, SoftReference, PhantomReference.
3. OOP Principles Recap
- Encapsulation, Inheritance, Polymorphism, Abstraction.
- Composition > Inheritance (for flexibility).
- SOLID Design Principles.
4. Multithreading
- Thread class and Runnable interface.
- Thread lifecycle: New → Runnable → Running → Waiting → Terminated.
- Synchronization: 'synchronized' keyword, locks, wait(), notify(), notifyAll().
- Thread-safe classes: Vector, Hashtable, ConcurrentHashMap.
- Executor Framework: ThreadPoolExecutor, Callable, Future.
5. Concurrency Utilities
- java.util.concurrent package:
• ReentrantLock, Semaphore, CountDownLatch, CyclicBarrier.
• Concurrent Collections, Atomic classes.
• CompletableFuture for async programming.
6. Java 8+ Features
- Lambda Expressions → Functional interfaces.
- Stream API → map(), filter(), reduce().
- Optional class → avoids NullPointerException.
- Date-Time API → java.time package.
- Default & static methods in interfaces.
- Records (Java 14+), Sealed Classes (Java 17+).
7. Functional Programming
- Predicate, Function, Consumer, Supplier.
- Method references and chaining.
- Parallel Streams for large data.
8. JDBC (Java Database Connectivity)
- Steps:
1. Load driver → Class.forName().
2. Establish connection → DriverManager.getConnection().
3. Create Statement/PreparedStatement.
4. Execute queries and handle ResultSet.
5. Close connection.
- Connection Pooling via DataSource.
- ORM → Hibernate, JPA.
9. Servlets & JSP
- Servlet lifecycle: init() → service() → destroy().
- RequestDispatcher for forwarding.
- Session management → Cookies, URL rewriting, HttpSession.
- JSP: Scriptlet, Expression, Declaration.
- MVC pattern using Servlets + JSP.
10. Spring Framework
- Core Concepts: Dependency Injection (DI), Inversion of Control (IoC).
- Spring Boot simplifies configuration.
- Annotations: @Component, @Autowired, @RestController.
- Spring MVC and REST API support.
11. Hibernate ORM
- Maps Java objects to DB tables.
- Annotations: @Entity, @Table, @Id, @Column.
- Lazy vs Eager loading.
- HQL and Criteria API.
12. Best Practices
- Use Streams and Lambdas for readability.
- Prefer immutability and defensive copying.
- Use logging frameworks (SLF4J, Logback).
- Avoid memory leaks by closing resources.
- Write unit tests using JUnit & Mockito.
End of Notes