Source code: ClearConsole.java
public class ClearConsole {
public final static void clearConsole()
{
    try
    {
        final String os = System.getProperty("os.name");
        //System.out.println("System name = " + os);

        if (os.contains("Windows"))
        {
            //System.out.println("Found Windows");
            Runtime.getRuntime().exec("cls\n");
        }
        else
        {
            Runtime.getRuntime().exec("clear");
        }
    }
    catch (final Exception e)
    {
        //  Handle any exceptions.
       for (int i=0; i< 50; i++) 
	   System.out.println("");
    }
}
}