Reserved Words in Java

Rupinder Kaur
2 min readMar 20, 2024

--

In both natural and programming languages, certain words are designated to convey specific meanings or functionalities. For instance, in English, “cat” typically refers to a type of animal, “apple” signifies a kind of fruit, and “eat” denotes an action. Similarly, in Java, there are reserved words intended to represent specific functionalities or meanings. These words are referred to as reserved words.

Java has a total of 53 reserved words.

Reserved Words in Java

Data Type Related Keywords

  • byte
  • short
  • int
  • long
  • double
  • float
  • boolean
  • char

Flow control related keywords

  • if
  • else
  • switch
  • case
  • default
  • while
  • do
  • for
  • break
  • continue
  • return

Modifier keywords

  • public
  • private
  • protected
  • static
  • final
  • abstract
  • synchronised
  • native
  • strictfp
  • transient
  • volatile

Keywords related to exception handling

  • try
  • catch
  • finally
  • throw
  • throws
  • assert

Class related keywords

  • class
  • interface
  • extends
  • implements
  • package
  • import

Object related keywords

  • new
  • instanceof
  • super
  • this

Other keywords

  • enum
  • void

Unused Keywords

  • Const: In Java, the const keyword is not used because it’s a reserved word that has no functionality assigned to it. Instead, Java uses final to achieve similar behavior.
  • Goto: Java avoids including the goto statement to prevent complex and hard-to-read code. Goto allows unconditional jumps, complicating program flow and potentially leading to spaghetti code. Java encourages structured programming for clearer organization. Instead of goto, Java offers loops and conditional statements for better control flow, enhancing code readability and maintainability.

If we try to use these keywords, we will get a compilation time error.

Reserved Literals

  • true: Value for boolean data type
  • false: Value for boolean data type
  • null: Default value for object reference

Conclusions

  • There are a total of 53 keywords in java
  • 50 are keywords, & 3 are literals (true, false, null)
  • Out of 50 keywords, two are unused, which are goto & const. If we try to use these keywords, we will get a compilation time error
  • All keywords contains only lowercase alphabets
  • In Java, a new keyword is there, but no delete keyword, because the destruction of useless objects is the responsibility of the garbage collector.
  • There are three new keywords: strictfp, which was introduced in the 1.2 version; assert, which was introduced in the 1.4 version; and enum, which was introduced in the 1.5 version.
Photo by Howie R on Unsplash

--

--

Responses (2)