Standard input and output streams:
We have already encountered one stream object, namely System.out whose println method we have used to display information on the computer screen. For example:
System.out.println("The program has started");
The System class found in java.lang provides reference variables for three predefined streams, System.in, System.out and System.err. The standard input stream is System.in and it normally carries data from the keyboard of your computer; System.out is the standard output stream and is normally directed to a window on the screen of your computer; System.err can be used by the programmer to display error messages, and the destination is normally a screen window. All these three standard stream references are declared as public and static, so they can be conveniently accessed directly via the System class, without the need to create an object.
The System.out and System.err streams are of type PrintStream and have println and print methods immediately available for use. The System.in stream is of the generic type InputStream and is not so straightforward to use. It must normally be used in combination with other streams.
Input and output operations of all kinds are particularly likely to give rise to errors of the 'unexpected' kind, such as missing data files or errors in the format of input data. These situations are normally catered for in Java by means of exceptions. At the point in the code where the error occurs, we say the code throws an exception.
We shall see, later in this unit, the detail of how exceptions work and how to handle them. For the moment, we will deal with possible exceptions in a very simple way. Any method that could give rise to an input/output exception must declare this by adding throws IOException at the end of the method header, as in the following example:
public void openStreams (String fileName)throws IOException
{
...
}
Failure to declare this causes a compiler error. If such an exception does occur, the program will terminate with an error message indicating that an IOException has occurred.
Java Assignment Help - Java Homework Help
Struggling with java programming language? Are you not finding solution for your Standard input and output streams homework and assignments? Live Standard input and output streams experts are working for students by solving their doubts & questions during their course studies and training program. We at Expertsmind.com offer Standard input and output streams homework help, java assignment help and Standard input and output streams projects help anytime from anywhere for 24x7 hours. Computer science programming assignments help making life easy for students.
Why Expertsmind for assignment help
- Higher degree holder and experienced experts network
- Punctuality and responsibility of work
- Quality solution with 100% plagiarism free answers
- Time on Delivery
- Privacy of information and details
- Excellence in solving java programming language queries in excels and word format.
- Best tutoring assistance 24x7 hours