8.5. Input and Output

The simplest forms of I/O are discussed in this section: printing to standard output and reading from standard input.

Printing to Standard Output

You've already seen examples of printing with System.out.println. As you probably guessed from the Java naming conventions, out is a static variable in the System class, and println is a method in the class that belongs to out. That class is PrintStream; it also contains a print method that works just like println except that it omits the trailing newline. Both println and print take a single argument of any type. Primitive types are converted to strings by the String.valueOf method, and non-String objects are converted to strings by their toString method. Longer strings can be ...

Get Core Web Programming, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.