wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Console class in Java [scjp 6] 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 "Console class in Java [scjp 6]" Watch "Console class in Java [scjp 6]" New topic
Author

Console class in Java [scjp 6]

Antriksh Verma
Ranch Hand

Joined: Nov 24, 2008
Posts: 56
1. What is the significance of Console class ? where exactly we will use it ?
2. How should i test it , since jdk1.6 is returning its object null ?

Please help me to understand , java.io.Console , with perspective to SCJP 6 exam.
Karthikeya Vaidyanathan
Greenhorn

Joined: Dec 27, 2011
Posts: 2

Console class is used for formatting output. For example, you wants to specify some common pattern while printing. It will helpful for that.
Antriksh Verma
Ranch Hand

Joined: Nov 24, 2008
Posts: 56
Thanks Karthik .. But we can get formatted output from System.out.format too , but i hav came across the fact that it is used
used for secure interaction via command line and when GUI is not needed .

But problem is , tell me way .. how to use it and test it , as my jdk 1.6 environment is giving Null to System.console()

So how to create Java environment that have access to console object in same environment.

I dont want to skip this topic of SCJP6 , just like that .. if its not running in my current environment. Please suggest.
O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

Are you using an IDE to test it? I am not sure if you can get a console when using an IDE. This test example works for me when compiled and run via the command prompt

Antriksh Verma
Ranch Hand

Joined: Nov 24, 2008
Posts: 56
Hi Ziggy , thanks !

No iam not running it @ Netbeans or other IDE.

Trying to compile it @ command prompt and iam getting below compile time errors :

ConsoleTests.java:2: cannot find symbol
symbol : class Console
location: package java.io
import java.io.Console;
^
ConsoleTests.java:8: cannot find symbol
symbol : class Console
location: class ConsoleTests
Console c = System.console();
^
ConsoleTests.java:8: cannot find symbol
symbol : method console()
location: class java.lang.System
Console c = System.console();

Which directly means that my java environment is not getting System.console object , how should i fix it ?
Antriksh Verma
Ranch Hand

Joined: Nov 24, 2008
Posts: 56
Hi

I got problem .. My Java version is 1.5

But now i have updated it to 1.6 , its working fine.

Thanks a lot for your support , Folks.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Console class in Java [scjp 6]
 
Similar Threads
SCJP 6 - Upgrade Exam
SCJP 6 Upgrade Exam - PASS 91%
SCJP 5.0 vs SCJP 6.0
SCJP 5 or 6 ?
scjp