Solved

JDK6: Console

Posted on 2011-02-19
2
291 Views
Last Modified: 2012-05-11
hi all,

i have a problem by using method console(). It could not be compiled.

following are the codes.

can someone tell me where is the problem?

thanks,
wantime
import java.io.*
public class Test{
 public static void main(String[] args){
   Console c = new Console();
 }
}

Open in new window

0
Comment
Question by:wantime
  • 2
2 Comments
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 500 total points
ID: 34933427
http://www.stupidjavatricks.com/?p=43
Console does not have public constructors - youshoud get it from System, see above link
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 34933501
You just say:

Console c = System.console();

instead  of  Console c = new Console();

It is probably also worth reading what they write there in the article above
about different cases when you can obtain Console and when it will return null.

More or less the same stuff in a more standard site with Java 6 API
http://download.oracle.com/javase/6/docs/api/java/io/Console.html
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java 1603 Error 3 50
Java and GPO 11 71
what is a "java.lang.System Property"   ? 20 57
maven project error 5 48
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now