Java keywords are reserved words that are predefined, while java identifiers are used for identification purposes. Learn more about Java Keywords and Identifiers in this module. Before diving into keywords and identifiers tutorials, you should know Data Types in Java.
Table of Contents
[hide]Java Keywords are the set of predefined words that are provided by Java Programming Langauge . They are also called "reserved words" which are case-sensitive.
These reserved words cannot be used as a variable name, class name or an method name. In Java there are 50 such keywords given in the below table.
abstract | assert | boolean | break | byte |
case | catch | char | class | const |
continue | default | do | double | else |
enum | extends | final | finally | float |
for | goto | if | implements | import |
instanceof | int | interface | long | native |
new | package | private | protected | public |
return | short | static | strictfp | super |
switch | synchronized | this | throw | throws |
transient | try | void | volatile | while |
In the above table keyword goto and const are never used though they are reserved. You can't use true , false and null as identifiers besides these keywords as well. The explanation is, they are literals
int age = 32; // "age" is an identifier here, while "int" is a reserved word.
java Identifier is any name, it can be a variable name, method name, class name or interface name. In the above example variable name age is also know as identifier. If you want to learn more about variables then refer to Java variables.
// Java program to illustrate identifiers in Java
public class IdentifyExample{
public static void main(String args[]){
int value = 10;
}
}
In the above example there are five identifiers namely :
There are some rules which we have to follow before defining Java Identifier. If these rules are not followed then we get compile time error. Rules for defining Java identifiers are :-