Page 96 - 2617_JSSPS_C-6
P. 96
Initialising a Variable
Intitialising means assigning a value to the variable at the time of declaration. We can initialise variables
in the following way:
int age = 30;
String name = "Nisha";
float temp = 35.7f;
double price = 625.50;
Here, variables age, name, temp, and price are initialised with the values 30, “Nisha”, 35.7, and 625.50,
respectively.
Hintbot
We can assign values to variables after declaration in the following way:
age = 30;
name = "Nisha";
temp = 35.7f;
price = 625.50;
Comments
A comment is a statement in a Java program that is not executed by the Java compiler. Generally,
comments are used to give additional information about the code for understanding the code better.
There are three techniques for adding comments to your Java programs, each of which has its own
particular usage. These techniques are as follows:
Single-Line Comments (//): Use the two forward slashes to comment out text that appears after the
forward slashes but on the same line.
Multi-Line Comments (/*...*/): Use the /* to turn on comments, and all text will be commented
until a */ is reached. This is useful for commenting out multiple lines of code.
Documentation Comments (/**...*/): A special type of comment used specifically with the javadoc
tool for generating HTML files that contain your comments. This feature of Java is widely used, and it
is expected that the HTML pages accompany any Java code that is distributed among developers.
For example,
public class comments{
public static void main(String[] args){
System.out.println("Comment Examples");
// This is a single line comment.
/* This is
multiline
comment*/
94 Premium Edition-VI

