System is the name of the built-in class that contains methods and objects used to get input from the keyboard, print text on the screen, and do file input/output (I/0).
System.out is the name of the object we have used to print text. When you invoke print and println, you invoke them on the object named System.out.
Interestingly, you can print System.out:
System.out.println (System.out);The output is:
java.io.PrintStream@80cc0e5As usual, when Java prints an object, it prints the type of the object, which is PrintStream, the package in which that type is defined, java.io, and a unique identifier for the object. On my machine the identifier is 80cc0e5, but if you run the same code, you will probably get something different.
There is also an object named System.in that has type BufferedInputStream. System.in makes it possible to get input from the keyboard. Unfortunately, it does not make it easy to get input from the keyboard. First, you have to use System.in to create a new InputStreamBuffer.
InputStreamReader in = new InputStreamReader (System.in);Then you use in to create a new BufferedReader:
BufferedReader keyboard = new BufferedReader (in);The point of all this manipulation is that there is a method you can invoke on a BufferedReader, called readLine, that gets input from the keyboard and converts it into a String. For example:
String s = keyboard.readLine (); System.out.println (s);reads a line from the keyboard and prints the result.
There is only one problem. There are things that can go wrong when you invoke readLine, and they might cause an IOException. There is a rule in Java that if a method might cause an exception, it should say so. The syntax looks like this:
This indicates that main might ``throw'' an IOException.
You can think of throwing an exception as similar to throwing
a tantrum.
Type a word or phrase. I will check and see if it is a palindrome. > banana You typed: banana banana is not a palindrome.