Page 156 - Computer science 868 Class 12
P. 156
3. Character Literals: They are any character enclosed in single quotation marks (‘ ’). They may be letters, number,
symbols, etc.
For example: ‘A’, ‘1’, ‘+’, ‘.’, etc.
There are further four different types of character literals that can be used in Java which are listed below:
• Single quote: ‘C’;
• Char literal as Integral literal: 062; // It doesn’t take single quotation marks
• Unicode representation: ‘\u0061’; // Here \u0061 represents character ‘a’
• Escape sequence: ‘\n’;
4. String Literals: A sequence of characters (including letters, digits and symbols) enclosed in double quotation marks
(" ") is called a string literal.
For example: "Orange Education", "Computer Science", "12th standard", etc.
5. Boolean Literals: Boolean literals represent only two values. Sometimes, the logic of the program requires the
result in either of the two values. For example, whether he is a good player or not. If he is a good player, then the
variable will contain true else will contain false. So, this type of literal can hold only two values, i.e., true and false.
One cannot do any other function with this type of variable.
For example: boolean a = true;
6. Null Literals: It is a special Java literal that represents a null value. It cannot be assigned to a primitive type such as
int, float, etc. However, it can be used to initialise an object or a reference variable.
For example: String s = null;
6.3 IDENTIFIERS
While coding, a programmer needs to have some containers which will be used to assign some values that may
be required to get the desired results. They are the names that are used to identify the variables in Java. Apart
from containing values, an identifier can also be used as the name of the class, method, array, etc. However, while
declaring identifiers, they must meet a condition that they should not resemble any reserved words or keywords
in Java. Even if it happens, then there should be at least one different character in the identifier to differentiate it
from the keyword.
While naming an identifier, we must keep in mind the following points:
• It may contain any number of characters.
• It should not begin with a digit or a symbol.
• It may contain letters, digits and an underscore.
• It should not be a keyword.
• It should not contain two words which means space is not allowed in the variable or class name.
For example:
• Valid identifiers: b, sum, fact_num, emp_code12, etc.
• Invalid identifiers: 1b, sum+, fact num, emp-code, etc.
Identifiers are used to name the variables. Let us learn about variables.
6.3.1 Variables
Variables are the named memory locations that contain values depending on the type of the variable. The value
of the variable can be changed as required by the program. A variable name can have any combination of letters
without space.
154154 Touchpad Computer Science-XII

