Characters In, Characters Out

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

What does the keyboard send to your program when you type the following:

1234

Answer:

The characters '1' , '2' , '3' , and '4' .

Characters In, Characters Out

The keyboard sends character data to the computer, even when the characters look like numbers. And the program sends characters to the monitor, even when it has calculated a numerical result. (Actually, characters are not sent directly to the monitor. They are sent to the graphics card which converts them into a video signal which is displayed on the monitor.)

characters flowing into a program

If your program does arithmetic, the input characters will be converted into one of the primitive numeric data types. This is done using a Scanner object. Then a result is calculated using arithmetic with the numeric data. The result must then converted to character data before it is sent to the monitor. This is done using a method of System.out.

QUESTION 5:

Have you already used System.out?