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.
abstract | continue | for | new | switch |
assert | default | goto | package | synchronized |
boolean | do | if | private | this |
break | double | implements | protected | throw |
byte | else | import | public | throws |
case | enum | instanceof | return | transient |
catch | extends | int | short | try |
char | final | interface | static | void |
class | finally | long | strictfp | volatile |
const | float | native | super | while |
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