Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Console class in Java [scjp 6]

 
Antriksh Verma
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic