JDK Introduction

What is JDK

JDK (Java Development Kit) is the software development kit for the Java programming language and forms the core of all Java development. It includes the Java Runtime Environment (JRE), Java compiler (javac), Java Virtual Machine (JVM), and extensive Java class libraries and tools. JDK is essential for Java application development, whether building desktop applications, web applications, mobile apps, or enterprise-level systems.

JDK is developed and maintained by Oracle Corporation (and its predecessor Sun Microsystems), serving as the foundation of the Java platform. The current latest LTS (Long-Term Support) versions are JDK 25 and JDK 21, with JDK 17 also being a widely used Long-Term Support version. Oracle periodically releases new JDK versions, each bringing performance improvements, new features, and security vulnerability fixes.

JDK is more than just a runtime environment; it provides all the components needed for complete Java development. The most core component is the Java compiler (javac), which compiles Java source code into bytecode (.class files). Additionally, there's the Java Virtual Machine (JVM), which executes bytecode, along with various tools like jar (archive tool), javadoc (documentation generator), and javap (disassembler). Together, these tools constitute a complete Java development environment.

Major JDK Versions

JDK 25 (New Version)

JDK 25 is the newest JDK version, bringing many new features and improvements. This is a short-term support version with a 6-month support cycle. Key features include: improved performance optimizations, enhanced garbage collectors, new language features, and support for the latest hardware. JDK 25 is suitable for developers who want to use the latest Java features, but be aware of its shorter support cycle.

JDK 21 (LTS)

JDK 21 is the latest Long-Term Support version (LTS) and will receive at least 8 years of support. This is the last LTS version with free Oracle JDK usage under the Oracle No-Fee Terms and Conditions. JDK 21 introduces important features like Virtual Threads, Pattern Matching, and Records, which significantly simplify Java programming and improve development efficiency.

Virtual Threads is one of the most important features in JDK 21, making it much simpler to write highly concurrent applications. Compared to traditional threads, virtual threads have extremely low creation costs and can easily create millions of virtual threads to handle concurrent tasks. This is significant for building large-scale distributed systems, microservices architectures, and high-performance server applications.

JDK 17 (LTS)

JDK 17 is one of the most mature Long-Term Support versions currently available and has widespread adoption. It is the last version with free Oracle JDK usage (according to Oracle's license terms), so many enterprises still choose to use JDK 17. JDK 17 includes many features from OpenJDK, such as Sealed Classes, Text Blocks, and switch expressions.

JDK 17's performance has significantly improved compared to JDK 11, especially in garbage collection and JIT compilation. For enterprise applications requiring long-term stable support, JDK 17 remains an excellent choice. It achieves a good balance between performance, stability, and features.

JDK 11 (LTS)

JDK 11 is another important Long-Term Support version, marking the dividing line for Java's paid features. Starting from JDK 11, some advanced features of Oracle JDK require a paid subscription. JDK 11 introduces the ZGC garbage collector (experimental), new HTTP client API, and local variable type inference (var keyword). Although no longer the latest LTS version, JDK 11 is still widely used in many existing projects.

Core Components of JDK

Java Compiler (javac)

The Java compiler (javac) is one of the most essential tools in JDK, responsible for compiling Java source code (.java files) into Java bytecode (.class files). Bytecode is an intermediate form of code that doesn't depend on specific hardware platforms and can only be executed by the Java Virtual Machine. This design gives Java programs the characteristic of "Write Once, Run Anywhere."

The javac compiler supports numerous compilation options, allowing developers to control various behaviors of the compilation process through command-line parameters. For example, you can use the -d option to specify the compilation output directory, -classpath to specify the class search path, and -source and -target to specify Java source and target bytecode versions. Mastering these compilation options is crucial for building large projects.

Java Virtual Machine (JVM)

The Java Virtual Machine (JVM) is the core environment for executing Java programs. It is responsible for loading bytecode and interpreting or compiling it for native execution. The JVM is key to Java's platform independence, shielding differences in underlying operating systems and hardware, allowing the same Java program to run on different platforms.

The core components of the JVM include: ClassLoader responsible for loading class files, Execution Engine responsible for executing bytecode, and Runtime Data Areas including method area, heap, virtual stack, native method stack, and program counter. Understanding how the JVM works is essential for writing high-performance Java applications.

The JVM also provides powerful garbage collection (GC) functionality, automatically managing memory allocation and reclamation. Different garbage collectors like Serial, Parallel, CMS, G1, ZGC, and Shenandoah are suitable for different application scenarios. Developers can choose the appropriate garbage collector based on application characteristics to achieve optimal performance.

Java Runtime Environment (JRE)

The Java Runtime Environment (JRE) is the environment required to run Java programs. It includes the JVM, Java core class libraries, and other supporting files. The JRE is a subset of JDK; JDK includes JRE plus development tools. If you only need to run Java programs without development, installing JRE is sufficient.

The core of JRE is the Java core class libraries, which provide basic Java functionality like java.lang, java.util, java.io, java.net. These class libraries have been developed and optimized over many years and are very mature and stable, covering everything from basic data structures to network programming.

Java Tool Set

JDK provides a rich set of command-line tools for Java program development, debugging, and diagnostics. The main tools include:

jar: Used for creating and managing Java archive files (.jar files), which can package multiple class files into a convenient file for distribution and deployment.

javadoc: Used for generating HTML-format API documentation from Java source code comments, the standard tool for creating code documentation.

javap: Used for disassembling Java bytecode, can view class file structures and method signatures, very helpful for understanding the Java compilation process and debugging.

jdb: Java debugger, provides command-line interface debugging features, can set breakpoints, step through execution, view variable values, etc.

jps: Displays information about all Java processes in the current system, including process ID and main class name.

jstat: Displays JVM statistics like garbage collection information, class loading information, etc.

jstack: Prints Java thread stack trace information, used for diagnosing thread deadlock issues.

jmap: Displays Java heap memory information, can generate heap dump files for analysis.

These tools are very useful in daily development and production environment problem diagnosis, and mastering them can significantly improve development efficiency and problem diagnosis capabilities.

Application Areas of JDK

Enterprise Application Development

JDK is the foundation of enterprise application development. Various Java EE (now renamed Jakarta EE) frameworks like Spring, Hibernate, and Struts all require running on JDK. These frameworks provide complete solutions for enterprise applications, including dependency injection, transaction management, data persistence, and web services.

Large enterprise applications typically have extremely high requirements for stability and performance, so choosing the appropriate JDK version is very important. Many enterprises use mature LTS versions like JDK 17 combined with commercial support services to ensure long-term stable system operation.

Android Development

Although Android apps are primarily written in Java or Kotlin, Android app development cannot proceed without JDK. Android SDK tools need JDK to compile Android projects and generate APK files that can be installed on Android devices. Android Studio also includes built-in JDK, and developers need to specify the JDK path when configuring the development environment.

It's worth noting that Android development doesn't require a complete JDK; usually just JRE is sufficient. However, to use all features of the Android SDK, it's recommended to install the complete JDK.

Big Data Processing

In the big data field, Java and JDK play a core role. Mainstream big data frameworks like Hadoop, Spark, and Flink are all developed in Java and require running on JDK. These frameworks typically need to process massive data and have extremely high performance and stability requirements.

Many components in the Hadoop ecosystem like HBase, Hive, and Pig all require JDK to run. When deploying big data environments, it's necessary to choose the appropriate JDK version and perform corresponding performance tuning.

Web Application Development

Java web application development is a traditional strength of JDK. Technologies like Servlet, JSP, Filter, and Listener form the foundation of Java web development. Mainstream web frameworks like Spring MVC, Struts, and JSF all run on JDK.

Web servers like Tomcat, Jetty, and WildFly provide running containers for Java web applications. These servers need JDK to start and run. In production environments, it's usually necessary to choose a high-performance and stable JDK version.

Cloud Computing and Microservices

With the popularity of cloud computing and microservices architecture, JDK also plays an important role in this area. Microservices frameworks like Spring Cloud and Dubbo provide complete solutions for building distributed systems. All these frameworks require running on JDK.

Cloud-native applications have new requirements for JDK, such as faster startup speed and lower memory usage. For this reason, Oracle and other vendors provide JDK distributions optimized for cloud scenarios, like Oracle GraalVM Native Image, which can compile Java applications into native executables, significantly reducing startup time and memory usage.

JDK and Other Java Implementations

OpenJDK

OpenJDK is the open-source implementation of Java SE, jointly developed and maintained by Oracle and the community. OpenJDK is the basis for most other JDK distributions. Many vendors like Eclipse (Eclipse Temurin), Amazon (Amazon Corretto), and Microsoft (Microsoft Build of OpenJDK) build their JDK distributions based on OpenJDK.

OpenJDK and Oracle JDK are almost identical at the code level, with main differences being license agreements and support services. Oracle JDK provides commercial support and additional enterprise-level features, while OpenJDK is completely open-source and free. For most users, using OpenJDK is perfectly adequate.

Other JDK Distributions

In addition to Oracle JDK and OpenJDK, there are many other JDK distributions:

Eclipse Temurin (formerly AdoptOpenJDK): OpenJDK distribution maintained by the Eclipse Foundation, providing high-quality builds and long-term support.

Amazon Corretto: Free, multi-platform JDK distribution provided by Amazon, offering long-term support and performance optimization.

Microsoft Build of OpenJDK: OpenJDK build provided by Microsoft, optimized for Windows and Azure.

Azul Zulu: JDK distribution provided by Azul Systems, known for high performance and stability.

GraalVM: Multi-language virtual machine provided by Oracle, supporting not only Java but also JavaScript, Python, Ruby, and other languages.

Choosing which JDK distribution depends on specific needs and environment. In most cases, standard Oracle JDK or OpenJDK can meet requirements. If commercial support is needed, you can choose Oracle JDK or vendor support services.

Importance of JDK

As the foundation of Java development, JDK's importance is self-evident. Regardless of which Java frameworks or tools are used, support from JDK is essential. JDK is not just a toolset for compiling and running Java programs; it also represents the core of the Java ecosystem.

Choosing an appropriate JDK version and configuring it correctly is crucial for project success. Factors to consider include: version stability, security update frequency, new features, performance optimization, and community support. For enterprise-level applications, it's recommended to use LTS versions to obtain long-term support.

With the continuous development and evolution of the Java language, JDK continues to be updated. New JDK versions bring better performance, more features, and higher security. Keeping JDK updated can provide better development experience and operational efficiency.

Version Differences

Different JDK major versions have significant differences in installation, usage, and features:

JDK 8: The last free Oracle JDK version for commercial use without restrictions. Introduced lambda expressions, streams API, and new date/time API. Still widely used in legacy systems.

JDK 11: Marked the beginning of Java's paid features. Introduced local variable type inference (var), new HTTP client API, and ZGC (experimental). The last version supporting 32-bit systems.

JDK 17: The last completely free Oracle JDK version under NFTC. Introduced sealed classes, text blocks, and switch expressions. Excellent balance between performance, stability, and features.

JDK 21: The latest LTS version with Virtual Threads, pattern matching for switch, and records as stable features. Recommended for new projects.

JDK 25: The newest version with latest language features and performance improvements. Suitable for developers wanting the newest features but with a shorter support cycle.