Reserved Words in Java
Reserved words are those words that a programmer cannot use for identifier name because that has been reserved by the language to perform different operations.
Reserved words consist of:
- Used keywords : 48 keywords currently in use.
- Unused keywods : 2 keywords(const, goto) not currently in use in the language.
- Some literals : 3 literal values(true, false, null).
The exhaustive list of keywords in Java programming language is:
- abstract : Used to implement an abstraction. Like classes and methods that can be implemented later.
- assert : It is used to place a predicate that the programmar thinks is true at that position in the program. If the assertion evaluates to false, the execution aborts.
- boolean : A data type that can be either true or false.
- break : A control statement to break out of the loop.
- byte : A data type which is 8-bit wide.
- case : Used inside switch statement to mark a code block.
- catch : Used to catch specific type of exceptions thrown by try statements.
- char : A 16-bit wide data-type to hold unsigned characters.
- class : Used to provide definition for new type of objects.
- continue : A control statement that sends the control to the end of a loop body.
- default : An optional statement that defines a default block of code inside switch statement.
- do : Used to signify the beginning of a do-while loop.
- double : A 64-bit wide data type to hold double precision signed floating-point numbers.
- else : Used to define alternative code block if the condition inside if-statement fails.
- enum : Used to declare enumerated type.
- extends : Used to specify the superclass for a class.
- final : A final class cannot be inherited, a final method cannot be overridden and a final variable cannot be re-assigned a value.
- finally : Defines a block of code after try-catch which is always executed.
- float : A 32-bit wide data type to hold single precision signed floating point numbers.
- for : Used to create a for loop.
- if : Used to define a code block which is executed if some condition is true.
- implements : Used to specify one or more interfaces that a class implements.
- import : Used to denote the packages and classes that have to be brought to the current scope.
- instanceof : Used to test if an object is an instance of a class or implements an interface.
- int : A 32-bit wide data type to hold signed integers.
- interface : Used to define a code block containing methods which will be implemented later.
- long : A 64-bit wide data type to hold signed integers.
- native : Used to specify that a method is not implemented in Java language but some other language like C, C++.
- new : Used to create objects of a class or to create new arrays.
- package : Used to create a package which is a collection of similar classes and interfaces.
- private : An access modifier. A private member of a class is visible only inside the class.
- protected : An access modifier. A protected member of a class is accessible in current package and subclasses outside the package.
- public : An access modifier. A public member is accessible from anywhere.
- return : Used to return some value from a method or to terminate the execution of a method.
- short : A 16-bit wide data type to hold signed integers.
- static : Used to declare static variables, static methods or static nested classes.
- strictfp : Used to restrict the precision and rounding of floating point operations to improve portability.
- super : Used to refer members of a superclass or to call its constructors.
- switch : Used to define a multiway branch statement.
- synchronized : Used to acquire mutex lock in a multithreaded program.
- this : During class design, it is used to refer current object of a class or to call the constructor of the current class.
- throw : Used to throw an exception.
- throws : Used to denote which exceptions might be thrown by a method.
- transient : Used to mark that an instance variable is not a part of the persistent state of an object.
- try : Used to define a block of code that will be tested for exceptions.
- void : Used to denote that a method returns nothing.
- volatile : Used to denote that a variable may change asynchronously.
- while : Used to define the while loop.
Unused Keywords
- const : A reserved keyword but not currently in use by the Java programming language.
- goto : A reserved keyword but not currently in use by the Java programming language.
Reserved words for literals
Although they may appear like keywords, they are literals actually.
- true : A boolean literal value used in affirmative sense.
- false : A boolean literal value used in negative sense.
- null : A reference literal value used to denote that a reference variable refers nothing.