๐ŸŒ
Medium
medium.com โ€บ @mukherjeesourabh07 โ€บ reserved-keywords-in-java-791b65df5707
Reserved keywords in Java. Reserved keywords | by Sourabh Mukherjee | Medium
January 15, 2024 - Based on Exception Handling: try, catch, finally, throw, throws, assert(came in 1.4 version of java onwards) โ€” 6 keywords ยท Based on Class level: class, package, import, interface, extends, implements, enum โ€” 7 keywords ยท Based on the Object level: new, instanceof, this, super โ€” 4 keywords ยท Based on the return type of the method: void โ€” 1 keyword ... All the reserved keywords are in lowercase only.
๐ŸŒ
Edureka
edureka.co โ€บ blog โ€บ java-keywords
What are Java Keywords and reserved words? Edureka
June 17, 2021 - These keywords are also known as reserved keywords which mean they cannot be used as a variable name, class, method or any other identifier. There are 57 reserved keywords in Java.
Discussions

syntax - What is the difference between keywords and reserved words in Java? - Stack Overflow
I have seen this popular stackoverflow post but the Java docs tends to say a different answer in this link The stackoverflow link answer that is accepted says a reserved word will be reserved for future use and keywords are special words part of language. It then says goto in Java is not a ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
When are reserved words not keywords?
The StackOverflow post is not wrong. I think the Java docs are misleading in that it shows a list of keywords with goto in it. However, the paragraph above all the keywords says how goto and const are currently only reserved words and are not yet keywords. This means you as a programmer cannot use goto or const as an identifier in your Java code, but those words also have no special meaning. So they are currently reserved incase the Java developers decide to give the words special meaning (make them keywords) in the future. More on reddit.com
๐ŸŒ r/learnprogramming
7
1
November 23, 2020
regex - Get a list of all Java reserved Keywords - Stack Overflow
I'm surprised that no one suggested javax.lang.model.SourceVersion yet, because it's actually been around since Java 1.6. If you need to check whether some string is a reserved keyword, you can just call: More on stackoverflow.com
๐ŸŒ stackoverflow.com
Do you have reserved keywords that are currently not in use?
In Tridash identifiers prefixed with a /, such as /module, are reserved for language keywords, and the documentation explicitly states not to use them for user-defined entities. This allows new keywords to be added in the future without collisions with existing code. More on reddit.com
๐ŸŒ r/ProgrammingLanguages
57
27
January 25, 2020
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_ref_keywords.asp
Java Keywords
Java Examples Java Compiler Java ... ... Java has a set of keywords that are reserved words that cannot be used as variables, methods, classes, or any other identifiers:...
๐ŸŒ
ThoughtCo
thoughtco.com โ€บ reserved-words-in-java-2034200
Reserved Words in Java
January 27, 2019 - Reserved words are words that cannot be used as object or variable names in a Java program because they're already used by the syntax of the Java programming language. If you ttempt to use any of the words below as identifiers in your Java programs, ...
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ List_of_Java_keywords
List of Java keywords - Wikipedia
October 20, 2025 - In the Java programming language, a keyword is any one of 68 reserved words that have a predefined meaning in the language. Because of this, programmers cannot use keywords in some contexts, such as names for variables, methods, classes, or ...
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ tutorial โ€บ java โ€บ nutsandbolts โ€บ _keywords.html
Java Language Keywords (The Javaโ„ข Tutorials > Learning the Java Language > Language Basics)
Here is a list of keywords in the Java programming language. You cannot use any of the following as identifiers in your programs. The keywords const and goto are reserved, even though they are not currently used.
๐ŸŒ
How to do in Java
howtodoinjava.com โ€บ home โ€บ java basics โ€บ java reserved and contextual keywords
Java Reserved and Contextual Keywords
December 27, 2022 - Java has 51 reserved words and 16 contextual keywords that cannot be used as identifiers in the code. Programmers should not use these keywords for other purposes.
๐ŸŒ
Java Challengers
javachallengers.com โ€บ home โ€บ keywords vs reserved words in java
Keywords VS Reserved Words in Java
January 18, 2021 - In the most recent Java releases, reserved identifiers that can be used as a Java identifier. To make a comparison between the most recent reserved identifiers and the previous keywords or reserved words; reserved identifiers can be used as a class, method, or variable names and keywords canโ€™t!
Find elsewhere
๐ŸŒ
Unstop
unstop.com โ€บ home โ€บ blog โ€บ java keywords explained | list of 54 keywords +code examples
Java Keywords Explained | List Of 54 Keywords +Code Examples // Unstop
December 12, 2024 - Keywords in Java are reserved words with predefined meaning and functionality that cannot be used for anything else. Examples: class, int, if, for, while, etc.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 68555224 โ€บ what-is-the-difference-between-keywords-and-reserved-words-in-java
syntax - What is the difference between keywords and reserved words in Java? - Stack Overflow
... key words - words in Java that have a pre-defined meaning reserved key words - words in Java that are keywords but they are not currently in use and don't have a function in code.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ when are reserved words not keywords?
r/learnprogramming on Reddit: When are reserved words not keywords?
November 23, 2020 -

I read this link: https://stackoverflow.com/questions/1078908/what-is-the-difference-between-keyword-and-reserved-word#:~:text=Keywords%20have%20a%20special%20meaning,reserved%20words%20and%20vice%20versa.

I understand how reserved words are keywords and how some keywords cannot be reserved words, but I do not understand how some reserved words cannot be keywords? The answer to the post says how goto is not a keyword, but the java docs say how goto is a reserved word but also a keyword. Does this mean that reserved words are always keywords, or is there an instance/example in some language where a reserved word is not a keyword, would this mean that the StackOverflow post is wrong?

Certain language such as Python and C++ seem to use both of these terms interchangeably, so it depends on the language as well?

๐ŸŒ
Javatpoint
javatpoint.com โ€บ java-reserved-keywords
Java Reserved Keywords - Javatpoint
Java Reserved Keywords with java tutorial, features, history, variables, object, programs, operators, oops concept, array, string, map, math, methods, examples etc.
๐ŸŒ
DataCamp
datacamp.com โ€บ doc โ€บ java โ€บ category โ€บ keywords
Java Keywords
In Java, keywords are reserved words that have a predefined meaning in the language. They form the foundation of Java's syntax and cannot be used as identifiers, such as variable names, method names, or class names.
๐ŸŒ
Medium
medium.com โ€บ codestorm โ€บ reserved-words-in-java-f71e7260933f
Reserved words in Java. Here is a list of keywords in the Javaโ€ฆ | by Asep Saputra | Code Storm | Medium
July 3, 2021 - Here is a list of keywords in the Java programming language. You cannot use any of the following as identifiers in your programs. The keywords const and goto are reserved, even though they are not currently used.
๐ŸŒ
TechVidvan
techvidvan.com โ€บ tutorials โ€บ keywords-in-java
Keywords in Java - Java Reserved Words - TechVidvan
June 5, 2020 - These are reserved for special purposes and we cannot use them as identifier names otherwise the compiler will give an error. In Java. there are 51 keywords, but 2 of them are not used which are-goto and const. Only 49 keywords are used in Java.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-keywords
Java Keywords
April 22, 2024 - In Java, keywords are case-sensitive, and writing Java keywords in upper case (like IF instead of if) will throw an error. Java keywords are reserved words that have predefined meanings in the language.
๐ŸŒ
Computer Hope
computerhope.com โ€บ jargon โ€บ j โ€บ java_reserved_words.htm
What Are Java Reserved Words?
Java reserved words are keywords that are reserved by Java functions or other uses that cannot be used as identifiers (e.g., variable names, function names, class names). If a reserved word was used as a variable, you would get an error or ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ reserved-words-in-java
Reserved Words in Java - GeeksforGeeks
October 6, 2025 - Java reserves some words to represent predefined functionalities. These words are called reserved words. They can be briefly categorized into two parts: Keywords (50): Keywords define functionalities.
Top answer
1 of 4
13

From axis.apache.org

Basically, Pre-Sort the keywords and store it in an array and using Arrays.binarySearch on your keyword for the good'ol O(logn) complexity

import java.util.Arrays;

    public class MainDemo {
        static final String keywords[] = { "abstract", "assert", "boolean",
                "break", "byte", "case", "catch", "char", "class", "const",
                "continue", "default", "do", "double", "else", "extends", "false",
                "final", "finally", "float", "for", "goto", "if", "implements",
                "import", "instanceof", "int", "interface", "long", "native",
                "new", "null", "package", "private", "protected", "public",
                "return", "short", "static", "strictfp", "super", "switch",
                "synchronized", "this", "throw", "throws", "transient", "true",
                "try", "void", "volatile", "while" };

        public static boolean isJavaKeyword(String keyword) {
            return (Arrays.binarySearch(keywords, keyword) >= 0);
        }

        //Main method
        public static void main(String[] args) {
            System.out.println(isJavaKeyword("void"));

        }

    }

Output:

True


Alternatively, as users @typeracer,@holger suggested in the comments, you can use SourceVersion.isKeyword("void") which uses javax.lang.model.SourceVersion library and Hashset Data structure internally and keeps the list updated for you.

2 of 4
7

I'm surprised that no one suggested javax.lang.model.SourceVersion yet, because it's actually been around since Java 1.6.

If you need to check whether some string is a reserved keyword, you can just call:

SourceVersion.isKeyword(str)

And if you really need the full list of the reserved keywords, you can obtain it from the source code of that class:

private final static Set<String> keywords;
static {
    Set<String> s = new HashSet<String>();
    String [] kws = {
        "abstract", "continue",     "for",          "new",          "switch",
        "assert",   "default",      "if",           "package",      "synchronized",
        "boolean",  "do",           "goto",         "private",      "this",
        "break",    "double",       "implements",   "protected",    "throw",
        "byte",     "else",         "import",       "public",       "throws",
        "case",     "enum",         "instanceof",   "return",       "transient",
        "catch",    "extends",      "int",          "short",        "try",
        "char",     "final",        "interface",    "static",       "void",
        "class",    "finally",      "long",         "strictfp",     "volatile",
        "const",    "float",        "native",       "super",        "while",
        // literals
        "null",     "true",         "false"
    };
    for(String kw : kws)
        s.add(kw);
    keywords = Collections.unmodifiableSet(s);
}

Caution: the above source code is from Java 1.8, so don't just copy & paste from this post if you're using a different version of Java. In fact, it's probably not a good idea to copy it at all โ€” they made the field private for good reason โ€” you probably don't want to have to keep it up-to-date for every new Java release. But if you absolutely must have it, then copy it from the source code in your own JDK distro, keeping in mind that you might have to manually keep updating it later.