Syntax error System.getProperty() in Java

System.getProperty() in Java



The getProperty(String key) method in Java is used to returns the system property denoted by the specified key passed as its argument.It is a method of the java.lang.System Class.

Declaration − The java.lang.System.getProperty(String key) is declared as follows −

public static String getProperty(String key)

where key is the name of the System property.

Some values of the key are as follows −

  • file.separator
  • java.specification.version
  • java.vm.version
  • java.class.path
  • java.vendor
  • java.class.version
  • os.arch
  • java.compiler
  • line.separator
  • java.version
  • java.vendor.url
  • os.name

Let us see a program showing the use of getProperty() method in Java −

Example

 Live Demo

public class Example {
   public static void main(String[] args) {
      System.out.println("System property: " + System.getProperty("user.dir"));
      System.out.println("Operating System: " + System.getProperty("os.name"));
      System.out.println("Java runtime version: " + System.getProperty("java.runtime.version" ));
   }
}

Output

System property: /home/cg/root/5182567
Operating System: Linux
Java runtime version: 1.8.0_141-b16
Updated on: 2023-10-31T03:19:57+05:30

27K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements