Java Reference
In-Depth Information
Examples of invalid identifiers are as follows:
2num // Cannot start with a number
my name // Cannot have a space
num1+num2 // Cannot have + sign
num1-num2 // Cannot have hyphen or minus sign
Java defines a list of words called keywords. Keywords are words that have predefined meanings in Java and they can
only be used in the contexts defined by the Java language. Keywords in Java cannot be used as identifiers. The complete
list of Java keywords is listed in Table 3-1 .
Table 3-1. List of Keywords and Reserved Words in Java
abstract
continue
for
new
switch
assert
default
goto
package
synchronized
boolean
do
if
private
this
break
double
implements
protected
throw
byte
else
import
public
throws
case
enum
instanceof
return
transient
catch
extends
int
short
try
char
final
interface
static
void
class
finally
long
strictfp
volatile
const
float
native
super
while
The two keywords, const and goto , are not currently used in Java. They are reserved keywords and they cannot
be used as identifiers.
In addition to all the keywords, three words, true , false , and null , cannot be used as identifiers; true and false
are boolean literals (or boolean constants) and null is a reference literal.
Data Types in Java
Before we start discussing all data types available in Java, let's take a simple example of adding two numbers. Suppose
your friend asks you to add two numbers. The procedure to add two numbers goes as follows.
1.
Your friend tells you the first number. You listen to him and your brain records the number
at a particular location in your memory. Of course, you do not know where the number is
exactly stored in your brain's memory.
2.
Your friend tells you the second number, you listen to him, and again, your brain records it
at a particular location in your memory.
3.
Now, your friend asks you to add the two numbers. Your brain comes into action again.
It recalls (or reads) the two numbers, adds them, and you tell your friend the sum of the
two numbers.
 
Search WWH ::




Custom Search