Java Reference
In-Depth Information
Java provides many built-in primitive data types, such as int , float , boolean , char , etc. For example, the three
components that define the int primitive data type in Java are as follows:
An
int data type consists of a set of all integers between -2,147,483,648 and 2,147,483,647.
Operations such as addition, subtraction, multiplication, division, comparison, and many
more are defined for the int data type.
A value of the
int data type is represented in 32-bit memory in 2's compliment form.
All three components of the int data type are predefined by the Java language. Developers cannot extend or
redefine the definition of the int data type in Java. You can give a name to a value of the int data type as
int employeeId;
This statement states that employeeId is a name (technically called an identifier) that can be associated with one
value from the set of values that defines values for the int data type. For example, you can associate integer 1969 to
the name employeeId using an assignment statement like
employeeId = 1969;
What Is an Identifier?
An identifier in Java is a sequence of characters of unlimited length. The sequence of characters includes all Java
letters and Java digits, the first of which must be a Java letter. Java uses the Unicode character set. A Java letter is a
letter from any language that is represented by Unicode character set. For example, A-Z, a-z, _ (underscore), and $
are considered Java letters from the ASCII character set range of Unicode. Java digits include 0-9 ASCII digits and any
Unicode character that denotes a digit in a language. Spaces are not allowed in an identifier.
In fact, an identifier is a technical term for a name. Therefore, an identifier is simply the name given to a class,
method, variable, etc. in a Java program. The name, Welcome , of our Java class is an example of an identifier. The
names of variables num1 , num2 , and str1 used in our examples are also identifiers. All characters used in an identifier
are important, as is their case. The names welcome , Welcome , and WELCOME are three different identifiers. There are
three important things to remember about identifiers in Java:
There is no limit on the number of characters used in an identifier. An identifier can be as
small as one character long (for example, i , j , k) or as big as you want.
Characters used in an identifier are drawn from the Unicode character set, not only from the
ASCII character set.
Identifiers are case sensitive. For example,
num and Num are two different identifiers.
Examples of valid identifiers are as follows:
num1 // Can use a-z and 0-9 and start with a letter
kn // Only letters
_abc // Can start with an underscore
_ // Can have only one letter, which is an underscore
sum_of_two_numbers // Can have letters and underscores
Outer$Inner // Can have a-z, A-Z and $
$var // Can also start with $
 
Search WWH ::




Custom Search