Java.lang.System.setProperties() Method

Advertisements


Description

The java.lang.System.setProperties() method sets the system properties to the Properties argument.

Declaration

Following is the declaration for java.lang.System.setProperties() method

public static void setProperties(Properties props)

Parameters

  • props -- This is the new system properties.

Return Value

This method does not return any value.

Exception

  • SecurityException -- if a security manager exists and its checkPropertiesAccess method doesn't allow access to the system properties.

Example

The following example shows the usage of java.lang.System.setProperties() method.

package com.tutorialspoint;

import java.lang.*;

public class SystemDemo {

   public static void main(String[] args) {

     // prints Java Runtime Version before property set
     System.out.print("Previous : ");
     System.out.println(System.getProperty("java.runtime.version"));
      
     Properties p = System.getProperties();
     p.put("java.runtime.version", "Java Runtime 1.6.0");
     System.setProperties(p);
      
     // prints Java Runtime Version after property set
     System.out.print("New : ");
     System.out.println(System.getProperty("java.runtime.version"));
   }
} 

Let us compile and run the above program, this will produce the following result:

Previous : 1.6.0_22-b22
New : Java Runtime 1.6.0



Advertisements
Advertisements