Java source code examples

Java source code samples. Java code examples.

Entries Tagged as 'java.lang'

Runs the finalization methods

April 29th, 2008 · 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();
}
}

[Read more →]

Tags: java.lang

Runs the garbage collector

April 29th, 2008 · 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();
}
}

[Read more →]

Tags: java.lang

Terminates the currently running Java Virtual Machine

April 29th, 2008 · No Comments

Terminates the current Java Virtual Machine

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

[Read more →]

Tags: java.lang

Gets an environment variable value

April 29th, 2008 · 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);
}
}

[Read more →]

Tags: java.lang

Removes a system property value

April 29th, 2008 · 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);
}
}

[Read more →]

Tags: java.lang

Gets the logged in user name using java

April 29th, 2008 · No Comments

public class SystemExample {
public static void main(String[] args) {
String value = System.getProperty(“user.name”);

System.out.println(value);
}
}

[Read more →]

Tags: java.lang

Gets operating system name using java

April 29th, 2008 · No Comments

public class SystemExample {
public static void main(String[] args) {
String value = System.getProperty(“os.name”);

System.out.println(value);
}
}

[Read more →]

Tags: java.lang

Gets the current System properties

April 29th, 2008 · 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);

}
}
}

[Read more →]

Tags: java.lang

Copies the contents of an array to another array

April 29th, 2008 · 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]);
}
}
}

[Read more →]

Tags: java.lang

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

April 29th, 2008 · 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”);
}
}

[Read more →]

Tags: java.lang