0% found this document useful (0 votes)
4 views3 pages

Advanced Short Java Notes

The document provides advanced Java notes covering JVM architecture, memory management, concurrency, functional programming, reflection, design patterns, and networking. Key topics include garbage collection tuning, the Fork/Join framework, CompletableFuture for asynchronous programming, and the use of streams and method references. It also discusses modern features like virtual threads and the HTTP Client API introduced in Java 11.

Uploaded by

fredykydong
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Advanced Short Java Notes

The document provides advanced Java notes covering JVM architecture, memory management, concurrency, functional programming, reflection, design patterns, and networking. Key topics include garbage collection tuning, the Fork/Join framework, CompletableFuture for asynchronous programming, and the use of streams and method references. It also discusses modern features like virtual threads and the HTTP Client API introduced in Java 11.

Uploaded by

fredykydong
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Short java notes -advanced

Module 1: JVM Architecture & Memory Management

To master advanced Java, you must understand how the code executes at the hardware level.

1.1 The Runtime Data Areas

 Method Area: Stores per-class structures (runtime constant pool, field/method data).

 Heap: The runtime data area from which memory for all class instances and arrays is
allocated.

 Stack: Each thread has a private JVM stack, created at the same time as the thread. It
holds local variables and partial results.

1.2 Garbage Collection (GC) Tuning

Modern Java uses different collectors based on throughput vs. latency needs:

 G1 (Garbage First): The default since Java 9. Designed for multi-processor machines with
large memories.

 ZGC & Shenandoah: Ultra-low latency collectors (sub-millisecond pauses) that perform
evacuation concurrently with the application threads.

Key Formula for Heap Size: > If $Xms$ is initial heap and $Xmx$ is max heap, for server
applications, it is often recommended that $Xms = Xmx$ to avoid heap resizing overhead during
runtime.

Module 2: Advanced Concurrency & Multi-threading

Moving beyond Thread and Runnable into the [Link] (JUC) ecosystem.

2.1 The Fork/Join Framework

Designed for work-stealing algorithms. It recursively breaks tasks into smaller sub-tasks until
they are simple enough to run asynchronously.

2.2 CompletableFuture

Introduced in Java 8, it allows for non-blocking asynchronous programming by "chaining" tasks:

Java

[Link](() -> fetchOrder())


.thenApply(order -> enrichOrder(order))

.thenAccept(enrichedOrder -> display(enrichedOrder));

2.3 Virtual Threads (Project Loom)

Introduced in Java 21, these are lightweight threads that reduce the effort of writing,
maintaining, and observing high-throughput concurrent applications. They allow you to run
millions of threads without the overhead of OS-level context switching.

Module 3: Functional Programming in Java

Java is no longer just imperative. Functional patterns improve code readability and
maintainability.

3.1 Streams API Deep Dive

 Intermediate Operations: filter, map, flatMap, distinct, sorted (Lazy evaluation).

 Terminal Operations: collect, forEach, reduce, findFirst.

 Parallel Streams: Use with caution. They utilize the [Link]() and can
lead to performance bottlenecks if tasks are non-CPU intensive.

3.2 Method References & Lambdas

Understand the four types of method references:

1. Static methods (ClassName::methodName)

2. Instance methods of a particular object (obj::methodName)

3. Instance methods of an arbitrary object of a particular type (ClassName::methodName)

4. Constructors (ClassName::new)

Module 4: Reflection and Annotation Processing

Reflection allows an executing Java program to examine or "introspect" upon itself.

 The Reflection API: Used by frameworks like Spring and Hibernate to inject
dependencies at runtime.

 Custom Annotations: * @Retention([Link]): Available at runtime for


reflection.
o @Target([Link]): Restricts where the annotation can be applied.

Module 5: Design Patterns (The Java Way)

Advanced developers should implement patterns using modern Java features:

 Singleton: Use Enum for the most robust implementation against reflection and
serialization attacks.

 Strategy Pattern: Can often be replaced by functional interfaces (Lambdas).

 Builder Pattern: Vital for creating immutable objects with many optional parameters.

Module 6: Networking & I/O

 NIO (New I/O): Uses Buffers and Channels for non-blocking I/O operations.

 HTTP Client API: The [Link] (Java 11+) supports HTTP/2 and
WebSockets natively.

You might also like