import java.io.IOException;
public class CLS {
    public static void main(String... arg) throws IOException, InterruptedException {
        new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
    }
}
Now when the Java process is connected to a console, i.e. has been started from a command line without output redirection, it will clear the console.