Java Keywords
Keywords in Java are reserved words that have predefined meanings in the language and cannot be used as identifiers for variables, classes, methods, or any other entities.
Key Topics
1. List of Java Keywords
Below is the complete list of Java keywords:
Keyword | Description |
---|---|
abstract | Specifies that a class or method is abstract |
assert | Used for debugging purposes |
boolean | Primitive data type for true/false values |
break | Exits a loop or switch |
byte | Primitive data type for 8-bit integers |
case | A case in a switch statement |
catch | Catches exceptions generated by try statements |
char | Primitive data type for 16-bit Unicode characters |
class | Defines a class |
const | Reserved but not used |
continue | Skips the current iteration of a loop |
default | Default case in a switch statement |
do | Starts a do-while loop |
double | Primitive data type for double-precision 64-bit floating point |
else | Alternative path in an if statement |
enum | Defines an enumerated type |
extends | Indicates that a class is derived from another class |
final | Defines an entity that cannot be changed or inherited |
finally | Block of code that always executes after try/catch |
float | Primitive data type for single-precision 32-bit floating point |
for | Starts a for loop |
goto | Reserved but not used |
if | Starts a conditional statement |
implements | Indicates that a class implements an interface |
import | Includes classes and interfaces from other packages |
instanceof | Tests whether an object is an instance of a class |
int | Primitive data type for 32-bit integers |
interface | Defines an interface |
long | Primitive data type for 64-bit integers |
native | Indicates that a method is implemented in native code |
new | Creates new objects |
null | Represents a null reference |
package | Declares a Java package |
private | Access modifier for private access |
protected | Access modifier for protected access |
public | Access modifier for public access |
return | Exits from a method, optionally returning a value |
short | Primitive data type for 16-bit integers |
static | Indicates that a variable or method is static |
strictfp | Restricts floating-point calculations to ensure portability |
super | Refers to superclass objects |
switch | Starts a switch statement |
synchronized | Indicates that a method or block is synchronized |
this | Refers to the current object |
throw | Throws an exception |
throws | Declares exceptions that a method might throw |
transient | Indicates that a field is not part of the serialization |
try | Starts a block of code that might throw an exception |
void | Indicates that a method does not return any value |
volatile | Indicates that a variable may be modified asynchronously |
while | Starts a while loop |
Key Takeaways
- Java has a set of reserved keywords that have special meanings.
- These keywords cannot be used as identifiers in your code.
- Understanding these keywords is essential for reading and writing Java programs.