File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Clear Screen in java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Clear Screen in java?" Watch "Clear Screen in java?" New topic
Author

Clear Screen in java?

Prateek Rawal
Ranch Hand

Joined: Dec 19, 2009
Posts: 90
Consider the following code:


The output of the code is:
1
2
3
4
5
6
7
8
9
10

I want the screen to get clear everytime the loop runs, although in this case it seems silly but for example i can create a new thread,make it print something and ask it to sleep, and when it wakes up i want the screen to get clear(so that i can notice the difference before clearing the screen and after clearing the screen......

So, speaking directly, i want the way to clear the screen in java.....



Waiting for enlightenment....
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

Check this FAQ...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

There is no simple way to do that. You might want to take a look at the link that Ankit posted. However do not go for an overkill like using another library to clear your screen. May be what you need is a method that will print 100 blank lines and you can invoke this method whenever required.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Prateek Rawal
Ranch Hand

Joined: Dec 19, 2009
Posts: 90
There is no simple way to do that.


So you are saying that there is no method or way in Java by which i can clear the screen anytime,
thats a shocking fact....omg!!!
Mark Uppeteer
Ranch Hand

Joined: Mar 02, 2004
Posts: 159

I once asked myself the same question (back in the days I was mostly doing C and C++) and was also shocked to hear that. But nowadays I'm not anymore and find it normal.


anyway..
try this:


in dos and read this


but you don't need to know this for your SCJP you know.


I know where my towel is. (SCJP 5, OCPJWCD)
[Free Quiz Tips for a fun night with friends or family] Flash games
Prateek Rawal
Ranch Hand

Joined: Dec 19, 2009
Posts: 90
The above supposed-to-be-solution is not working, i'm getting output like this

<-[2J
1
<-[2J
2
<-[2J
3
...and so on

Is clear screen not possible in java?
Give me a definite answer, i'm not able to interpret from the link you gave me....
Can you explain it here itself?


Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 543
    
    4

As was stated before, clear screen doesn't depend on any programming language, it depends on an Operating system. Read Mark Uppeteer's link. The only reason clear screen doesn't work in Java is because Java is platform independent and consoles are bound to the platform.

So you're not to check java for a clear screen command, you're to check your console if it allows it, then in what way it allows it.


Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Prateek Rawal
Ranch Hand

Joined: Dec 19, 2009
Posts: 90
I'm doing my program on command prompt....
How can i get how to clear screen in cmd using java?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Clear Screen in java?