Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML
 
 
Hot Web Programming Job

 

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

[an error occurred while processing this directive]

Java Notes

Keyboard Input

There are two approaches to getting keyboard input from the user.

  1. GUI (Graphical User Interface). Displaying a graphical text box to type into is the how standard programs communicate.
  2. Console. Console I/0 is the old-fashioned style of interaction where the human and computer type text back and forth to each other - basically a screen version of the old Teletype machine. Java was designed for graphical user interfaces (GUI) and large programs, and no attempt was made in the beginning to have simple keyboard input, eg, something like C++'s cin.

    Java 5 (introduced around the beginning of 2005) introduced the java.util.Scanner class, which made console I/O easy for the first time. It's also very useful for reading from text files.

Graphical User Interface

This is how normal programs interact - windows, buttons, menus, etc.

  • Full-strength GUIs require a bit of programming. They aren't really very hard, but they do require knowing things that would be too much for the very first programs.
    • Advantages: This is what you want your programs to look like.
    • Disadvantages: Too much coding to start. Fortunately, it's easy to use the simple dialog boxes.
  • Dialog boxes using JOptionPane.showInputDialog.
    • Advantages: Easy to use.
    • Disadvantages: Limited to text fields (no menus, etc).

Console input - reading from System.in

Console input is rarely used in real programs, so why do authors like to use it? There are probably two reasons: (1) It was the only standard way in Pascal, C, C++, etc. This is how the authors learned to program, and they often have written pre-Java textbooks which they've adapted to Java.

  • Proprietary classes (eg, SavitchIn, ...). Many authors have struggled with how do simple input. If they're determined to use console input, there was no alternative to writing their own classes.
    • Advantages: Easier than BufferedReader.
    • Disadvantages: The are unique to each author and are never used anywhere else.
  • java.io.BufferedReader
    • Advantages: It runs in all versions of Java.
    • Disadvantages: It requires a lot of programming. Console input is awkward..
  • java.util.Scanner
    • Advantages: It's easy to use.
    • Disadvantages: It wasn't available until Java 5, so may not be available, and it's still coming from the console.

My recommendation - Use JOptionPane for simple input

You really want to have a GUI interface, don't you? JOptionPane methods are easy and standard.

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (
post your own) View All Comments Latest 10 Comments:
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.