Page 61 - iprime_V2.2_class8
P. 61

For example,

                        int age;
                        String name;
                        float temp;
                        double price;

                 Here, four variables named age, name, temp, and price are declared with the int, String, float, and
                 double data types, respectively.
                 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.

                                                                                               Program Coding      59
   56   57   58   59   60   61   62   63   64   65   66