ตั้งแต่ Java 9 การกำหนดเวอร์ชันสอดคล้องกับ semantic versioning หมายเลขเวอร์ชันเป็น non-empty sequence ของสตริงคั่นด้วย dots ประกอบ 3 ส่วนหลัก: major version number minor version number และ security รูปแบบเวอร์ชันใหม่มีเอกสารในคลาส Runtime.Version และเข้าถึงข้อมูลเวอร์ชันได้จากที่นั่น
รูปแบบหมายเลขเวอร์ชัน
$MAJOR.$MINOR.$SECURITY(.$otherpart)?
- $MAJOR - major version number เพิ่มเมื่อ major release เปลี่ยนแปลง platform specification สำหรับ JDK 9 ค่านี้คือ 9
- $MINOR - minor version number เพิ่มสำหรับ release ที่มี bug fixes และ enhancements ของ standard APIs
- $SECURITY - security level เพิ่มสำหรับ release ที่มี critical security fixes ไม่ reset เป็นศูนย์เมื่อ minor version เพิ่ม
- $otherpart - ส่วนเพิ่มเติม 1 หรือหลายเวอร์ชัน ที่ JVM providers ใช้ระบุ patch ที่มี non-security fixes จำนวนน้อย
รูปแบบ version string
$VNUM(-$PRE)?+$BUILD(-$OPT)?
$VNUM-$PRE(-$OPT)?
$VNUM(+-$OPT)?
- $PRE - pre-release identifier
- $BUILD - build number
- $OPT - ข้อมูลเพิ่มเติม เช่น timestamp
ตัวอย่าง: เข้าถึงข้อมูลเวอร์ชันผ่าน Runtime.Version
public class VersionSchemeTest {
public static void main(String args[]) {
System.out.println(Runtime.version().toString()); // String representation
System.out.println(Runtime.version().major()); // major version number
System.out.println(Runtime.version().minor()); // minor version number
System.out.println(Runtime.version().security()); // security version number
}
}
ผลลัพธ์
9.0.4+11
9
0
4
เปรียบเทียบรูปแบบเก่า vs ใหม่
| รูปแบบเก่า (Java 8) | รูปแบบใหม่ (Java 9+) |
|---|---|
| 1.8.0_181 | 8.0.181 (หรือ 8u181) |
| 9.0.1 | 9.0.1 |
| 10.0.1 | 10.0.1 |
| 11.0.1 (LTS) | 11.0.1 |
รูปแบบใหม่ชัดเจนกว่า แยก security version ชัดเจน และสอดคล้อง semantic versioning