In Java, keywords are special words that have a predefined meaning to the Java compiler. They are reserved words and cannot be used as an identifier, function names, or any other program elements, including classes, subclasses, variables, methods, and objects. Java contains 50 such keywords that are reserved for specific purposes in the Java language. Some of the keywords are abstract
, break
, implements
, float
, etc. Since they are reserved words that convey a special meaning to the Java compiler, they are highlighted with different colors in any IDE or editor to differentiate them from other words. Here is a list of all Java keywords:
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
It is important to note that the rules for the naming convention of variables clearly mention that a variable name should not be a keyword. If a keyword is used as a variable name, it would give a compile-time error in Java.