Java Keywords are also known as reserved words in JAVA. Java Keywords are predefined in JAVA and they are used for some internal process or represent some predefined actions. There are a number of Java Keywords which plays an important role. We will discuss them in a separate post.
RULE: These are words not allowed to use as variable names or objects.
- abstract: abstract keyword is used to declare an abstract method or abstract class. That class or method will be implemented later, in a subclass
- boolean: It is used to declare a boolean variable that can hold only true or false.
- break: It is used in loops and witch statement. It breaks the control flow based on conditions.
- byte: It is used to declare a variable that can hold 8-bits data values.
- case: It used in switch statements to mark a block of code.
- catch: This keyword is used in exception handling to catch the exceptions that are generated by try block.
- char: It is used to declare a variable of a character type that can hold unsigned 16-bit Unicode characters
- class: This keyword is used to declare a new class.
- continue: It is used in loops. It continues the current flow of the program and skips the remaining code at the specified condition.
- default: default keyword is used in the switch block to specify the default block. It is also used in access modifiers.
- do: It is used in do-while loop
- double: It is used to declare a variable that can hold 64-bit floating-point numbers.
- else: It is used in if-else statements.
- enum: It is used to declare enum(Enumeration). It is used to define a fixed set of constants.
- extends: It is used to inheritance to extends the class.
- final: This keyword is used to declare a variable that holds constant value.
- finally: It is used in exception handling.
- float: Java float keyword is used to declare a variable that can hold a 32-bit floating-point number.
- for: It is a keyword that is used to define for a loop.
- if: It is the keyword used to test the condition.
- implements: It is used to implement the interface.
- import: It is used to import/access the class or interface to the current source.
- instanceOf: It is used to test the object is an instance of a class or interface.
- int: It is used to declare a variable that can hold a 32-bit signed integer.
- interface: it is a keyword that is used to declare the interface. The interface can hold only abstract methods.
- long: long keyword is used to declare a variable that can hold a 64-bit integer.
- native: It is used to specify that a method is implemented with native code
- new: It is used to create new objects.
- null: It means an object doesn’t refer anything.
- package: It is used to define a package that includes classes.
- private: Its an access modifier that can use with class, variable or method. If variables or method is private, then it can’t be accessible from outside the class.
- protected: It’s an access modifier that can use with variable or method. If variable or method are protected, It can be accessible within the package and outside the package but through inheritance only.
- public: It’s an access modifier that can use with class, variable or method. If variables or method is private, then it can be accessed from outside the class or anywhere.
- return: It is used in a method to return from the method when execution gets completed.
- short: Java short keyword is used to declare a variable that can hold a 16-bit integer.
- static: It is used for memory management.
- strictfp: It is used to restrict the precision and rounding of floating-point calculations to ensure portability.
- super: It is used to refer parent class or parent’s class method.
- switch: It’s used in a switch statement that executes different blocks based of conditions.
- synchronized: Used with method/section in multi-threading
- this: Used to refer to the current object.
- throw: Used to throw the exception from try block
- throws: Used to throw multiple exceptions from method
- transient: It does not want to serialize the variable.
- try: It is used in exception handling.
- void: If the method doesn’t return anything.
- volatile: If we used it with variable it means variable may change asynchronously.
- while: while is a keyword that used in while loop