All keywords in Java
Keywords are special words in the programing language which have reserved use in the language. Keywords may not be used as identifiers in Java; for example you cannot declare a field whose name is a keyword.
There are different types of keywords:
primitive types like
control flow statement like
special words which mark the declaration and definition of Java classes, packages, and interfaces like
literal values like
false. These are not actually considered as keywords, and can not be used to create identifiers.
Below are all the Java language keywords:
Bellow is a brief description for each keyword and links to more in dept details.
abstract keyword is used to declare an abstract class or an abstract method. An abstract class it can have abstract and
non-abstract methods. Read more...
assert is a keyword used to define an assert statement. An assert statement is used to declare an expected boolean condition in a
boolean keyword is used to declare a variable as a boolean type. It can hold
false values only.
break keyword is used to break a loop or a switch statement. The execution of the code jumps at the first instructions after the current
byte keyword is used to declare a variable that can hold an 8-bit data values.
case keyword is used with the
switch statements to mark blocks of code.
catch keyword is used to catch the exceptions generated by try statements. It can be used after the
try block only.
char keyword is used to declare a variable that can hold unsigned 16-bit Unicode characters.
class keyword is used to declare a class.
continue keyword is used to continue the loop. It continues the current flow of the program and skips the remaining
code from the loop, and it continues with the next iteration.
default keyword is used to specify the default block of code in a switch statement.
do keyword is used to declare a loop. It is used to iterate a part of the program until the condition is met. It can be used when
there is not a fix number of iterations.
double keyword is used to declare a variable that can hold a 64-bit floating-point numbers.
else keyword is used to indicate the alternative branches in an
enum keyword is used to define a fixed set of constants. Enum constructors are always private or default. It was introduced with
since Java 5.0.
extends keyword is used to indicate that a
class is derived from another
final keyword is used to indicate that a variable holds a constant value. If it is used for a
class it cannot be subclassed.
final keyword it is in a
method declaration this will indicate that the method cannot be overridden by subclasses.
finally keyword indicates a block of code in a try-catch structure. The finally block is always executed whether an exception is handled
or not. This is useful usually to clean up resources.
float keyword is used to declare a variable that can hold a 32-bit floating-point number.
for keyword is used to start a for loop. It is used to execute a section of code repeatedly as long the condition is true.
for loop it is recomanded when there is a fix number of iteration.
if keyword tests the condition. It executes the
if block if condition is true.
implements keyword is used when a
class is implementing an interface.
import keyword makes classes and interfaces available and accessible to the current source code file.
instanceof keyword is used to test whether the object is an instance of the specified class or implements an
int keyword is used to declare a variable that can hold a 32-bit signed integer.
interface keyword is used to declare an interface.
long keyword is used to declare a variable that can hold a 64-bit integer.
native keyword is used to specify that a method is implemented in a different programing language, and it is accessed
using JNI (Java Native Interface).
new keyword is used to create new objects.
package keyword is used to declare a Java package that includes the classes. The pachages will also match the folder structure.
private keyword is an access modifier. It is used to indicate that a class, method or variable may be accessed only in the
class in which it is declared.
protected keyword is an access modifier. A class, method or variable declared as protected, it can be accessible within the
package and outside the package but through inheritance only.
public keyword is an access modifier. It is used to indicate that a class, method or variable is accessible to any package.
return keyword is used to return from a method either with a value or not.
short keyword is used to declare a variable that can hold a 16-bit integer.
static keyword is used to indicate that a variable or method is a class method, this means that the variable or the method is
identical for all the instantiated objects of that class. Any changes done by an object will be available to all the other objects of that type.
strictfp is used to restrict the floating-point calculations to ensure portability.
super keyword is a reference variable that is used to refer parent class variable or method. In a long chain of inheritance
super can be used to invoke immediate parent class method.
switch keyword is used to tests the equality of a variable against multiple values.
synchronized keyword is used to specify the critical sections or methods in multithreaded code that can be executed only by one
thread a the time.
this keyword can be used to refer the current object members in a method or constructor.
throw keyword is used to explicitly throw an exception.
throws keyword is used to declare an method with an exception.
transient keyword is used in the context of serialization. A variable that is defined as transient, it will not be serialized.
try keyword is used to start a block of code that might throw an exception. The try block must be followed by either
void keyword is used to specify that a method does not have a return value.
volatile keyword is used to indicate that a variable may change asynchronously.
while keyword is used to start a while loop. The while loop iterates a part of the code as long as the condition is met.
The while loop is useful when the number of iteration is not fixed.