List of Java class file format major version numbers?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Java class files are the compiled bytecode files generated by the Java compiler from source files written in the Java programming language. The class file format is a key aspect of Java’s platform independence, as these files are used by the Java Virtual Machine (JVM) to execute Java programs on any platform without recompilation. The format of these class files is strictly defined and includes a version number, which is crucial for ensuring compatibility between different versions of the JVM.
Understanding Java Class File Format and Version Numbers
Java class files contain a specific format with several components, including a magic number, version numbers (minor and major), a constant pool, access flags, this class, super class, interfaces, fields, methods, and attributes. Among these, the major version number plays a critical role as it signifies the version of the JVM that the class file is compatible with.
Each version of the Java compiler correlates with specific major and minor version numbers in the class files it generates. The JVM uses the major version number to determine if it can run the class file. If a class file has a higher major version than the JVM supports, an error like UnsupportedClassVersionError occurs.
Table of Java Class File Major Version Numbers
The version numbers are incremented with each significant release of the Java Development Kit (JDK). Here is a table with the major release versions and their corresponding class file format major version numbers:
| JDK Version | Major Version Number | Release Year |
| 1.0 | 45 | 1996 |
| 1.1 | 45 | 1997 |
| 1.2 | 46 | 1998 |
| 1.3 | 47 | 2000 |
| 1.4 | 48 | 2002 |
| Java SE 5 | 49 | 2004 |
| Java SE 6 | 50 | 2006 |
| Java SE 7 | 51 | 2011 |
| Java SE 8 | 52 | 2014 |
| Java SE 9 | 53 | 2017 |
| Java SE 10 | 54 | 2018 |
| Java SE 11 | 55 | 2018 |
| Java SE 12 | 56 | 2019 |
| Java SE 13 | 57 | 2019 |
| Java SE 14 | 58 | 2020 |
| Java SE 15 | 59 | 2020 |
| Java SE 16 | 60 | 2021 |
| Java SE 17 | 61 | 2021 |
| Java SE 18 | 62 | 2022 |
| Java SE 19 | 63 | 2023 |
Impact of Version Compatibility
The backward compatibility issue arises when an older JVM tries to run a class file compiled by a newer version of the JDK, which may include newer language features not understood by the older JVM. For example, Java SE 8 introduced lambda expressions as a new language feature, and thus, class files containing lambda expressions (compiled with JDK 8 or higher) are unreadable by JVMs designed for Java SE 7 or lower.
How JVMs Handle Class File Versions
When the JVM loads a class file, it checks the major version number of the class file against its own internal version. If the class file's version is higher than the JVM's supported version, it will throw an UnsupportedClassVersionError. This mechanism ensures that features or bytecode not understood by the JVM are not erroneously processed, which could potentially lead to incorrect program behavior or system crashes.
Practical Tips
Developers should consider the target environment’s Java platform version when compiling source code. For instance, if a piece of software is intended to run on systems where only Java SE 8 is installed, then the JDK used for compilation should not be set to a higher version than 8, unless specific features from higher versions are required and backward compatibility is not an issue.
Also, development tools and build systems such as Maven and Gradle allow you to specify the target Java version, preventing accidental usage of features from newer Java versions that are not available on the target platform.
In summary, understanding and managing Java class file versions is critical for Java developers to ensure compatibility across different Java platform versions. Being cautious about the JDK version used for compilation can prevent runtime errors due to version incompatibilities in deployed environments.

