This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Program for Console Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Program for Console" Watch "Program for Console" New topic
Author

Program for Console

Sonali Sehgal
Ranch Hand

Joined: Jul 09, 2009
Posts: 75
I am preparing for SCJP 6.
Can you please explain java.io.Console class with the help of small program?
Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2691
    
    3

There are only few methods in java.io.Console class
I would recommend you to read the javadoc (please have a look at the above link). And then you should solve some mock exam questions too.


Author of ExamLab (Download) - the free mock exam kit for SCJP / OCPJP
Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
Sonali Sehgal
Ranch Hand

Joined: Jul 09, 2009
Posts: 75
I tried doing a program and there is a error coming in can you please help??

Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2691
    
    3

Sonali Sehgal wrote:I tried doing a program and there is a error coming


What is the error you are getting there?
I can see a little error that the "name" variable is not defined.
Sonali Sehgal
Ranch Hand

Joined: Jul 09, 2009
Posts: 75
Thanks a lot Devaka I got the solution and another thing I was using the version of Java that is 1.5 to fix the problem it should be of version1.6
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Note that netbeans does not support the console class internally.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Ankit Garg
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9189
    
    2

When you call System.console(), it will only return an instance of Console class if one is available. If the program is running in an environment which doesn't have a console, then null is returned...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Sonali Sehgal
Ranch Hand

Joined: Jul 09, 2009
Posts: 75
Hi Wouter and Ankit,


So in order to execute the program will the upgrading the version of java from 1.5 to 1.6 will help or only console needs to be added to netbeans ....As Kathy says java.io.Console is the latest in version 1.6....I also tried this program on another computer with version 1.6 java it was successfully executing........
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

If you want to use java.io.Console you need to hava java 1.6. The problem is that if you develop in netbeans, the console class will not be available because netbeans does (not yet) support it.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Program for Console
 
Similar Threads
not able to run my first java program
WA #1.....word association
Delete Expired Rows?
Finding the value of PI
Deployment error in jboss