search
HomeJavajavaTutorialHow to get system properties in JShell in Java 9?

如何在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>

The above is the detailed content of How to get system properties in JShell in Java 9?. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:tutorialspoint. If there is any infringement, please contact admin@php.cn delete
How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?Mar 17, 2025 pm 05:46 PM

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?Mar 17, 2025 pm 05:45 PM

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?Mar 17, 2025 pm 05:44 PM

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?Mar 17, 2025 pm 05:43 PM

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

How does Java's classloading mechanism work, including different classloaders and their delegation models?How does Java's classloading mechanism work, including different classloaders and their delegation models?Mar 17, 2025 pm 05:35 PM

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment