Home » Java programming language

Java System class setProperty() method with example

System class setProperty() method: Here, we are going to learn about the setProperty() method of System class with its syntax and example.
Submitted by Preeti Jain, on September 12, 2019

System class setProperty() method

  • setProperty() method is available in java.lang package.
  • setProperty() method is used to sets the system property denoted by the given parameter (system_property) with the given another parameter (system_property_value).
  • setProperty() method is a static method, so it is accessible with the class name too.
  • setProperty() method method throws various exceptions at the time of setting the system property
    • SecurityException: In this exception, its checkPermission() method can't allow access to the given system properties when the security manager exists.
    • NullPointerException: In this exception, if the given system_property or given system_property_value is null.
    • IllegalArgumentException: In this exception, if the given system property is null.


    public static String setProperty(
            String  system_property, 
            String system_property_value);


  • ssystem_property – represents the name of the system property.
  • ssystem_property_value – represents the value of the system property.

Return value:

The return type of this method is String, it returns the old value of the system property if exists else it returns null.


// Java program to demonstrate the example of 
// setProperty() method of System Class.

import java.lang.*;
import java.util.*;

public class SetPropertyMethod {
    public static void main(String[] args) {
        //Display previous operating system
        //architecture before setting properties
        System.out.print("Previous os name :" + " ");

        System.setProperty("os.name", "Ubuntu");


        //Display new operating system
        //architecture after setting properties
        System.out.print("New os name :" + " ");


E:\Programs>javac SetPropertyMethod.java
E:\Programs>java SetPropertyMethod
Previous os name : Linux
New os name : Ubuntu

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.