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.
No related posts.

Recent Comments