The problem is that a reliable implementation of clrscr
requires the library method to know what kind of device it is connected to ... so that it can do the appropriate thing to clear the screen. A library might be able to know how to do this on Windows, but it can't be done on all platforms.
The general philosophy has been that if some functionality cannot be implemented across all supported platforms, then standard Java classes won't support it.
However, this doesn't mean that you can't implement your own library to do clrscr
yourself ... after having figured out how to do it on all platforms that matter to you. Or you could find a suitable 3rd-party library. You risk making your application non-portable, but that's your concern.
The other explanation is that the Java SE libraries don't provide any support for old-school terminals / terminal emulators. (The equivalent of the old "termcap" libraries.) Why? Because there is little call for it in these days of computers and phones with graphic screens. (I can't remember the last time I used a real 24x80 terminal ... but it was probably more than 25 years ago!)
I am a little skeptical on John's and mvp's answer:
It is hard to address your disbelief. Maybe the only thing that will convince you is for you to try to implement clrscr
in Java yourself across a wide range of platforms and output devices ...
How would a function like Thread.sleep() and System.out.println() work then?
All operating systems (or at least all that are capable of supporting Java) provide native API's / libraries with the required functionality.
In the case of Thread.sleep
, the JVM implementation typically uses the POSIX sleep(...)
function.
In the case of System.out.println
, out
is a PrintWriter
and the JVM creates a PrintWriter
that is connected to the standard output device. The println
call most likely results in a call to the POSIX write
function.
This is NOT the case for clrscr
. This functionality is not supported by the C standard libraries.