Page 60 - iPro_trackGPT_V5_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 = “Amrita”;
                         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.

                          Tech Tweak

                    We can also assign values to variables after declaration in the following way:
                           age = 30;

                           name = “Amrita”;
                           temp = 35.7f;

                           price = 625.50;

                  Comments

                  A comment in a Java program is a piece of text that the Java compiler ignores. Comments are
                  essential for adding extra information about the code, making it easier for others (and yourself)
                  to understand and maintain.
                  There are three ways to add comments in Java:
                     Single-Line Comments (//): Use two forward slashes (//) to start a comment. The compiler
                     will treat everything after // on that line as a comment and ignore it.

                     Multi-Line Comments (/*...*/): Use /* to start and */ to end a multi-line comment. This is
                     useful when you want to comment out multiple lines of code.
                     Documentation Comments (/**...*/): These are special comments used with the javadoc
                     tool to generate HTML documentation. They are commonly placed before classes, methods,
                     or fields to provide detailed documentation.
                  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*/
                      }
                  }


                    58    TrackGPT iPRO (V5.0)-VIII
   55   56   57   58   59   60   61   62   63   64   65