如何在Java 9的JShell中获取系统属性?
JShell is a REPL (Read-Evaluate-Print-Loop) tool used to execute simple statements, evaluates it, and displays the result without a main() method. We can start it by simply type "jshell" in command-line prompt.
We need to get the system properties by using System.getProperty() and System.getProperties() methods.
In the below code snippet, we can able to display the system properties in the JShell tool by using static method property() of System class.
Snippet-1
<strong>jshell> System.getProperty("java.class.path") </strong><strong>$1 ==> </strong><strong>"C:\Program Files\Java\jdk-9.0.4\lib;C:\json-jars\json.jar;.;C:\json-jars\json-simple.jar;.;C:\json-jars\gson.jar;.;C:\json-jars\commons-io.jar;.;C:\json-jars\jackson-core.jar;.;C:\json-jars\jackson-databind.jar;.;C:\json-jars\jackson-annotations.jar;.;C:\json jars\flexjson.jar;.;C:\json-jars\jackson-dataformat-xml.jar;.;C:\json-jars\stax2-api.jar;.;C:\json-jars\jackson-dataformat-csv.jar;.;C:\json-jars\javax.json.jar;.;C:\json jars\javax.json-api.jar;.;C:\json-jars\jackson-module-jsonSchema.jar;.;C:\json-jars\json-lib.jar;.;C:\json-jars\commons-lang.jar;.;C:\json-jars\commons-logging.jar;.;"</strong>
在下面的代码片段中,我们必须使用扩展了Hashtable的“properties”对象。因此,可以通过在JShell工具中使用“System.getProperties().forEach((k, v)”来列出所有属性作为键/值对.
Snippet-2
<strong>jshell> System.getProperties().forEach((k, v) -> { System.out.printf("%s: %s\n", k, v); })</strong> <strong>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;C:\json jars\json.jar;.;C:\json jars\json-simple.jar;.;C:\json jars\gson.jar;.;C:\json jars\commons-io.jar;.;C:\json jars\jackson-core.jar;.;C:\json jars\jackson-databind.jar;.;C:\json jars\jackson-annotations.jar;.;C:\json jars\flexjson.jar;.;C:\json jars\jackson-dataformat-xml.jar;.;C:\json jars\stax2-api.jar;.;C:\json jars\jackson-dataformat-csv.jar;.;C:\json jars\javax.json.jar;.;C:\json jars\javax.json-api.jar;.;C:\json jars\jackson-module-jsonSchema.jar;.;C:\json jars\json-lib.jar;.;C:\json jars\commons-lang.jar;.;C:\json jars\commons-logging.jar;.; java.vm.vendor: Oracle Corporation sun.arch.data.model: 64 user.variant: java.vendor.url: http://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: http://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</strong>
以上是如何在Java 9的JShell中获取系统属性?的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

Java的类上载涉及使用带有引导,扩展程序和应用程序类负载器的分层系统加载,链接和初始化类。父代授权模型确保首先加载核心类别,从而影响自定义类LOA

本文讨论了使用咖啡因和Guava缓存在Java中实施多层缓存以提高应用程序性能。它涵盖设置,集成和绩效优势,以及配置和驱逐政策管理最佳PRA

本文讨论了使用JPA进行对象相关映射,并具有高级功能,例如缓存和懒惰加载。它涵盖了设置,实体映射和优化性能的最佳实践,同时突出潜在的陷阱。[159个字符]

本文讨论了使用Maven和Gradle进行Java项目管理,构建自动化和依赖性解决方案,以比较其方法和优化策略。

本文使用Maven和Gradle之类的工具讨论了具有适当的版本控制和依赖关系管理的自定义Java库(JAR文件)的创建和使用。
