All keywords in Java
keywords
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
intorboolean -
control flow statement like
fororif -
access modifiers:
publicorprivate -
special words which mark the declaration and definition of Java classes, packages, and interfaces like
classorpackageorinterface. -
literal values like
null,trueandfalse. These are not actually considered as keywords, and can not be used to create identifiers.
Below are all the Java language keywords:
Keywords Description
Bellow is a brief description for each keyword and links to more in dept details.
abstract
The Java 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
The Java assert is a keyword used to define an assert statement. An assert statement is used to declare an expected boolean condition in a
program.
boolean
The Java boolean keyword is used to declare a variable as a boolean type. It can hold true and false values only.
break
Java 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
statement.
byte
Java byte keyword is used to declare a variable that can hold an 8-bit data values.
case
Java case keyword is used with the switch statements to mark blocks of code.
catch
The Java catch keyword is used to catch the exceptions generated by try statements. It can be used after the try block only.
char
The Java char keyword is used to declare a variable that can hold unsigned 16-bit Unicode characters.
class
The Java class keyword is used to declare a class.
continue
The Java 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
The Java default keyword is used to specify the default block of code in a switch statement.
do
The Java 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
The Java double keyword is used to declare a variable that can hold a 64-bit floating-point numbers.
else
The Java else keyword is used to indicate the alternative branches in an if statement.
enum
The Java 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
The Java extends keyword is used to indicate that a class is derived from another class.
final
The Java final keyword is used to indicate that a variable holds a constant value. If it is used for a class it cannot be subclassed.
If the final keyword it is in a method declaration this will indicate that the method cannot be overridden by subclasses.
finally
The Java 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
The Java float keyword is used to declare a variable that can hold a 32-bit floating-point number.
for
The Java 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.
The for loop it is recomanded when there is a fix number of iteration.
if
The Java if keyword tests the condition. It executes the if block if condition is true.
implements
The Java implements keyword is used when a class is implementing an interface.
import
The Java import keyword makes classes and interfaces available and accessible to the current source code file.
instanceof
The Java instanceof keyword is used to test whether the object is an instance of the specified class or implements an
specific interface.
int
The Java int keyword is used to declare a variable that can hold a 32-bit signed integer.
interface
The Java interface keyword is used to declare an interface.
long
The Java long keyword is used to declare a variable that can hold a 64-bit integer.
native
The Java 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
The Java new keyword is used to create new objects.
package
The Java package keyword is used to declare a Java package that includes the classes. The pachages will also match the folder structure.
private
The Java 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
The Java 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
The Java public keyword is an access modifier. It is used to indicate that a class, method or variable is accessible to any package.
return
The Java return keyword is used to return from a method either with a value or not.
short
The Java short keyword is used to declare a variable that can hold a 16-bit integer.
static
The Java 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
The Java strictfp is used to restrict the floating-point calculations to ensure portability.
super
The Java 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
The Java switch keyword is used to tests the equality of a variable against multiple values.
synchronized
The Java 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
The Java this keyword can be used to refer the current object members in a method or constructor.
throw
The Java throw keyword is used to explicitly throw an exception.
throws
The Java throws keyword is used to declare an method with an exception.
transient
The Java transient keyword is used in the context of serialization. A variable that is defined as transient, it will not be serialized.
try
The Java try keyword is used to start a block of code that might throw an exception. The try block must be followed by either catch or
finally block.
void
The Java void keyword is used to specify that a method does not have a return value.
volatile
The Java volatile keyword is used to indicate that a variable may change asynchronously.
while
The Java 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.