Java 9 giới thiệu JShell – công cụ REPL cho phép đánh giá snippet code (khai báo, câu lệnh, biểu thức). Ta có thể lấy thông tin Java Version, Vendor, OS Version, OS Name bằng phương thức static System.getProperty().
Ví dụ trong JShell
C:\Users\User> jshell
| Welcome to JShell -- Version 9.0.4
jshell> System.out.println(System.getProperty("java.version"));
9.0.4
jshell> System.out.println(System.getProperty("java.vendor"));
Oracle Corporation
jshell> System.out.println(System.getProperty("os.version"));
6.3
jshell> System.out.println(System.getProperty("os.name"));
Windows 8.1
jshell>
Các property thường dùng
| Property Key | Mô tả | Ví dụ giá trị |
|---|---|---|
java.version | Phiên bản Java runtime | 9.0.4, 11.0.2, 17.0.1 |
java.vendor | Nhà cung cấp JDK | Oracle Corporation, Eclipse Adoptium |
java.home | Thư mục cài đặt JRE | C:\Program Files\Java\jdk-9.0.4 |
os.name | Tên hệ điều hành | Windows 10, Linux, Mac OS X |
os.version | Phiên bản OS | 10.0, 5.15.0-91-generic |
os.arch | Kiến trúc CPU | amd64, aarch64 |
user.name | Tên user đăng nhập | admin, nguyenvana |
user.dir | Thư mục làm việc hiện tại | C:\Projects\MyApp |
Trong JShell, chỉ cần gõ System.getProperty("key") để tra cứu nhanh mà không cần viết chương trình hoàn chỉnh.