A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/java/lang/system_getproperty_string.htm below:

Java System getProperty() Method

Java System getProperty() Method Description

The Java System getProperty(String key) method gets the system property indicated by the specified key.

Declaration

Following is the declaration for java.lang.System.getProperty() method

public static String getProperty(String key)
Parameters

key − This is the name of the system property.

Return Value

This method returns the string value of the system property, or null if there is no property with that key.

Exception Example: Getting User Directory

The following example shows the usage of java.lang.System.getProperty() method. In this program, we've retrieved and printed the user directory using getProperty() method and passing it "user.dir". In next statement, we've passed non-existent key to check if getProperty() method returns null.

package com.tutorialspoint;

public class SystemDemo {

   public static void main(String[] args) {

      // prints the name of the system property
      System.out.println(System.getProperty("user.dir"));

      // prints null if system property is not present
      System.out.println(System.getProperty("user.name1"));
   }
} 
Output

Let us compile and run the above program, this will produce the following result −

C:\Users\Tutorialspoint\eclipse-workspace\Tutorialspoint
null
Example: Getting Operating System Name

The following example shows the usage of java.lang.System.getProperty() method. In this program, we've retrieved and printed the user directory using getProperty() method and passing it "os.name".

package com.tutorialspoint;

public class SystemDemo {

   public static void main(String[] args) {
   
      // prints the name of the Operating System
      System.out.println(System.getProperty("os.name"));
   }
} 
Output

Let us compile and run the above program, this will produce the following result −

Windows 11
Example: Getting Java Runtime Details

The following example shows the usage of java.lang.System.getProperty() method. In this program, we've retrieved and printed the user directory using getProperty() method and passing it "java.runtime.version".

package com.tutorialspoint;

public class SystemDemo {

   public static void main(String[] args) {

      // prints Java Runtime Version
      System.out.println(System.getProperty("java.runtime.version" ));
   }
} 
Output

Let us compile and run the above program, this will produce the following result −

21.0.2+13-LTS-58

java_lang_system.htm


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4