Java Keywords

Java has 51 reserved words that have very specific meanings and cannot be used as identifiers in the application code. Also, there are 16 contextual keywords that are treated as keywords when found in a specific context. Programmers should not use these keywords for any purpose other than what they are meant to be.

1. What is a Keyword in Java?

  • Given is the list has all reserved java keywords. We cannot use any of the following as identifiers in our programs.
  • The keywords const and goto are reserved, even though they are not currently used.
  • true, false, and null might seem like keywords, but they are literal; we cannot use them as identifiers in our programs.
  • strictfp was added in JDK 1.2.
  • assert was added in JDK 1.4.
  • enum was added in JDK 1.5.
  • Later versions of features such as sealed classes, records and JPMS added few more contextual keywords.

2. Java Keywords

The following 51 keywords cannot be used as identifiers.

_ (Underscore)

3. Contextual Keywords

The following 16 words can be interpreted as keywords or as other tokens, depending on the context in which they appear.

  • The module and open are used for declaring modules.
  • The exportsopensprovidesrequirestouses, and with are used for importing and exporting the modules.
  • The transitive is recognized as a terminal in a RequiresModifier.
  • The var is used to infer local variable types.
  • The yield is used to yield a value in a switch statement.
  • The record is used to define new record types.
  • The non-sealedpermits, and sealed are used to define sealed classes and interfaces.

Learning about all keywords on a single page is not possible. We will learn about each Java keyword in its dedicated tutorial.

Happy Learning !!

Leave a Reply

Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.

Our Blogs

REST API Tutorial