Friday, 10 May 2013

System class 2 - JAVA

Continue from http://tech-world-brij.blogspot.in/2013/05/system-class-1-java.html
Another interesting method of System class is System.getProperty. It gives much useful information about java, current use and OS. Here is example,

class SystemClass
{
public static void main(String[] args) 
{
System.out.print("\n" + System.getProperty("java.version"));
System.out.print("\n" + System.getProperty("java.vendor"));
System.out.print("\n" + System.getProperty("java.vendor.url"));
System.out.print("\n" + System.getProperty("java.home"));
System.out.print("\n" + System.getProperty("java.class.version"));
System.out.print("\n" + System.getProperty("java.class.path"));
System.out.print("\n" + System.getProperty("os.name"));
System.out.print("\n" + System.getProperty("os.arch"));
System.out.print("\n" + System.getProperty("os.version"));
System.out.print("\n" + System.getProperty("line.separator"));
System.out.print("\n" + System.getProperty("user.name"));
System.out.print("\n" + System.getProperty("user.home"));
System.out.print("\n" + System.getProperty("user.dirr"));
System.out.print("\n" + System.getProperty("file.separator"));
}
}

If you are in need of more information then use System.getProperties().

System.exit(int); method will exit from currently running program directly.

System.gc() can be called to make space i.e. it will free all unused memory. This method internally calls Runtime.getRunTime().gc();

System.currentTimeMillis() and System.nanoTime() these functions will give you current system time in milli-seconds and nano-seconds respectively.

System.getenv("ENV_VAR_NAME") this method will return you value of that specific environment variable.

System.getenv() this method will return all environment variables and path of system. It will also give processor architecture, number of processors, home drive etc. If you exactly know what you want then use above method.

No comments:

Post a Comment