previous | start | next

An Application Program Example

An application class must have a main method in order to be executable.

/**
 * Application class that prompts for an input string, 
 * converts the string to upper case and prints the 
 * converted string.
 * @author glancast
 */
public class StringApp
{
    /**
     * The main program of this application
     * @param args - command line arguments (not used)
     */
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        String line;

        greeting();

        System.out.print("Enter an input line: ");
        line = in.nextLine();
        line = line.toUpperCase();
        System.out.printf("\nHere is your input converted to upper case:\n");
        System.out.println(line);
    }  

    /** 
     * Prints an introductory message to explain
     * what input this application expects and what it does.
     */
    public static void greeting()
    {
        String msg = 
            "This program will read an input line, convert it\n" +
            "to upper case, and print the converted string.";

        System.out.println(msg);
    }

}


previous | start | next