Java keywords

Java keywords

Keywords are reserved words that have special meaning to the compiler. They cannot be used as a variable name or identifier. All the keywords are written in lowercase. There are 49 keywords in Java.

Here’s the list of all Java keywords with their respective uses:

KeywordsUse
abstractDeclares a class or method as abstract
assertDescribes a predicate (a true–false statement)
booleanDefines a variable of boolean data type
breakBreaking the control of program out of current loop
byteDefines a variable of byte data type
caseUsed in switch statement to mark blocks
catchCatches exceptions generated by try statements
charDefines a variable of char data type
classDeclares a new class
continueUsed to resume the control of program at the end of current loop
defaultSpecifies the default block of code in a switch statement
doDeclares do-while loop
doubleDeclares a double precision floating-point variable
elseAlternate case for an if statement
enumDeclares a predefined list of values
extendsIndicate that a class is derived from another class or interface
finalRestricts the user from changing the value of a final variable or overriding a final method
finallyIndicates the block of code that will always be executed
floatDeclares a floating-point variable
forDeclares for loop
ifExecutes code by checking a condition
implementsSpecifies that a class implements an interface
importSpecifies classes or interfaces for later use
instanceofIndicates if an object is an instance of a class or implements an interface
intDeclares an integer variable
interfaceDeclares an interface
longDeclares a long integer variable
nativeSpecifies that a method is implemented with native code
newCreates new objects
nullDoes not refer to anything
packageDeclares a Java package
privateDeclares private members of a class
protectedDeclares protected members of a class
publicDeclares public members of a class
returnReturns a value from a method
shortDeclares a short integer variable
staticCreates permanent storage for a variable
strictfpUsed to restrict the precision and rounding of floating point calculations
superUsed to refer parent class object
switchExecutes code for different values of a variable
synchronizedUsed to specify the critical sections or methods in multi-threaded code
thisRefers to the current object in a method or class
throwThrows an exception
throwsDeclares an exception
transientSpecifies that a variable is not part of serialization
tryExecutes a code that can throw an exception
voidDeclares functions or data with no associated data type
volatileWarns the compiler about variables that can be modified unexpectedly
whileDeclares while loop

So these were the Keywords and their uses in Java. We hope the concept was clear to you. For daily updates and more such content do follow us on Instagram.

Keep programming!

ErrorFreeProgram.

2 COMMENTS

comments user
Fitness Wellness

I do agree with all the ideas you’ve presented in your post. They’re really convincing and will certainly work. Still, the posts are too short for novices. Could you please extend them a bit from next time? Thanks for the post.

Leave a Reply

Your email address will not be published. Required fields are marked *