![java package tutorial](/java/lang/images/java.jpg)
- Java.lang Package classes
- Java.lang - Home
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang Package extras
- Java.lang - Interfaces
- Java.lang - Errors
- Java.lang - Exceptions
- Java.lang Package Useful Resources
- Java.lang - Useful Resources
- Java.lang - Discussion
Java System getProperty() Method
Description
The Java System getProperty(String key, String def) method gets the system property indicated by the specified key.The argument def is the default value.
Declaration
Following is the declaration for java.lang.System.getProperty() method
public static String getProperty(String key, String def)
Parameters
key − This is the name of the system property.
def − This is a default value.
Return Value
This method returns the string value of the system property, or null if there is no property with that key.
Exception
SecurityException − if a security manager exists and its checkPropertyAccess method doesn't allow access to the specified system property.
NullPointerException − if key is null.
IllegalArgumentException − if key is empty.
Example: Getting default Value if System Property is not present
The following example shows the usage of Java System getProperty() method. In this example, we've used a non-existing key password. As key is not present, System.getProperty() method returns the default value passed as argument as same is printed.
package com.tutorialspoint; public class SystemDemo { public static void main(String[] args) { // gets the system property System.out.println(System.getProperty("password","defaultPassword")); } }
Output
Let us compile and run the above program, this will produce the following result −
defaultPassword
Example: Getting Value if System Property is present
The following example shows the usage of Java System getProperty() method. In this example, we've used an existing key password. As key is present, System.getProperty() method returns the available value.
package com.tutorialspoint; public class SystemDemo { public static void main(String[] args) { // gets the system property System.out.println(System.getProperty("user.name","user")); } }
Output
Let us compile and run the above program, this will produce the following result −
Tutorialspoint