1.7 Java Keywords
In Java, keywords are reserved words that have a predefined meaning in the language. These keywords cannot be used as identifiers (names for variables, classes, methods, etc.). Java 8 introduced new keywords along with existing ones that form the foundation of the language.
Java Keywords Table
Below is a table listing all the important keywords in Java, along with a brief description of each:
| Keyword | Description |
|---|---|
abstract | Declares an abstract class or method. |
assert | Used for debugging purposes to make an assertion. |
boolean | Declares a variable as a boolean (true/false). |
break | Exits a loop or switch statement prematurely. |
byte | Declares a variable as an 8-bit integer. |
case | Defines a branch in a switch statement. |
catch | Handles exceptions thrown by the try block. |
char | Declares a variable as a character. |
class | Declares a class. |
const | Not used, reserved for future use. |
continue | Skips the current iteration of a loop and proceeds to the next one. |
default | Defines the default block in a switch statement or a default method in an interface (Java 8). |
do | Defines a block of code to be executed once before condition checking. |
double | Declares a variable as a double-precision floating-point number. |
else | Specifies a block of code to execute if the if condition is false. |
enum | Declares an enumeration, which is a fixed set of constants. |
extends | Indicates that a class inherits from a superclass. |
final | Prevents a class from being subclassed, a method from being overridden, or a variable from being modified. |
finally | Executes a block of code after a try-catch block, regardless of the outcome. |
float | Declares a variable as a floating-point number. |
for | Declares a loop that repeats a block of code a set number of times. |
goto | Not used, reserved for future use. |
if | Executes a block of code if a condition is true. |
implements | Indicates that a class implements an interface. |
import | Imports other Java packages or classes into your code. |
instanceof | Tests whether an object is an instance of a particular class or interface. |
int | Declares a variable as an integer. |
interface | Declares an interface, a reference type in Java. |
long | Declares a variable as a 64-bit integer. |
native | Specifies that a method is implemented in native code using JNI. |
new | Creates new objects. |
null | Represents the null value, indicating no object. |
package | Defines a namespace for a group of related classes. |
private | Restricts access to the class, method, or variable within its own class. |
protected | Restricts access to the class, method, or variable within its own package and subclasses. |
public | Allows the class, method, or variable to be accessed from any other class. |
return | Exits from a method and optionally returns a value. |
short | Declares a variable as a 16-bit integer. |
static | Belongs to the class rather than instances of the class. |
strictfp | Used to restrict floating-point calculations to ensure portability. |
super | Refers to the parent class or constructor. |
switch | Selects one of many code blocks to execute. |
synchronized | Controls access to a method or block of code by multiple threads. |
this | Refers to the current instance of a class. |
throw | Throws an exception. |
throws | Declares that a method may throw exceptions. |
transient | Prevents serialization of a field. |
try | Defines a block of code to test for exceptions. |
void | Specifies that a method does not return any value. |
volatile | Indicates that a variable's value may be changed by different threads. |
while | Defines a loop that repeats a block of code as long as a condition is true. |
Conclusion
Understanding Java keywords is crucial for mastering the language, as they define the structure and flow of your programs. Java 8 brought powerful new features, but the core keywords remained the same, allowing developers to write expressive and modern Java code.