Solved

JDK6: Console

Posted on 2011-02-19
2
325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

636 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