Page 121 - CA_Blue( J )_Class9
P. 121
06
INPUT IN JAVA
Learning Objectives
6.1 Comments in Java 6.2 Packages in Java
6.3 Initialisation 6.4 Input using Parameters
6.5 Using Scanner Class 6.6 Using InputStreamReader Class
6.7 Errors in Java 6.8 Testing and Debugging
6.9 Exception Handling in Java
So far you have learnt about programming in Java with simple examples. In this chapter, we are going to learn
about the input and exception handling in Java.
6.1 COMMENTS IN JAVA
While writing a program code, we might need to explain certain parts of the program. This helps us to understand
the reason for writing the statements. This can be done with the help of comments. Comments are non-executable
statements that are required to explain certain parts of the program or add notes to some parts of the program.
This also helps a new programmer to debug any error easily.
In Java, there are three types of comments: single-line comments, multi-line comments and documentation
comments. Let us learn about them in detail.
6.1.1 Single-line Comments
These comments are used to write one-line comments. It may be written in a new line or after the end of the
statement, i.e., after the semicolon (“;”). A single-line comment begins with “//” (double forward slash). For example,
//The below statement prints My book name is Touchpad
System.out.println(“My book name is Touchpad”);
6.1.2 Multiline Comments
These comments are used to write more than one line or multiple lines so that the logic of the code can be
explained in detail. They begin with “/*” and end with “*/”.
/*This program code prints whether the numbers 5 and 2 are equal or not. If they are
equal, it will print Equal; otherwise, it will print Not Equal.*./
Input in Java 119

