Page 71 - Viva ICSE Computer Studies 8 : E-book
P. 71
Identifi ers
All Java components require names. Identifi ers are the names given to classes, methods and
variables. There are certain rules to be followed for naming identifi ers.
• All identifi ers must begin with a letter (A to Z or a to z), underscore (_) or dollar sign($).
After the fi rst characters, identifi ers can have any combination of characters.
• Identifi er name must not be a keyword.
• Identifi ers can be of any length and are case sensitive.
Keywords
Keywords are the words that have already been reserved for Java compiler. Java keywords
must be known because these words cannot be used as variable, class or method names.
Constants
Constants in Java are fi xed values that do not change during the execution of a program.
Constants are also called literals. A constant is a variable which cannot have its value changed
after declaration.
Integer Constants
An integer constant refers to a sequence of digits which includes only negative or positive
values. For example, 12 and 35 are integer constants.
Real Constants
A real constant refers to a sequence of digits which includes only negative or positive values.
However, it must have a decimal value. For example, 23.5 and 123.45 are real constants.
Single Character Constants
A single character constant is a single letter, a single digit or a single symbol that is enclosed
within single inverted commas. For example ‘S’ and ’1’ are single character constants.
String Constants
A string constant is a sequence of characters enclosed between double quotes. These characters
may be digits or letters. For example, “Hello” and “1234” are string constants.
Variables
Variables are the names given to a memory location which are used to save data temporarily
to be used later in the program. During execution of a program, values can be stored in a
variable, and the stored value can be changed. In Java programming, it is necessary to declare
the variable before being used.
For example: sum = a+b;
Here sum, a and b are variables.
59