Home » Java programming language

Java System class setProperties() method with example

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

System class setProperties() method

  • setProperties() method is available in java.lang package.
  • setProperties() method is used to set the current system properties of the given parameter (system_property).
  • setProperties() method is a static method, so it is accessible with the class name too.
  • setProperties() method throws a SecurityException at the time of setting the system properties:
    SecurityException: In this exception, its checkPermission() method can’t allow access to the given system properties when the security manager exists.

Syntax:

    public static void setProperties(Properties system_property);

Parameter(s):

  • system_property – represents the new system property.

Return value:

The return type of this method is void, it does not return any value.

Example:

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

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

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

        Properties prop = System.getProperties();
        prop.put("os.arch", "Hybrid Kernel");
        System.setProperties(prop);

        System.out.println();

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

Output

E:\Programs>javac SetPropertiesMethod.java
E:\Programs>java SetPropertiesMethod
Previous Architecture : amd64
New Architecture : Hybrid Kernel


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.