Solved

JDK6: Console

Posted on 2011-02-19
2
314 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

679 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