Page 106 - computer science (868) class 11
P. 106

We know that a variable is a named memory location where a value is being stored. The name of the variable contains
              any combination of letters without any space.
              But we should remember that it must not start with any digit. If the name is a combination of two or more words, then
              we can use an underscore (_) to separate the words.
              For example:

                 int a = 5; double sum_of_numbers = 40.5;
              5.1.2 Literals
              The values that are stored in the variables are known as literals. These values can be of any data type.

                 int a = 10;
                 double d = 11.55;
                 String s = "India is a country";
              Types of Literals
              There are six different types of literals. They are integer literals, floating-point literals, character literals, string literals,
              Boolean literals, and null literals. Let us learn about them in detail.
              •   Integer Literals: Integer Literals are the whole numbers of any length. They may be positive, negative or zero. For
                 example, 78, +456, -765, etc.
              •   Floating-point Literals: Floating-point Literals are the fractional numbers. They are also called real literals. They may
                 be positive or negative. For example, 2.65, 985.94, -5.68 etc.
              •   Character Literals: Character literals are the alphabets, numbers or symbols enclosed in single quotes. For example,
                 ‘B’, ‘^’, ‘5’, etc.
              •   String Literals: String literals are a sequence of a set of characters that are enclosed in double quotations. For
                 example, “India”, “Kolkata 700115”, “I am an Indian”, etc.
              •   Boolean Literals: Boolean Literals contain two values only: true or false.
              •   Null Literals: Null literals represent the null value in a string variable when we need to initialise it. The default value
                 is ‘null’.

              5.1.3 Assignment
              Assigning a value to a variable using the symbol “=” is known as an assignment. This “=” is an assignment operator. The
              default value is ‘no 11’.
                 int a = 5;          // here 5 is assigned to the variable a
                 double b = 6.7;  // here 6.7 is assigned to the variable b

              Initialisation
              Initialisation is the assignment of a value to a variable at the time of declaration.

              Types of Initialisation
              There are two types of initialisations. They are static initialisation and dynamic Initialisation. Actually, as soon as a variable
              is declared, it contains a garbage values. This garbage value has to be removed, as it may lead us to a wrong result.

              •  Static Initialisation: When a constant is directly assigned to a variable, it is known as Static Initialisation. For example,
                     int a=6;
                     String n="Name";
              •  Dynamic Initialisation: When a variable is initialised during the execution/run time of the program, it is known as
                 Dynamic Initialisation. For example,
                     int a=5, b=6, c;           // Known as Static Initialisation
                     c=a+b;                     // Known as Dynamic Initialisation
                     System.out.println(c);


                104104  Touchpad Computer Science-XI
   101   102   103   104   105   106   107   108   109   110   111