HOME      BLOG       FORUMS      CONTACT       ABOUT

Runs the finalization methods

April 29th, 2008 Albin Joseph Posted in java.lang No Comments »

Runs the finalization methods

public class SystemExample {
	public static void main(String[] args) {
		Runtime.getRuntime().runFinalization();
	}
}

or

public class SystemExample {
	public static void main(String[] args) {
		System.runFinalization();
	}
}
Share
AddThis Social Bookmark Button

Runs the garbage collector

April 29th, 2008 Albin Joseph Posted in java.lang No Comments »

Runs the garbage collector

public class SystemExample {
	public static void main(String[] args) {
		System.gc();
	}
}

or

public class SystemExample {
	public static void main(String[] args) {
		Runtime.getRuntime().gc();
	}
}
Share
AddThis Social Bookmark Button

Terminates the currently running Java Virtual Machine

April 29th, 2008 Albin Joseph Posted in java.lang No Comments »

Terminates the current Java Virtual Machine

public class SystemExample {
	public static void main(String[] args) {
		System.exit(1);
	}
}
Share
AddThis Social Bookmark Button

Gets an environment variable value

April 29th, 2008 Albin Joseph Posted in java.lang No Comments »

Gets an environment variable value

public class SystemExample {
	public static void main(String[] args) {
		String value = System.getenv("PATH");
		
		System.out.println(value);
	}
}
Share
AddThis Social Bookmark Button

Removes a system property value

April 29th, 2008 Albin Joseph Posted in java.lang No Comments »

Removes a system property value

public class SystemExample {
	public static void main(String[] args) {
		System.clearProperty("user.name");
		String value = System.getProperty("user.name");
		
		System.out.println(value);
	}
}
Share
AddThis Social Bookmark Button

Gets the logged in user name using java

April 29th, 2008 Albin Joseph Posted in java.lang No Comments »

public class SystemExample {
	public static void main(String[] args) {
		String value = System.getProperty("user.name");
		
		System.out.println(value);
	}
}
Share
AddThis Social Bookmark Button

Gets operating system name using java

April 29th, 2008 Albin Joseph Posted in java.lang No Comments »

public class SystemExample {
	public static void main(String[] args) {
		String value = System.getProperty("os.name");
		
		System.out.println(value);
	}
}
Share
AddThis Social Bookmark Button

Gets the current System properties

April 29th, 2008 Albin Joseph Posted in java.lang No Comments »

import java.util.Enumeration;
import java.util.Properties;

public class SystemExample {
	public static void main(String[] args) {
		Properties prop = System.getProperties();
		
		Enumeration en = prop.keys();
		while(en.hasMoreElements()){
			String  key = (String) en.nextElement();
			String value = prop.getProperty(key);
			
			System.out.println(key +" = "+value);
				
		}
	}
}
Share
AddThis Social Bookmark Button

Copies the contents of an array to another array

April 29th, 2008 Albin Joseph Posted in java.lang No Comments »

public class SystemExample {
	public static void main(String[] args) {
		int arr1[] ={1,2,3,4,5};
		int arr2[] = new int[5];
		
		System.arraycopy(arr1, 0, arr2, 0, 5);
		for (int i = 0; i < arr2.length; i++) {
			System.out.println(arr2[i]);
		}
	}
}
Share
AddThis Social Bookmark Button

Redirect standard error stream (System.err) to a file

April 29th, 2008 Albin Joseph Posted in java.lang No Comments »

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;

public class SystemExample {
	public static void main(String[] args) throws IOException {
		PrintStream p = new PrintStream(new FileOutputStream(new File("c:\\temp\\out.log")));
		System.setErr(p);
		
		System.out.println("Hello World");
	}
}
Share
AddThis Social Bookmark Button