JShell là công cụ REPL (Read-Evaluate-Print-Loop) dùng để thực thi câu lệnh đơn giản, đánh giá và hiển thị kết quả mà không cần phương thức main(). Khởi động bằng cách gõ jshell tại command-line.
Để lấy thuộc tính hệ thống, dùng phương thức System.getProperty() và System.getProperties().
Đoạn mã dưới đây hiển thị thuộc tính hệ thống trong JShell bằng phương thức tĩnh property() của lớp System.
Đoạn mã 1
jshell> System.getProperty("java.class.path")
$1 ==> "C:\Program Files\Java\jdk-9.0.4\lib;C:\json-jars\json.jar;.;C:\json-jars\json-simple.jar;..."
Đoạn mã tiếp theo dùng đối tượng properties (kế thừa Hashtable) để liệt kê tất cả thuộc tính dưới dạng cặp key/value trong JShell bằng System.getProperties().forEach((k, v) -> ...).
Đoạn mã 2
jshell> System.getProperties().forEach((k, v) -> {
System.out.printf("%s: %s\n", k, v);
})
sun.desktop: windows
awt.toolkit: sun.awt.windows.WToolkit
java.specification.version: 9
file.encoding.pkg: sun.io
sun.cpu.isalist: amd64
sun.jnu.encoding: Cp1252
java.class.path: C:\Program Files\Java\jdk-9.0.4\lib;...
user.variant:
java.vendor.url: https://java.oracle.com/
user.timezone:
os.name: Windows 8.1
java.vm.specification.version: 9
sun.java.launcher: SUN_STANDARD
user.country: US
sun.boot.library.path: C:\Program Files\Java\jdk-9.0.4\bin
sun.java.command: jdk.jshell.execution.RemoteExecutionControl 54984
jdk.debug: release
sun.cpu.endian: little
user.home: C:\Users\User
user.language: en
java.specification.vendor: Oracle Corporation
java.home: C:\Program Files\Java\jdk-9.0.4
file.separator: \
java.vm.compressedOopsMode: 32-bit
line.separator:
java.vm.specification.vendor: Oracle Corporation
java.specification.name: Java Platform API Specification
java.awt.graphicsenv: sun.awt.Win32GraphicsEnvironment
user.script:
sun.management.compiler: HotSpot 64-Bit Tiered Compilers
java.runtime.version: 9.0.4+11
user.name: User
path.separator: ;
os.version: 6.3
java.runtime.name: Java(TM) SE Runtime Environment
file.encoding: Cp1252
java.vm.name: Java HotSpot(TM) 64-Bit Server VM
java.vendor.url.bug: https://bugreport.java.com/bugreport/
java.io.tmpdir: C:\Users\User\AppData\Local\Temp\
java.version: 9.0.4
user.dir: C:\Users\User\Desktop\Java 9 QNA
os.arch: amd64
java.vm.specification.name: Java Virtual Machine Specification
java.awt.printerjob: sun.awt.windows.WPrinterJob
sun.os.patch.level:
java.library.path: C:\Program Files\Java\jdk-9.0.4\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Java\jdk-9.0.4\bin;.;.;
java.vm.info: mixed mode
java.vendor: Oracle Corporation
java.vm.version: 9.0.4+11
sun.io.unicode.encoding: UnicodeLittle
java.class.version: 53.0