views:

313

answers:

3

Can any body please tell me what code is used for clear screen in Java? For example in C++

system("CLS");

What code is used in Java for clear screen?

Thanks!

+2  A: 
Runtime.getRuntime().exec("cls");
Lucass
is any import statement also required with this?
sadia
@sadia - no ... but you could have figured that out for yourself.
Stephen C
i have no other source to get info about this because i have no book and my next java class is on monday so i cannot ask to my teacher too, but i don't want to wast my 2 days before monday. That is why i am presenting my queries here.
sadia
You do - the internet. Learn to google, it will be important.
Bozho
+4  A: 

The equivalent Java code would be:

Runtime.getRuntime().exec("cls");

Just a word of caution, that's going to be system dependent.

Bill the Lizard
is any import statement also required with this? i am using jcreator as my java editor. but your code is not working there. can you please help a little more? thanks.
sadia
@sadia - that is not actually executable code ... but a hint to help you solve the problem for yourself.
Stephen C
i have no other source to get info about this because i have no book and my next java class is on monday so i cannot ask to my teacher too, but i don't want to wast my 2 days before monday. That is why i am asking u people.
sadia
@sadia: No, Runtime is in the java.lang package, so no import statement is necessary. Are you running this in an IDE, or at the command line?
Bill the Lizard
i am running this in Jcreator(IDE) not in command line.
sadia
"i have no other source to get info about this" - Really? You're online, aren't you? Who needs books or a professor then?
Jan Kuboschek
@sadia: Try wrapping that line of code in a simple main method (you should have or be able to find a "Hello, World!" example), compile it, and run it from the command line.
Bill the Lizard
i have searched Google to a great extent for finding this but everywhere i found nothing but a debate between different people regarding this clear screen code. and i have reached to the conclusion that there does not exist such code in java which can be used for clear screen!!!
sadia
A: 

Does anyone know how to make this work in Linux. I tried

java.lang.Runtime.getRuntime().exec("pwd");

It didn't give me the supposed output.

Desper