Keywords in Java: Complete List

In this article, we will learn about keywords in Java. We will know about different keywords in Java.

keywords in Java

What are Keywords in Java ?

keywords in Java are reserved words. These cannot be used as names of method, variable, class names and other identifiers. These keywords have predefined meanings w.r.t Java language.

Complete List of Keywords in Java

The below is the list of keywords in Java.

  1. new – used when creating a new object
  2. switch – please read Java Switch
  3. case – used in switch statements. Please read Java Switch
  4. assert – used in assertion statement
  5. default – used in switch statements(read Java Switch) and also in interface for a default method implementation(please read Interface Default and Static Methods)
  6. private – Access specifier for class, methods and variables. These can be only accessed inside a class where it is defined. Please read Access Modifiers
  7. protected – The protected access modifier is specified using the keyword protected. The data members, class or methods having protected access modifier are accessible within the same package and also in the subclasses in different packages. Please read Access Modifiers
  8. public – The public access modifier is specified using the keyword public. The data members, class or methods having public access modifier are accessible everywhere. Please read Access Modifiers.
  9. package – declares a Java Package
  10. synchronized – please read All About Synchronization
  11. transient – declares that an instance field is not part of the default serialized form of an object. Please read Serialization in Java
  12. for – used for looping.
  13. while – we use it to create a while loop.
  14. do – used in conjunction with while loop
  15. if – we use it to test a condition. If the condition returns true, it executes the block inside if.
  16. else – we use it to indicate the alternative branches in an if statement.
  17. this – please read this and super keywords
  18. super – please read this and super keywords
  19. break – please read break and continue in loop
  20. continue – please read break and continue in loop
  21. abstract – please read abstract keyword : classes and methods
  22. class – we use it to define a class.
  23. interface – we use it to define an interface.
  24. extends – A Class can use extends to extend another class. An interface can use extends to extend one or more interfaces.
  25. implements – we use it to implement an interface.
  26. throw – please read throw and throws
  27. throws – please read throw and throws
  28. import – we use it to import a package, class or interface.
  29. enum – please read Enums
  30. instanceof -we use it to test whether the object is an instance of the specified class or implements an interface.
  31. return – we use it to return from a method when its execution is complete. It will return a value if the method return type is not void.
  32. void – we use it to declare that a method does not return any value.
  33. try – It is used to start a block of code that will be tested for exceptions. The try block must be followed by either catch or finally block. Please read try, catch, and finally
  34. catch – used to catch the exceptions generated by try statements. It must be used after the try block only. Please read try, catch, and finally
  35. finally – used in conjunction with try. The finally block is executed after execution exits the try block and any associated catch clauses regardless of whether an exception was thrown or caught, or execution left method in the middle of the try or catch blocks using the return keyword. Please read try, catch, and finally
  36. byte – declares a variable that can hold an 8-bit data value.
  37. int – we can use it to declare a variable that can hold a 32-bit signed integer. please read Widening and Narrowing Primitive Conversions
  38. short – we can use it to declare a variable that can hold a 16-bit integer.
  39. char – we can use it to declare a variable that can hold unsigned 16-bit Unicode characters.
  40. long – we can use it to declare a variable that can hold a 64-bit integer.
  41. float – we can use it to declare a variable that can hold a 32-bit floating-point number.
  42. double – we can use it to declare a variable that can hold a 64-bit floating-point numbers.
  43. boolean – defines a boolean variable for the values “true” or “false” only.
  44. native – please read native keyword
  45. final – please read final keyword
  46. static – please read static keyword
  47. strictfp – please read strictly
  48. volatile – please read volatile

The below keywords are reserved but not used.

  1. const
  2. goto

Please note that truefalse and null are literals, not keywords.

Conclusion: Keywords in Java

Keywords in Java empower us to communicate with the Java compiler effectively. By understanding their meanings and adhering to their usage rules, we ensure that our code follows the syntax and semantics of the language.

Leave a Reply

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