Page 60 - Trackpad_ipro 4.1_Class8
P. 60

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, 30, “Nisha”, 35.7f, and 625.50 are the values assigned to the variables age, name, temp, and
                  price, respectively.

                   Tech


                     Funda
                                   We can also 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 it better.

                  There are three techniques of adding comments to Java programs, each of which has its own
                  particular usage. These techniques are as follows:
                      Single-Line Comments (//): Use two forward slashes to comment out text that appears after
                     the slashes on the same line.
                      Multi-Line Comments (/*...*/): Use /* 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 (/**...*/): This is 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 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



                    58     iPro (Ver. 4.1)-VIII
   55   56   57   58   59   60   61   62   63   64   65