Page 80 - CA_Blue( J )_Class10
P. 80

05


                                                                            INPUT IN JAVA

















                        Learning Objectives


                   5.1 Introducing Packages            5.2 Initialization            5.3 Using Parameters
                   5.4 Using Scanner Class             5.5 Using InputStreamReader Class
                   5.6 Errors in Java                  5.7 Exception                 5.8 Comments in Java






              A computer works on IPO (Input-Process-Output) cycle. It takes input from the user through an input device like a
              keyboard. After taking the input, it processes the input using the CPU (Central Processing Unit) and then displays the
              result on the output device, like a monitor.

              Apart from IPO, there exists a feature called store which is used to save the data before and after processing. The data
              is stored in the storage devices attached to the computer, like a hard disk.

              Similarly, a Java program needs input to work. There are mainly three ways to provide input for a Java program.These
              are:
              •  Initialization,
              •  Using parameters
              •  Using methods of Scanner and InputStreamReader classes
              Before learning about these ways, let us first learn about packages in Java.


                   5.1 INTRODUCING PACKAGES
              A package is a collection of Java classes and other packages having similar functionality. In other
              words, a package is similar to a folder in a computer where we can store similar types of files and
              folders. In the same way, a package in Java can store similar types of Java classes and packages. The
              package inside another package is known as a sub-package.
              Each class within a package can use the public properties and behaviours of other classes. This saves your time and
              effort, and makes the programming efficient. A package is also helpful in resolving the issue of name confliction when
              a class has the same name as any predefined Java class. For example, if you have defined a class named Date, then
              the Java compiler will show an error message that the Data class is already defined in the Java class library. But if you
              place your Date class in a package, then the Java compiler will not conflict with the name as your class is accessed by
              using the package name.



                7878  Touchpad Computer Applications-X
   75   76   77   78   79   80   81   82   83   84   85