All Posts

Java System.getProperty Method

Java System.getProperty Method

The Java System.getProperty() method retrieves system properties and key-value(KV) pairs that provide configuration and environment details about the Java runtime and the operating system. The System class is part of the java.lang default package. It provides a collection of static methods and fields that offer system-level functionality.

Syntax

The general syntax of the method call is as follows:

System.getProperty(key);

The method signatures are:

public static String getProperty(String key)
key: The name of the system property to retrieve.

public static String getProperty(String key, String defaultValue)
key: The name of the system property to retrieve.
defaultValue: A default value to return if the specified property is not found.

Example

For example, you can use the method to retrieve the Java version as follows:

String javaVersion = System.getProperty(“java.version”);
System.out.println(“Java version: ” + javaVersion);

 

Java System getProperty method

 

In the above example, the Java version system property is retrieved and printed to the console.

Java Tutorials

Java Tutorial on this website: