Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #2199
| From | markspace <-@.> |
|---|---|
| Newsgroups | comp.lang.java.help |
| Subject | Re: Please recommend a book |
| Date | 2012-10-29 15:29 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <k6n017$pct$1@dont-email.me> (permalink) |
| References | <k6m3ti$n58$1@dont-email.me> <uauyrnthsg.gvjmts@mixnym.net> |
On 10/29/2012 12:09 PM, bobwhite@mixnym.net wrote:
>
> I don't think that's true because I'm familiar with abstract data types. My
> confusion starts when I say gee let me read a string from the keyboard. Now
> where do I go from there? I look at the Java API doc and try to find
> something that looks like console IO. Ok, I see a function there, but now
> how do I use it? I have to set up exception handling before I can do that!
> How do I do that? And it goes downhill from there.
Some of this is just "time," like I mentioned before. Java has a BIG
API and you won't learn it well by just reading one thing. Getting a
few basic books and looking at how they do it will give you some ideas.
In other words, there's "patterns" here that work, and some that don't.
Also, the API is spread out. It's been improved incrementally for 17
odd years, and similar things are not all together. In general to read
user input you want the System, not Console. Console is recent and just
contains some extensions to the basic I/O that people were asking for.
System.in is the workhorse. Wrap that in a BufferedReader and read from
that.
Time and just plowing through will get you there after a while. The
important bit is to do it.
Here's the most basic method. Try to build on this, even if fancier
methods are available, until you get more familiar with the Java API and
things start to be easier. Note that for quick-and-dirty and testing I
think it's better to NOT catch the exception, just declare the main
method with " throws Exception" and let the system do its thing.
<http://www.mkyong.com/java/how-to-read-input-from-console-java/>
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ReadConsoleSystem {
public static void main(String[] args) {
System.out.println("Enter something here : ");
try{
BufferedReader bufferRead = new BufferedReader(new
InputStreamReader(System.in));
String s = bufferRead.readLine();
System.out.println(s);
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Please recommend a book bobwhite@mixnym.net - 2012-10-25 14:50 +0000
Re: Please recommend a book Nigel Wade <nmw@ion.le.ac.uk> - 2012-10-25 17:44 +0100
Re: Please recommend a book markspace <-@.> - 2012-10-25 09:50 -0700
Re: Please recommend a book bobwhite@mixnym.net - 2012-10-26 14:54 +0000
Re: Please recommend a book "Charles Hottel" <chottel@earthlink.net> - 2012-10-26 11:14 -0400
Re: Please recommend a book Roedy Green <see_website@mindprod.com.invalid> - 2012-10-26 09:32 -0700
Re: Please recommend a book David Lamb <dalamb@cs.queensu.ca> - 2012-10-26 17:17 -0400
Re: Please recommend a book Lew <lewbloch@gmail.com> - 2012-10-26 15:04 -0700
Re: Please recommend a book bobwhite@mixnym.net - 2012-10-28 22:05 +0000
Re: Please recommend a book bobwhite@mixnym.net - 2012-10-29 11:07 +0000
Re: Please recommend a book David Lamb <dalamb@cs.queensu.ca> - 2012-10-29 10:30 -0400
Re: Please recommend a book bobwhite@mixnym.net - 2012-10-29 19:09 +0000
Re: Please recommend a book Patricia Shanahan <pats@acm.org> - 2012-10-29 12:38 -0700
Re: Please recommend a book Lew <lewbloch@gmail.com> - 2012-10-29 13:42 -0700
Re: Please recommend a book markspace <-@.> - 2012-10-29 15:29 -0700
Re: Please recommend a book Roedy Green <see_website@mindprod.com.invalid> - 2012-10-31 07:28 -0700
Re: Please recommend a book bobwhite@mixnym.net - 2012-11-03 20:37 +0000
Re: Please recommend a book Lew <lewbloch@gmail.com> - 2012-11-03 16:22 -0700
Re: Please recommend a book markspace <-@.> - 2012-11-03 20:42 -0700
Re: Please recommend a book bobwhite@mixnym.net - 2012-11-04 14:40 +0000
Re: Please recommend a book Lew <lewbloch@gmail.com> - 2012-11-04 20:27 -0800
Re: Please recommend a book Roedy Green <see_website@mindprod.com.invalid> - 2012-10-26 09:24 -0700
Re: Please recommend a book Roedy Green <see_website@mindprod.com.invalid> - 2012-10-26 09:31 -0700
Re: Please recommend a book Patricia Shanahan <pats@acm.org> - 2012-10-27 06:19 -0700
Re: Please recommend a book bobwhite@mixnym.net - 2012-10-28 21:05 +0000
Re: Please recommend a book bobwhite@mixnym.net - 2012-10-29 12:08 +0000
Re: Please recommend a book Jeff Higgins <jeff@invalid.invalid> - 2012-10-28 19:09 -0400
Re: Please recommend a book bobwhite@mixnym.net - 2012-11-01 14:25 +0000
Re: Please recommend a book Jeff Higgins <jeff@invalid.invalid> - 2012-11-01 13:47 -0400
csiph-web