Page 326 - CITS - Computer Software Application -TT
P. 326

COMPUTER SOFTWARE APPLICATION - CITS


           JAVA Input and Output streams(I/O)


           Java I/O, which stands for Input and Output, is a fundamental part of Java programming used for handling data
           input and producing output in various applications.
           Java leverages the concept of streams to optimise I/O operations, and the java.io package encompasses all the
           necessary classes for handling input and output tasks efficiently.
           File handling in Java can be achieved through the Java I/O API.
           Stream
           In Java, a stream is a sequence of elements that you can process in a functional and declarative manner. Java
           Streams were introduced in Java 8 and provide a powerful way to work with collections, arrays, and other data
           sources. Streams allow you to perform operations on the elements of a sequence, such as filtering, mapping, and
           reducing, without the need for explicit loops.
           In Java, three streams are automatically created for us, all of which are associated with the console:
           1   `System.in`: This represents the standard input stream, which serves the purpose of reading characters from
              the keyboard or any other standard input source.
           2   `System.out`:  This refers to the standard output stream, utilised  for displaying  the program’s results on
              an output device, such as the computer screen. Here is a list of various print functions used for outputting
              statements
           •  ‘print()’: In Java, this method is employed to exhibit text on the console. The text is supplied as a parameter
              in the form of a string. When invoked, this method displays the text on the console while keeping the cursor at
              the end of the printed text. Subsequent printing operations will begin from this point.
           Syntax:
           System.out.print(parameter);

           // Java code to illustrate print()
           import java.io.*;
           class Demo {
               public static void main(String[] args)

               {
                     // using print()
                   // all are printed in the
                   // same line
                   System.out.print(“CTI WORLD “);

                   System.out.print(“CTI WORLD “);
                   System.out.print(“CTI WORLD “);
               }
           }

           Output:


           CTI WORLD CTI WORLD CTI WORLD

           •  println(): In Java, this method serves the purpose of showcasing text on the console. It outputs the text to the
              console and positions the cursor at the beginning of the next line. Subsequent printing operations will begin
              from the next line







                                                           313
                               CITS : IT&ITES - Computer Software Application - Lesson 78 - 84





  78
   321   322   323   324   325   326   327   328   329   330   331