Page 138 - ComputerScience_Class_11
P. 138

Rules for Naming a Variable
              While naming a variable, certain rules must be followed. They are as follows:
              •  A variable name should start with a letter.
              •  A variable name may contain of letters, digits and underscores.
              •  The name should have a meaning related to the program.
              •  There should not be any space between the letters in the name of the variable.
              •  Variable names cannot be reserved words.


              6.1.4 Punctuators
              These are punctuation signs and are used in Java as special characters. They help in structuring and organising the
              program. Some of them are:
              •  Semicolon (;) is used for the termination of a statement. For example,

                     int a=5;
              •  Dot operator(.) is used to access methods and variables of an object or class. For example,
                     System.out.println(); or import java.util.*;

              6.1.5 Separators
              They are the special characters in Java, which are used to separate the variable or the character. Some of them are:
              •  Parentheses () are used to set the priority of a calculation by enclosing any part of an arithmetic, logical or relational
                 expression.
              •  Curly brackets {} are used to enclose code blocks.
              •  Square brackets [] are used to define and access elements in arrays.

              6.1.6 Operators
              Operators are the special symbols that instruct the compiler to perform some specific mathematical or non-mathematical
              operations on one or more operands. Java supports eight types of operators which are as follows:
              •  Arithmetic Operators: “+”, “-”, “*”, “/”
              •  Assignment Operators: “=”

              •  Logical Operators: “&&”, “||”, “!”
              •  Relational Operators: “==”, “<”, “>”, “<=”, “>=”, “!=”
              •  Unary Operators: “+”, “-”, “++”, “--”
              •  Bitwise Operators: “&”, “|”, “^”, “~”
              •  Ternary Operators: "?:"

              •  Shift Operators: (>>), (>>>), (<<)


                   6.2 ESCAPE SEQUENCE
              An escape sequence is a non-graphical character preceded by a backslash (\) having a special meaning for the
              compiler. It is a command from the keyboard. Some of the escape sequences used in Java are as follows:

                                       Escape Sequence                 Required for
                                             \t         Inserts a horizontal tab.
                                             \b         Inserts a backspace.
                                             \n         Inserts a new line.
                                             \r         Inserts a carriage return.




                  136  Touchpad Computer Science (Ver. 3.0)-XI
   133   134   135   136   137   138   139   140   141   142   143