Summary of all Java keywords with code examples
- Details
- Written by Nam Ha Minh
- Last Updated on 09 March 2024   |   Print Email
This article gives you an overview of all keywords in the Java programming language with explanation and code examples (updated to Java 14). Understand the meaning of each Java keyword will help you write better and more precise code, e.g. know when to use public or private for a variable or class.
Beginners in Java programming will find the list below helpful in terms of getting started with Java from the ground up. And senior Java programmers will also find this article helpful in terms of reviewing all Java keywords updated to the most recent release of Java.
You know, the Java programming language has over 50 reserved keywords which have special meaning for the compiler and cannot be used as variable names. Following is a list of Java keywords in alphabetical order. You can click on an individual keyword to see its description and usage example.
List of all keywords in Java (updated to Java 14):
Some noteworthy points regarding Java keywords:
- const and goto are resevered words but not used.
- true, false and null are literals, not keywords.
- Since Java 8, the default keyword is also used to declare default methods in interfaces.
- Since Java 10, the word var is used to declare local variables (local variables type inference). For backward compatibility, you can still use var as variable names. So var is a reserved word, not keyword.
- Java 14 adds two new keywords record and yield (but in preview mode)
- all keywords are in lower-case.
And based on categories, the keywords in Java can be grouped as follows:
Java keywords for access modifiers: private, protected, public
Java keywords for class, method, variable modifiers:
abstract, class, default, extends, final,
implements, interface, native, new,
static, strictfp, synchronized, transient,
Java keywords for Flow control:
break, case, continue, default, do, else,
for, if, instanceof, return, switch, while,
Java keywords for package control: import, package
Java keywords for primitive types: boolean, byte, char,
double, float, int, long, short
Java keyword for error handling: assert, catch, finally,
Java keyword for enumeration: enum
Other Java keywords: super, this, void
Unused (reserved) Java keywords: const, goto
Other Recommended Tutorials:
- 9 Rules about Constructors in Java
- 12 Rules and Examples About Inheritance in Java
- 12 Rules of Overriding in Java You Should Know
- 10 Java Core Best Practices Every Java Programmer Should Know
- Understand Interfaces in Java
- Understand abstraction in Java
- Understand encapsulation in Java
- Understand inheritance in Java
- Understand polymorphism in Java
- Notes about Arrays in Java
- Notes about execution control statements in Java
- Notes about numeric literals in Java
- Notes about operators in Java
Comments