Is the following declaration correct?
int answer;
Yes—assuming that answer
is a correct name for
a variable.
The programmer (you) picks a name for each variable in a program. There are several things in programs (including variables) that need to be named. Such a programmer-picked name is called an identifier. Here are the rules for choosing an identifier:
SUM
and Sum
are different names.
A reserved word is a word which has a predefined meaning in Java.
For example int
, double
, true
,
and import
are
reserved words.
Rather than worry about the complete list of reserved words, just remember to
avoid using words that you know already mean something,
and be prepared to make a change if you accidentally use one you didn't know.