Web Design, Development & Marketing

Web Development Articles

Java: Simple Prompt and Message Display

A simple script for beginners in Java is one which prints out a message to the user:

class Message
{
  public static void main (String [] args)
  {
    // Displays a message
    System.out.println("Hello!");
  }
}

Another addition to this would be to prompt for the user's name and then displaying this name in a message box:

import javax.swing.*;

class HelloName
{
  public static void main (String [] args)
  {
    //Prompts for name and displays welcome message
    String name = JOptionPane.showInputDialog
    ("Type in your name and press <enter>");
    System.out.println("Hello " + name);
    System.exit(0);
  }
}

This is a simple way to get started with Java and so that you can actually see some results straight away. This of course adds some meaning to what you are doing instead of leaving you baffled after looking at loads of Java code, not having a clue what it does!

Subscribe to RSS Feed Bookmark and Share

Related Links

Related Articles / Posts

Java: Quick Sort Algorithm Analysis (13/06/2006)

Java: Merge Sort Algorithm Analysis and Code (05/04/2006)

Java: Random Array Generator (29/03/2006)

Java: Insertion Sort Algorithm Analysis and Code (29/03/2006)

Java: Binary Search Algorithm Analysis and Code (29/03/2006)