Page 63 - TP_iPlus_V2.1_Class8
P. 63

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.
                    Quick Byte

                     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*/

                     /** These types of comments are used when you want to add HTML code
                     into your Java program*/
                     }
                 }
                 When you run the preceding code, only the message "Comment Examples" will appear on the
                 terminal. All the comments are ignored by the compiler.


                                                                                                                  61
                                                                                               Program Coding
   58   59   60   61   62   63   64   65   66   67   68