Keywords in Java

By | July 18, 2020

Keywords in Java are something that has got a special meaning. It is a predefined word which has special meaning in Java and these words cannot be used as object reference, variables, or data member.

Example: If we want to store a numeric data, we use a keyword called “int” If we want to store a character value, we use char keyword. If we want to store a decimal value, we use either float or double keyword.

Total numbers of keywords in java

We have a total of 53 keywords in java.
In which, 3 are literals or constant value such as true, false, and null. And on the remaining 50, we don’t use 2 keywords in java ( goto and const) .

The list of 48 keywords is as follows.

1. abstract 

It used in two contexts, class and method.

  • An abstract class is a class which declared with abstract keyword. It is just like a simple class having data members, constructors, methods along with that we can also declare the abstract method in this class.
  • An abstract method is a method that does have any implementation or definition or logic. This type of method is declared with an abstract keyword just like an abstract class.

2. assert

3. boolean

This keyword in java used to indicate a data type that can hold True and False values only.

4. break 

It is a control statement that used to come out from loops after certain conditions achieved.

5. byte 

It is a datatype in java which used to store the numeric value of up to 8 bit.

6. case 

This keyword in java used with a switch statement.

7. catch

It used which a try block, if any exception occurs inside the code written under try block, then catch block will handle the exception. 

8. char

It used to store the character datatype in Java.

9. class

This keyword in java used to create or declare the class.

 10. continue

It generally used with a loop and the purpose of the continue keyword is to Sends back the control outside of the loop.

11. default

It used with the switch case statement, if the switch argument does not match with any of the mentioned cases then control swift to the default statement.

12. do

Generally, it used with the do-while loop. In this case, before starting a loop, the very first condition is always true. 

13. double 

It is one of the datatypes in java which holds the numeric value up to 64 bit.

14. else 

It used with the if statement. The condition of if the statement is false then control will be moved to else part.

15. enum 

16. extends

It used to inherit the other class. If any class having extends keyword that means it is the sub or derived class of some other class.

17. final

The final keyword in java has two meanings, one for class and other for data members of the class.

  •  If any class declared with the final keyword that means this class is not eligible for inheritance. Hence there will be no subclass or derived class for the final class in java. 
  • Any data member declared with the final keyword that means once the value assigned to it, then that not going to change in a further line of code.

18. finally

This keyword used with the try-catch block, even any exception arises the code written in finally block will get executed.

19. float

It is also a data type in java which is used to hold 32-bit value.

20. for

It used to initialize a for a loop.

21. if

Tests a true/false expression and branches accordingly.

22. implements

It used with the class to implement any interface.

23. import

When you want to use other classes in different class files, then import keyword used for this purpose.

 24. instanceof

It is a keyword that is used to check the Object type. It returns the boolean value that is True or False.

keywords in Java

 25. int 

It is used to store the 32-bit numeric value of the integer type.

26. interface

This keyword in java is used to declare the interface.

27. long

A data type that holds a 64-bit integer

28. native

It indicates that a method is implemented with native (platform-specific)  code.

29. new 

It is used to create an object in java. This new keyword gives the direction to JVM to create an Object.

30. package

Used to Declares a Java package.

31. private

An access modifier indicating that a method or variable may be accessed only in the class in which it declared. 

32. protected

It is also one type of access modifier. The scope of any data member or method is up to package level when that declares with a protected access modifier.

33. public

The data member or method which declares with public access modified can be accessed from anywhere in java even outside the package.

34. return

It is a last executable statement in any method, which basically use to return some value if the method get invoked.

35. short 

A data type that can store a 16-bit integer

36. static

The static keyword in java used to declare the method or variable is of Class type. That is method or variable which declares with a static keyword can be called with the Class name.

37. strictfp 

This Java keyword used to ensure that the floating value calculation is always the same on every platform. 

38. super

Refers to a class’s base class (used in a method or class constructor).

39. switch

A statement that executes code based on a test value.

40. synchronized

It indicates critical sections or methods in multithreaded code.

41. this

It represents the current invoking or class Object.

42. throw

Creates an exception.

43. throws

Indicates what exceptions may be thrown by a method.

44. transient

It used to Specifies that a variable is not part of an object’s persistent state.

45. try

Starts a block of code that will be tested for exceptions

46. void

It used with the method and indicates that the method does not have any return type.

47. volatile

Indicates that a variable may change asynchronously.

48. while

Starts a while loop. 

Summary

In this article, you learned about all the available keywords in java which frequently used while writing a program or developing any java based production-ready application. You can also refer to the official pdf link of Keywords in Java.

Thank You for reading the article. If you have any queries or doubt regarding this article, please feel free to write down in the comment box. You will get the reply within 24 hours.

If you find any mistake or any feedback, let me know. You can also check out my other articles such as Abstraction, Encapsulation, Inheritance, etc.

Leave a Reply

Your email address will not be published. Required fields are marked *