Previous | Next | Trail Map | Writing Java Programs | The Nuts and Bolts of the Java Language


Run the Application

The output of the character-counting program depends on the input you enter for it. When an application reads from the standard input stream, like the character-counting application does, the application blocks and waits for you to type something in. The application continues to wait for input until you give it some indication that the input is complete. For any program that reads from the standard input stream, you must type the end-of-input character at the beginning of a new line to indicate that you have finished entering characters. When the character-counting program receives an end-of-input character it prints out the number of characters you typed.

Here are the platform-specific instructions for running the character-counting application.

In the sample below, the user enters This is a test. followed by the appropriate end-of-input character. In response, the application displays Input has 16 chars.

This is a test.
Input has 16 chars.
At first glance it may appear that the output is incorrect, since This is a test. has only 15 characters. But the user entered a new line as the 16th character.

Note: The program gives different results for different platforms. On UNIX when you press the Return key, you get a single character: \n. However, in Windows 95/NT when you press the Return key, you get two characters: \r\n.


Previous | Next | Trail Map | Writing Java Programs | The Nuts and Bolts of the Java Language