Category: Java tutorial
-
Understanding the JVM Code Cache
When studying the JVM and its Just-In-Time (JIT) compilation process, one important component to understand is the code cache.This cache stores the optimized native machine code generated by the JIT compilers.Knowing how the code cache works, how to inspect it, and how to tune its size can help improve application performance, especially in large or…
-
Understanding JVM Tiered Compilation
1. JVM Has Two JIT Compilers: C1 and C2 Modern JVMs include two different compilers, each with a specific purpose: C1 (Client Compiler) C2 (Server Compiler) This structure is known as tiered compilation, and it dramatically improves how Java warms up and stabilizes performance. 2. Understanding Compilation Levels (Tiers) Every compiled method receives a compilation…
-
Understanding -XX:+PrintCompilation in the JVM
When you run a Java application, the JVM does not immediately compile everything into optimized machine code. Instead, it dynamically profiles, interprets, and JIT-compiles parts of your program based on how frequently they are used. To see exactly what the JVM is compiling, the JVM provides a powerful diagnostic flag: -XX:+PrintCompilation This option prints every…
-
JVM Just-In-Time Compilation (JIT)
Java’s performance story is often misunderstood. Many people hear: “Java is interpreted, so it must be slow.” But the truth is far more interesting. The JVM does not behave like a simple interpreter. It is a sophisticated, intelligent, adaptive execution engine capable of learning how your program behaves and optimizing itself continuously. 1. The Initial…
-
What is Bytecode?
1. The Java Execution Pipeline: Bytecode is Key The journey from writing human-readable Java code to its execution is a two-step process, designed to provide consistent, reliable performance across diverse hardware. Step A: Compilation When you write code in Java (.java files), it is first processed by the Java Compiler. Step B: Execution When you…
-
Understanding JVM Just-In-Time (JIT) Compilation
1. The JVM Starts as an Interpreter When you start your Java application, the JVM initially behaves like a classic interpreter: This approach offers an important benefit: Write Once, Run Anywhere Your Java bytecode runs on any platform with a JVM implementation — Windows, macOS, Linux, and more. However, there’s a drawback: Interpreted execution is…
-
How the JVM Runs Your Code
What exactly does the JVM do when it runs our code? Most developers know that Java is a compiled language—yet not compiled in the same sense as C or C++.Instead, Java follows a unique two-step model: Understanding this lifecycle is essential because every optimization, performance decision, and runtime behavior in Java flows from this model.…
-
JDK Vendors and JVM Implementations
Java is one of the world’s most widely used technologies, and with its growth has come a rich ecosystem of multiple JDK vendors and multiple JVM implementations.Understanding the differences among them is essential, especially when you’re tuning performance, deploying to production, or choosing a runtime for long-term stability. Part 1: JDK Vendors — Oracle vs…
-
How TreeMap Maintains Order Internally in Java
The TreeMap class in Java is a part of the Java Collections Framework (JCF) and implements the NavigableMap interface, which extends SortedMap. Unlike HashMap, which stores key-value pairs in no predictable order, TreeMap automatically sorts its keys based on their natural ordering or a custom comparator provided at map creation. Let’s go step by step…
-
How PriorityQueue Works Internally in Java?
1. Introduction A PriorityQueue in Java is a specialized queue data structure where elements are arranged according to their priority rather than their insertion order. Unlike a regular Queue (which follows FIFO – First In, First Out), a PriorityQueue always ensures that the head of the queue is the element with the highest priority (or…
