Chapter 1. Declarations, Initialization and Scoping
(Part-3)
Develop code that declares, initializes, and uses primitives, arrays, enums, and objects as static, instance, and local variables. Also, use legal identifiers for variable names.
Develop code that declares, initializes, and uses primitives, arrays, enums, and objects as static, instance, and local variables. Also, use legal identifiers for variable names.
Variable Identifiers
Variable names must be legal Java identifiers:
- Keywords and reserved words may not be used.
.
- It must start with a letter, dollar sign ($), or underscore (_).
.
- Subsequent characters may be letters, dollar signs, underscores, or digits.
.
- It is case sensitive. For example, mymodel and MyModel are different identifiers.
The following are not legal variable names:
.
My Variable // Contains a space
.
9pins // Begins with a digit
.
a+c // The plus sign is not an alphanumeric character
.
testing1-2-3 // The hyphen is not an alphanumeric character
.
O'Reilly // Apostrophe is not an alphanumeric character
.
OReilly_&_Associates // ampersand is not an alphanumeric character
|
Keywords: abstract assert boolean break byte case catch char class const continue default do double else enum extends false final finally float for goto if implements import instanceof int interface long native new null package private protected public return short static strictfp super switch synchronized this throw throws transient true try void volatile while
.
The goto keyword is not used.
.
The const is also not used.
.
The assert is a new keyword added with Java 1.4
.
The enum is a new keyword added with Java 5.0
______________
Author: Mikalai Zaikin. Please Click Here to visit Authors site for any updates and changes to the study notes.
Trackback(0)
|