Java System.getProperty() Method

Learn via video course
FREE
View all courses
Java Course - Mastering the Fundamentals
Java Course - Mastering the Fundamentals
by Tarun Luthra
1000
5
Start Learning
Java Course - Mastering the Fundamentals
Java Course - Mastering the Fundamentals
by Tarun Luthra
1000
5
Start Learning
Topics Covered

Overview

The Java System.getProperty method is a built-in method of the System class in Java which is used to return the property of a system that is read by the key specified.

The system is a final class that contains several useful class fields and methods. out is a field in the System class, which is of type PrintStream, and it's the "standard" output stream. and println() is the method defined in PrintStream class

Syntax of Java System.getProperty()

The following is the syntax of the java system getproperty methods:

  • getProperty method with single parameter:
  • getProperty method with two parameters:

Parameters of Java System.getProperty()

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

getProperty Method with Single Parameter

In this case, the getProperty method takes one parameter key of the string type.

  • key: Key refers to the value whose system properties are being extracted.

getProperty Method with Two Parameters

In this case, the getProperty method takes two parameters key and definition of string type.

  • key: Key refers to the value whose system properties are being extracted.
  • definition: Definition refers to the default value of the specified key.

Return Value of Java System.getProperty()

The java system getproperty methods, when called, return the following values:

  • It returns the system property of the key specified in the parameter.
  • If the key is not present in the string input then it returns the null value.

Example

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

getProperty Method with Single Parameter

In this example, we will pass a string "java getProperty:" and a key "Java" in the getProperty method and will use the java system getproperty.

Code:

Output:

Explanation of the example:

  • In this case, we are only passing one parameter "Java" to the java system getproperty method, thus the System.out.println("Java getProperty : " + System.getProperty("Java")); would display null because the definition of the key is not present.

getProperty Method with Two Parameters

In this example, we will pass a string "java getProperty: " and a key "Java" and definition "language" in the getProperty method and will use the java system getproperty.

Code:

Output:

Explanation of the example:

  • In this case, we are passing two parameters "Java" and "language" to the java system getproperty method, thus the System.out.println("Java getProperty : " + System.getProperty("Java", "language")); would display 'Java getProperty : language'.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data

What is Java System.getProperty()?

As discussed earlier, The java system getproperty method is used to return the property of a system that is read by the key specified.

The java system getproperty is a method of Java System class. The java system getproperty method is passed an argument list and it is used to extract the property associated with keys from the list.

There are two types of java system getproperty methods present in the Java System Class:

  • java system getproperty method with single parameter: This method only takes one parameter key and returns the values associated with the key as a string value.
  • java system getproperty method with two parameters: This method only takes two parameters key and definition and returns the values associated with the key as a string value.

More Examples

In this section, we will be going displaying the system properties of custom values as well as inbuilt ones.

Output:

Explanation

In the above example, for each case, we have passed the key and definitions (in the case of two parameters). The java system getproperty method will return the values according to the input provided.

Java System.getProperty vs System.getenv

The System.getenv() returns an unmodifiable string map view of the current system environment. In this section we will learn the difference between System.getProperty vs System.getenv:

System.getPropertySystem.getenv
The System.getProperty values are available only within the scope of the Java platform.The System.getenv values are globally scoped at the Operating System level and thus available to all applications running on the same machine.
It is necessary to exit System.getProperty while packaging the application.The System.getenv values can be created anytime.
The System.getProperty values can be updated at runtime.The System.getenv values are an immutable copy of the operating system thus they cannot be updated.

Conclusion

  • The java system getproperty method is used to return the property of a system.
  • The java system getproperty works on key-value pairs.
  • The java system getproperty is a method of Java system class.
  • The java system getproperty methods can either accept one parameter key or two parameters key and definition.
  • The java system getproperty returns the system property of the specified key.
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more