Keywords and Reserved Words in Java

In Java, Keywords are the words that are used by the Java for internal use. Let’s say we declare a variable:

int id = 1234;

Java will allocate 4 bytes of memory to the variable id. This is because int is already recognized by Java and it knows what to do when a developer uses int word and also knows how much memory to allocate for its variable like id. If the word int was not already recognized by Java then it would have done nothing.

Let’s take another example:

for(int a=1; a<=5; a++){
    System.out.println(a);
}

Java knows to execute print statement 5 times because it already knows what to do when developer defines the for word.

Hence, the keywords are the predefined words in Java that has internal functionality and Java does internal processing based on these keywords.

Following are the list of keywords in Java.

abstractcontinuefornewswitch
assertdefaultgotopackagesynchronized
booleandoifprivatethis
breakdoubleimplementsprotectedthrow
byteelseimportpublicthrows
caseenuminstanceofreturntransient
catchextendsintshorttry
charfinalinterfacestaticvoid
classfinallylongstrictfpvolatile
constfloatnativesuperwhile

The following keywords are not used by Java yet but is reserved and we can’t use them as identifier in our program.

  • const
  • goto
  • strictfp

There are three literals in Java Keywords and these are:

  • true
  • false
  • null

Reference: Java Language Keywords

Leave a Reply

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x