Keywords in Java

In this tutorial, we will learn about Keywords in Java. Java provides a wide range of keywords to us. Every keyword has some special meaning in Java. We can not use any keyword as a class name or as a variable name.

All keywords have some predefined meaning which the Java compiler knows very well For example if you are using the “while” keyword then the compiler knows very well that we are going to define a loop. Like other programming languages, Java has some common keywords like if, and for. But it also has some special keywords like byte and implements.

It’s important to note we can not use any keyword as the name of an identifier (as a class name, variable name or method name.)

Keyword List in Java: –

  • abstract: – We use the abstract keyword with the class to make a class abstract. We can not create an instance of an abstract class
  • boolean: – We use the boolean keyword with a variable to define a variable of the boolean data type. boolean is a special kind of data type in Java and a boolean variable can hold only two values(true/false).
  • break: – break keyword is used to break the normal flow of a statement we normally use this keyword with switch but we can also use this with if statement.
  • byte: – The byte keyword is used to define a variable of the byte data type. The byte is a special kind of data type in Java that can store 8-bit numeric values.
  • case: – case keyword we used in a switch statement to define different cases of the switch statement.
  • catch: – catch keyword we use with try keyword and it helps us in Exception handling.
  • char: – char keyword we use with a variable to define a variable of the char data type.
  • class: – class keyword used to create a class.
  • do: – do keyword is used to define the do-while loop in Java.
  • double: – double keyword is used to define a variable of the double data type.
  • else: – else keyword we use with if keyword, we use this keyword to define the negative part of the if statement.
  • extends: – We use extends keyword to perform inheritance in Java in simple words to get features of one class into another class.
  • final: – final keyword is used to define a constant in Java, to define a non-overrideable method in Java and to define the final class in Java.
  • finally: – we use finally keyword to define finally block in exception handling.
  • float: – float keyword is used to define the variable of float data type in Java.
  • for: – for a keyword is used to define a loop in Java.
  • if: – if is a keyword used to define conditional statements in Java.
  • implements: – implements keyword is used to inherit an interface in a class.
  • import: – import keyword is used to import a complete package or a class in the program.
  • int: – int keyword is used to define a variable of int data type in Java.
  • interface: – The interface keyword is used to define an interface in Java.
  • long: – long keyword is used to define the variable of long data type in Java.
  • new: – new keyword is used to create a new object of the class.
  • package: – package keyword is used to define package in Java.
  • private: – private keyword is used as the access specifier of class, variable or method.
  • protected: – protected keyword is also used as the access specifier of class, variable or method.
  • return: – return keyword is used to return some value back after the execution of the method.
  • short: – short keyword is used to define the variable of the short data type.
  • static: – static keyword is used to define a static variable, static methods and static blocks in Java. This keyword is mainly used for memory management
  • super: – super keyword is like a reference variable and super keyword references to the object of the parent class.
  • switch: – switch keyword is used to define the switch statement in the program it is part of the control flow.
  • this: – this keyword is like a reference variable and this keyword references to the object of the current class.
  • throw: – throw keyword is used in Exception handling. it is used to throw explicitly Exception in the program
  • throws: – throws keyword is used in Exception handling. A checked exception can be propagated with throws.
  • try: – try keyword is used in mention part of code where an exception may occur in the program.
  • void: – void keyword is used to define the return type of function in Java. The void mean function will return nothing.
  • while: – while keyword is used to define a while loop in Java.
Spread the love
Scroll to Top
×