3.12 Using System.in and System.out

In order to print program output to the screen, we have been using statements like

System.out.println( "The value of b is " + b );

and

System.out.print( "Enter your first name > " );

And to instantiate a Scanner object, we used this statement:

Scanner scan = new Scanner( System.in );

It is now time to look at these statements in depth and understand them completely.

System is an existing Java class in the java.lang package. One of its fields is a static constant, out, which represents the Java console by default. Another of its fields is a static constant, in, which represents the keyboard by default. Because in and out are static, we refer to them using the class name, System, and the dot notation:

System ...

Get Java Illuminated, 5th 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.