Keywords are predefined, reserved words used in Java programming that have special meanings to the compiler. For example:
int is a keyword. It indicates that the variable score is of integer type (32-bit signed two's complement integer).
You cannot use keywords like
class etc as variable name (or identifiers) as they are part of the Java programming language syntax. Here's the complete list of all keywords in Java programming.
Beside these keywords, you cannot also use
null as identifiers as they are literals.
Identifiers are the name given to variables, classes, methods etc. Consider the above code;
Here, score is a variable (an identifier). You cannot use keywords as variable name. It's because keywords have predefined meaning. For example,
The above code is wrong. It's because
float is a keyword and cannot be used as a variable name.
To learn more about variables, visit Java variables.
- Identifier cannot be a keyword.
- Identifiers are case-sensitive.
- It can have a sequence of letters and digits. However, it must begin with a letter,
_. The first letter of an identifier cannot be a digit.
- It's convention to start an identifier with a letter rather and
- Whitespaces are not allowed.
- Similarly, you cannot use symbols such as
#, and so on.
Here are some valid identifiers:
Here are some invalid identifiers:
- highest Score