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

Alternatives to SavitchIn

Objection to SavitchIn

Non-standard. The Savitch textbook is good, but has one objectionable aspect - Instead of using standard Java to get input from the user, he has written a proprietary class called SavitchIn to read from the console input stream. You will never see this class used anywhere else. If you use it in this class, you will have to forget about it and learn the standard way to doing things. I propose we drop it and learn one of the easy, standard ways to do input.

Scanner, but.... Before Java 5 (JDK 1.5), it was awkward to read from the console, so his intentions were good in making it easier for students. Console input can be done using the Java 5 java.util.Scanner class. However, this only works if you have installed Java 5, which was not on the book CD. Some students probably don't have adequate download access, so this alternative is unacceptable. Anyway, there's a better way using graphical dialog boxes.

Before we go into the (simple) details of dialog boxes, here are two simple "first" programs to test your installed software with. These should be used in preference to the example on page 23 of the textbook.

First programs

Here are two programs here that you can use to test your development software installation (eg, TextPad). Copy from these examples, and paste them into TextPad (or whatever). Save them in a file with the same name as the class plus ".java", compile and run them. They show the difference between console output and dialog box output. Everything in these programs will be explained, so I don't expect you to understand them yet. This is just a test for your development system.

Console output

// File:        cmis102a/ch01_helloConsole/HelloConsole.java
// Description: First console program.
// Author:      Fred Swartz
// Date:        2005-Jan-26

public class HelloConsole {
    public static void main(String[] args) {
        System.out.println("Hello in the console output stream!");
    }
}

This should produce a DOS command window with the message in it.

Dialog box output

// File:        cmis102a/ch01_helloDialog/HelloDialog.java
// Description: First dialog box program.
// Author:      Fred Swartz
// Date:        2005-Jan-26

import javax.swing.*;

public class HelloDialog {
    public static void main(String[] args) {
        JOptionPane.showMessageDialog(null, "Hello in a dialog box!");

        System.exit(0);  // Make sure program is stopped.
    }
}

If you compile and run this in TextPad it will produce a DOS command window, altho there is no program output in it. This window is entirely an artifact of TextPad and would not normally appear when running a GUI-based Java program.

Use SavitchIn if you wish

It really doesn't matter which style of input/output (I/O) you use in this class.

  • Console I/O using SavitchIn for input.
  • Console I/O using Scanner for input (requires Java 5)
  • Dialog box I/O.

I'll supply notes on dialog box I/O and will be using it in my examples, so you will get used to reading it, but write your programs using any of the above schemes.

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.