Using system properties in Java

The System class maintains a Properties object that describes the configuration of the current working environment. System properties include information about the current user,the current version of the Java runtime,and the character used to separate components of a file path name.
In this post I am going to show simple example which shows how to get and set system properties.

public class Main{ public static void main(String[] args){ String version = System.getProperty("java.version"); System.out.println("Java version = " + version); System.setProperty("java.version","2"); System.out.println("Java version = " + System.getProperty("java.version")); System.out.println("=======All system properties======="); System.getProperties().list(System.out); }}

In this example I get/set specific property and get all system properties.
Note:your changes will not be available after exiting from program. The runtime system re-initializes the system properties each time its starts up. If changes to system properties are to be persistent,then the application must write the values to some file before exiting and read them in again upon startup.

 

Download this code.

Share

No related posts.

Leave a Reply

  

  

  

You can use these HTML tags

<a href=""title=""><abbr title=""><acronym title=""><b><blockquote cite=""><cite><code><del datetime=""><em><i><q cite=""><strike><strong>

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna,tincidunt vitae molestie nec,molestie at mi. Nulla nulla lorem,suscipit in posuere in,interdum non magna.