Different Keywords in Java? | Keywords in Java

 


Java has several keywords that have specific meanings and uses in the language.

 

Some common keywords include:


abstract: Indicates that a class or method is abstract, meaning it must be overridden by a subclass or implementing class.


boolean: The data type that can hold only true or false values.


break: Terminates the current loop or switch statement.


byte: The data type that can hold an 8-bit signed integer value.


case: A label in a switch statement that specifies a value to match against.


catch: The block of code that is executed when a specific exception is thrown in a try-catch block.


char: The data type that can hold a single 16-bit Unicode character.


class: Indicates the start of a class definition.


continue: Skips the current iteration of a loop and continues with the next one.


default: A label in a switch statement that is executed if no other case labels match.


do: Indicates the start of a do-while loop.


double: The data type that can hold a double-precision 64-bit floating-point value.


else: The block of code that is executed if an if statement evaluates to false.


enum: Indicates the start of an enumerated type definition.


extends: Indicates that a class is a subclass of another class.


final: Indicates that a variable or method cannot be overridden or subclassed.


finally: The block of code that is executed after a try-catch block, regardless of whether an exception was thrown.


float: The data type that can hold a single-precision 32-bit floating-point value.


for: Indicates the start of a for loop.


if: The block of code that is executed if a certain condition is true.


implements: Indicates that a class is implementing an interface.


import: Allows the use of types from other packages in the current file.


instanceof: A operator that tests whether an object is an instance of a particular class or interface.


int: The data type that can hold a 32-bit signed integer value.


interface: Indicates the start of an interface definition.


long: The data type that can hold a 64-bit signed integer value.


native: Indicates that a method is implemented in native code.


new: Creates a new instance of a class.


null: A special value that represents the absence of an object reference.


package: Specifies the package that a class or interface belongs to.


private: Indicates that a method or variable can only be accessed within the same class.


protected: Indicates that a method or variable can be accessed within the same package or by subclasses.


public: Indicates that a method or variable can be accessed by any code.


return: Returns a value from a method.


short: The data type that can hold a 16-bit signed integer value.


static: Indicates that a method or variable belongs to the class, rather than an instance of the class.


strictfp: Indicates that a method or class should be executed using strict floating-point arithmetic, ensuring that the same results are produced on all platforms.


super: Refers to the parent class of the current class.


switch: Indicates the start of a switch statement.


synchronized: Indicates that a method can only be accessed by one thread at a time.


this: Refers to the current object.


throw: Throws an exception.


throws: Indicates that a method may throw a specific exception.


transient: Indicates that a variable should not be serialized.


try: Indicates the start of a try-catch block.


void: Indicates that a method does not return a value.


volatile: Indicates that a variable may be modified by multiple threads.


while: Indicates the start of a while loop.


Please note that this is not an exhaustive list and there are some more keywords available in Java that are used for specific purposes.

Post a Comment

Post a Comment (0)

Previous Post Next Post