This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Console Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Console Class" Watch "Console Class" New topic
Author

Console Class

Mudit Srivastava
Ranch Hand

Joined: Apr 30, 2007
Posts: 38
Guys

I just can't figure out the Console Class.

Please help...
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
When I don't understand the use of a class in the standard library, the first thing I do is see if Sun had the wisdom to provide a tutorial, site:java.sun.com java.io.Console tutorial. In this case, they have


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43968
    
  33
You are reminded: Console will only work if you start your application from the command line with the java instruction.
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
Campbell, that's only true for some OS right?


SCJA
~Currently preparing for SCJP6
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20078
    
  30

System.console() will return null if no console is available, and that is always the case if started using javaw or from most IDEs. Therefore, always perform the check against null.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43968
    
  33
Brian Legg wrote:Campbell, that's only true for some OS right?
Rob has provided a more accurate answer.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Console Class
 
It's not a secret anymore!