java Keyword And Its Uses
Java contains 51 keywords.
Keywords are :
Keyword | Description |
---|---|
abstract | Used to declare a class or method as abstract, meaning it must be implemented by a subclass or overridden. |
assert | Used to check assumptions about the code, and throws an AssertionError if the condition is false. |
boolean | A data type that can only have two values: true or false. |
break | Used to exit a loop or switch statement. |
byte | A data type that can store whole numbers from -128 to 127. |
case | Used in a switch statement to specify different code blocks to be executed based on different values of a variable. |
catch | Used in a try-catch block to handle exceptions that are thrown in the try block. |
char | A data type that can store a single character or symbol. |
class | Used to define a new class. |
const | Previously used to define a constant, but is now deprecated and not used in modern Java. |
continue | Used to skip the current iteration of a loop and continue with the next iteration. |
default | Used in a switch statement to specify the default code block to be executed if no other case matches. |
do | Used to start a do-while loop, which executes a block of code at least once and then repeats as long as a specified condition is true. |
double | A data type that can store decimal numbers with greater precision than the float data type. |
else | Used to specify a block of code to be executed if a certain condition is false. |
enum | Used to define a new enumeration, which is a list of named values. |
extends | Used to create a subclass that inherits fields and methods from a superclass. |
final | Used to specify that a variable or method cannot be changed or overridden. |
finally | Used in a try-catch block |
float | A data type that can store decimal numbers with less precision than the double data type. |
for | Used to create a for loop, which executes a block of code a certain number of times. |
goto | Previously used to jump to a specific point in the code, but is now deprecated and not used in modern Java. |
if | Used to specify a block of code to be executed if a certain condition is true. |
implements | Used to indicate that a class is implementing an interface. |
import | Used to import a package or class into the current code file. |
instanceof | Used to check if an object is an instance of a certain class or interface. |
int | A data type that can store whole numbers from -2147483648 to 2147483647. |
interface | Used to define a new interface, which is a list of methods that a class can implement. |
long | A data type that can store whole numbers from -9223372036854775808 to 9223372036854775807. |
native | Used to specify that a method is implemented in a platform-specific way using native code. |
new | Used to create a new object of a certain class. |
package | Used to define a new package, which is a group of related classes and interfaces. |
private | Used to specify that a variable or method can only be accessed within the same class. |
protected | Used to specify that a variable or method can only be accessed within the same class or its subclasses. |
public | Used to specify that a variable or method can be accessed from any other class. |
return | Used to return a value from a method. |
short | A data type that can store whole numbers from -32768 to 32767. |
static | Used to specify that a variable or method belongs to a class, rather than an instance of the class. |
strictfp | Used to enforce strict floating-point arithmetic, ensuring consistent results across different platforms. |
super | Used to refer to the superclass of a class. |
switch | Used to create a switch statement, which executes different blocks of code depending on the value of a variable. |
synchronized | Used to specify that a block of code can only be executed by one thread at a time. |
this | Used to refer to the current instance of a class. |
throw | Used to throw an exception, which is an error that occurs during the execution of a program. |
throws | Used to declare that a method may throw certain exceptions. |
transient | Used to specify that a variable should not be serialized when an object is written to a file or transferred over a network. |
try | Used to create a try-catch block, which allows for the handling of exceptions that may occur within a block of code. |
void | A data type used to indicate that a method does not return a value. |
volatile | Used to indicate that a variable may be modified by multiple threads, ensuring that changes are immediately visible to other threads. |
while | Used to create a while loop, which executes a block of code while a certain condition is true. |
strictfp | Used to enforce strict floating-point arithmetic, ensuring consistent results across different platforms. |
module | Used to define a module, which is a grouping of related packages and classes. |