The modern Java platform, with OpenJDK 11 and above.
The Java Community Process defines standards for these areas:
- The Java Language
- The Java Virtual Machine
- Java Platform
Each Java Specification Request (JSR) includes a Technology Compatibility Kit (TCK) that enables developers to test that an implementation meets the specifications of the JSR.
Similarly, the Java Compatibility Kit (JCK) tests that Java Platform implementations are compatible with standards.
The Java Virtual Machine
Each Java Virtual Machine (JVM) runs compiled binary Java bytecode. This bytecode is platform-independent. Bytecode is enclosed in .class files.
Components of the JVM
- Compiler - Interprets bytecode, and automatically applies JIT compilation (using the C1 fast compiler, and the C2 optimized compiler)
- Runtime - Loads class files into memory, concurrency, interacts with the operating system (threads, memory allocation, sockets), works with external monitoring, handles logging
- Garbage Collector - Memory management
G1 is now the default garbage collector for OpenJDK 10 and above. It implements a parallel mark-sweep-compact algorithm. The default pause time goal for G1 is 200 milliseconds, but this is adjustable.
Java ARchives (JARs)
A JAR is a ZIP file archive that should contain a directory named META-INF, and inside that a manifest file, which will be named MANIFEST.MF. The manifest file provides data about the files that are contained in the JAR.
Java Class Loaders
The JVM does not find classes itself. Instead, Java Class Loaders look for the appropriate class file when the class is first used. By default, a JVM will use three class loaders: the boot class loader (for core libraries that are supplied with the JVM), the extension class loader (for libraries in the extensions directory), and a system class loader, which looks on the classpath, a list of directories and JARs. A classpath can specify any combination of directories, paths to individual JARs, and paths with wildcards to load multiple JARs. Web application servers use additional class loaders. The boot class loader is written in platform-specific native code, and all other class loaders are written in Java.
The system class loader looks for class files in the locations that are specified by the classpath. Each location can either be a directory, the path to a specific JAR file, or a directory with a wildcard. In the last case, the loader uses all of the JAR files in the specified directory.
The classpath is either defined by a CLASSPATH environment variable, or set by a command-line option to the java run-time, or specified in a manifest file. It is a colon-separatedlist on UNIX-like systems, a semi-colon separated list on Windows, and space separated list in manifest files. This example sets the classpath at the command-line on a UNIX-like system:
java -classpath ".:../java-classes/*:/usr/local/lib/java-classes/*"
The default value of classpath is . (the period character), which means that it checks the current directory.
Java uses the concept of Properties objects to hold configuration information. A Properties object is an instance of the java.util.Properties class. Each Properties object can hold multiple properties. A property is a key-value pair that is held within a Properties object.
Properties objects are stored as .properties files, usually alongside the the .class files for the application. Developers write code in the application to load properties objects from the appropriate properties files when the application starts.
The Java platform itself uses a Properties object for global configuration. This object provides system properties. The system properties are accessed through methods on the System class.
Agents are plugins for the JVM. For example, JRebel is an agent that enables hot-code reloading.
Each distribution of Java includes a Java Virtual Machine (JVM), and a Java Developers Kit (JDK), which provides the tools and class libraries. Compatibility tests verify whether a distribution complies with Java standards.
Most distributions use the HotSpot JVM. For example, both Amazon Corretto and Azul Zulu include versions of the HotSpot JVM. OpenJ9 is an alternative Open Source JVM that is maintained by IBM and the Eclipse Foundation.
Almost every Java distribution now uses versions of the OpenJDK tools and libraries.
Android uses the Java language, but Android software development kits (SDKs) are not fully compatible with Java standards.
Free, Open Source Distributions
- Adoptium - Provides Eclipse Temurin, a free version of the OpenJDK with the HotSpot Java Virtual Machine for all popular operating systems. IBM offers commercial support contracts
- Amazon Corretto - OpenJDK with the HotSpot Java Virtual Machine, supported by AWS
- Eclipse OpenJ9 - OpenJDK with the OpenJ9 JVM
- IBM Semeru - OpenJDK with the OpenJ9 Java Virtual Machine, supported by IBM
- Red Hat OpenJDK - OpenJDK with the HotSpot Java Virtual Machine, supported by Red Hat, Linux and Windows only
- SapMachine - OpenJDK and JVM, provided by SAP for their customers
- Zulu - OpenJDK with the Zulu JVM, maintained by Azul Systems
- IBM Java SDK
- JamaicaVM - A proprietary Java implementation for real-time systems.
- Oracle JDK - Proprietary builds of HotSpot and OpenJDK, supported by Oracle
- Pivotal Spring Runtime - A distribution of the OpenJDK that is supported by Pivotal
- Zing - High-performance proprietary Java implementation maintained by Azul Systems
OpenJDK packages include a JVM (such as HotSpot or OpenJ9), a standard library (the Java Class Library), and various tools, including:
- javac compiler turns .java source files into .class files.
- javap de-compiler reads the contents of class files.
- jar tool works with .jar files, which contain the compiled .class files.
- jarsigner tool is for digitally signing JAR files.
- jdb is a command-line debugging client for the JVM
- jshell command-line shell, which was introduced in Java 9.
- jlink tool create image files that include both code modules and a Java run-time. This was introduced in Java 9.
JDK 9 introduced jaotc, an experimental alternative compiler to javac that produces Ahead Of Time Compiled code, rather than generic bytecode. This is based on Graal.
Monitoring and Debugging
Java Virtual Machines accept connections from debuggers. The debugger may either be on the same system, or connecting from a remote system. The OpenJDK tself includes jdb, a command-line debugger. Each IDE for Java includes a graphical debugger.
Java Flight Recorder and Java Mission Control provide a data collection and profiling system for the OracleJDK.
The OpenJDK also includes these tools for monitoring and diagnostics:
- jconsole - Graphical utility for monitoring and managing Java applications
- jinfo - Provides configuration information for a specified Java process
- jps - Java process viewer
- jstat - Java statistics monitoring
The OpenJDK includes JMH, the Java Micro-benchmark Harness.
Popular Third-Party Software
- jEnv - Convenient switching between JDKs
- Maven - The standard project management tool
- Gradle - Powerful build system
- Jib - Container builder
- JBake - Static site generator
- Swagger - OpenAPI code generation for clients and servers
Code Quality Tools
- CheckStyle - Code style checks
- Google Java Format - Reformats Java code to Google Java Style, can be automated with the Maven plugin
- JaCoCo - Test coverage
- PMD - Code quality checks for Java and Salesforce.com
- SonarQube - Code analysis framework
- SpotBugs - Static analysis of code
- Dropwizard - Framework for REST APIs
- Ratpack - Toolkit for lean, asynchronous HTTP services
- Spring Batch - Batch processing
- Spring Boot - Opinionated Web framework
- Apache Tomcat - De-facto standard Web applications server for Java
- Eclipse Jetty - Often embedded in applications
- Undertow - High performance, embeddable Web server
- Flyway - Schema management
- H2 - SQL database in pure Java
- Hibernate - Most popular SQL database toolkit and ORM
- Liquibase - Older schema management tool
- MyBatis - Powerful SQL database framework
- Ehcache - In-memory caching
- Google Guava - A set of utility libraries
- Google Guice - Dependency injection framework
- Jackson - Libraries for JSON and other data formats
- JavaPoet - Java code generation
- jsoup - HTML parser
- Logback - Logging
- Micrometer - Metrics collection agent library
- Quartz - Job scheduler
- resilience4j - Fault tolerance
- Thymeleaf - Templating
- DZone Java Zone - News and tips
- Baeldung - Articles and a weekly newsletter on Java and Spring topics