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.

Answer from Ravi Yenugu on Stack Overflow
🌐
Igmguru
igmguru.com › blog › java-keywords
Java Keywords – 68 Java Keywords Explained
4 weeks ago - The following keywords are used in this code: public: This access modifier helps to make sure that classes, methods or variables are accessible from any other class. It is important for the Java Virtual Machine (JVM) to start the program. class: This keyword is used to declare a class and works as a blueprint for creating objects. Nearly all code of this programming language resides within classes.
🌐
Oracle
docs.oracle.com › javase › tutorial › java › nutsandbolts › _keywords.html
Java Language Keywords (The Java™ Tutorials > Learning the Java Language > Language Basics)
See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases. See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases. Here is a list of keywords in the Java programming language.
Discussions

regex - Get a list of all Java reserved Keywords - Stack Overflow
I need to do a name validation ... to any java keywords. Is there a specific way of retrieving all the keywords into one data structure? or do I need to just build a regex string with all these keywords in it : "for|while|if|..." and try and match my string against it? ... @Kabulan0lak yeah, I know of the list, I want to ... More on stackoverflow.com
🌐 stackoverflow.com
What is the most common keywords in writing a Java program?
From one of my java project, https://github.com/DropSnorz/OwlPlug : 154 class 162 null 208 true 266 void 304 for 334 if 462 new 500 return 503 private 540 String 596 this 766 public 1293 import Just counted all words regardless if they are in code or part of comments and Javadoc. More on reddit.com
🌐 r/javahelp
6
0
August 11, 2020
Need a detailed understanding of the keywords in the beginning of any java programming.
void means the method doesn't return a value. You can have a method declared void kickRocks() and if it is void, you can just call it. It doesn't provide a value, it just kicks the rocks. kickRocks(); If you have a method that does return a value, then it needs to return that value. int breakRocks() may return how many rocks are broken. You can use that value. count = count + breakRocks(); Or you can ignore the return value. breakRocks(); But either way, it needs to fulfill its return value. Static has more than one place it might get used, but for fields or methods, it means that thing belongs to the class itself and not the instances of the class. Your Rocks class allows rocks of three sizes, so when you make a Rock myRock = new Rock(RockSize.SMALL), you get an instance of Rock that probably has a field that stores its size. Each instance of a Rock gets its own size. However, if the Rock class also needs to keep a list of all rocks and let you know how many rocks have been made, that list isn't a separate list for each instance of a rock, its for the class itself, so that list is static, which means there is only one list, not a seperate rock list for each rock. String[] args is an array of strings so if the program is run from the command line, it can access all the arguments passed in that command line. If you aren't running your stuff from a command line, you can probably just ignore the args. It needs to be there, but you don't have to use them. More on reddit.com
🌐 r/javahelp
3
1
December 29, 2021
new to java looking for list of statements/commands.

Here are all the keywords in java:

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html

Part of the Oracle Learning the Java Language tutorials:

https://docs.oracle.com/javase/tutorial/java/TOC.html

The Java 8 Docs include all the classes that exist in JDK8

https://docs.oracle.com/javase/8/docs/api/

More on reddit.com
🌐 r/javahelp
9
9
September 27, 2021
🌐
Bukkit
bukkit.org › threads › the-complete-list-of-java-keywords.199291
The Complete List of Java Keywords | Bukkit Forums
The Complete List of Java Keywords Introduction and Overview: Whether you are a Java or JavaScript coder, game maker, or plugin developer, this...
🌐
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 - Control Flow: Keywords like if, else, for, while, and switch help in creating control flow structures that dictate the execution of code blocks. Object-Oriented Features: Keywords in Java enable class creation and inheritance, such as class, ...
🌐
DataCamp
datacamp.com › doc › java › category › keywords
Java Keywords
Keep keywords in mind when working with frameworks: Be mindful of keywords when you generate classes or methods dynamically, especially when using frameworks that auto-generate code. Organize code using keywords effectively: Make good use of keywords like final, synchronized, and volatile in multithreaded applications for thread safety and performance.
🌐
CodeJava
codejava.net › java-core › the-java-language › java-keywords
Summary of all Java keywords with code examples
Java keywords for access modifiers: private, protected, publicJava keywords for class, method, variable modifiers:abstract, class, default, extends, final, implements, interface, native, new, static, strictfp, synchronized, transient, var, record, volatile Java keywords for Flow control:break, ...
🌐
Programiz
programiz.com › java-programming › keywords-identifiers
Java Keywords and Identifiers
You cannot use keywords like int, for, class, etc as variable name (or identifiers) as they are part of the Java programming language syntax. Here's the complete list of all keywords in Java programming.
Find elsewhere
🌐
University of North Carolina
cs.unc.edu › ~weiss › COMP14 › 18-JavaKeyWords.html
Java Keywords or Reserved Words (52)for jdk1.4
Keywords for data types are: boolean byte char int long short float double · Keywords for access control are: private protected public · Keywords for modifiers are: abstract final native private protected public static transient synchronized volatile strictfp ·
🌐
Croma Campus
cromacampus.com › blogs › list-of-java-keywords
List of Java Keywords: A Comprehensive Guide
Prashant Bisht Technical content writer experienced in writing tech-related blogs along with software technologies. Skilled in technical content writing, content writing, SEO content writing, WordPress, off-page SEO. ... Explore the comprehensive list of Java keywords, including reserved words like public, static, final, class, and more in this guide.
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.

🌐
Medium
yuvrajscorpio.medium.com › keywords-in-java-e5eabd2b4dda
Keywords In Java. In Java, keywords are reserved words… | by Yuvraj Kevit | Medium
April 26, 2025 - Keywords In Java In Java, keywords are reserved words that have special meanings and cannot be used as identifiers (variable names, method names, etc.). Here’s a complete list of all default …
🌐
TechVidvan
techvidvan.com › tutorials › keywords-in-java
Keywords in Java - Java Reserved Words - TechVidvan
June 5, 2020 - Java Keywords - What are keywords in java and list of java keywords with examples - boolean, short, for, case, catch,final,interface,protected, this, byte
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-keywords
Java Keywords - GeeksforGeeks
1 month ago - Used to define classes, interfaces, and objects, as well as inheritance and encapsulation properties. Define the visibility or accessibility of classes, methods, and variables. Used to organize classes and access external code. Used to handle concurrent execution of code and ensure thread safety. Handle object persistence, garbage collection, and native method calls. Define additional behaviors and precision control. These keywords are reserved but not currently used by Java.
🌐
Great Learning
mygreatlearning.com › blog › it/software development › java keywords
Master Java Keywords: A Detailed List with Examples
June 27, 2025 - Leverage OOP Keywords: Use class, extends, implements, abstract, and interface to design robust object-oriented systems. This promotes code reusability and maintainability. To test the understanding more better, take Java Quiz. ... The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods.
🌐
Scientech Easy
scientecheasy.com › home › blog › keywords in java | list of keywords
Keywords in Java | List of Keywords - Scientech Easy
April 2, 2025 - The keywords const and goto are reserved but not used. In addition to these keywords, Java reserves the following: null, true, and false. These are values that are defined by Java language. We may not use these words for the names of classes, variables, methods, and so on.
🌐
Scribd
scribd.com › document › 818740502 › 4
Java Keywords: Comprehensive List | PDF | Class (Computer Programming) | Method (Computer Programming)
The document provides a comprehensive list of 51 reserved keywords in Java, which cannot be used as variable names or identifiers. Each keyword is accompanied by its usage and functionality within the Java programming language.
🌐
ThoughtCo
thoughtco.com › reserved-words-in-java-2034200
Reserved Words in Java
January 27, 2019 - This is a full list of the 53 keywords reserved in Java that cannot be used as object or variable names.
🌐
GitHub
github.com › e3b0c442 › keywords
GitHub - e3b0c442/keywords: A list and count of keywords in programming languages.
A list and count of keywords in programming languages. - e3b0c442/keywords
Starred by 265 users
Forked by 26 users
Languages   Go
🌐
Wikipedia
en.wikipedia.org › wiki › List_of_Java_keywords
List of Java keywords - Wikipedia
October 20, 2025 - Defines a character variable capable of holding any character of the Java source file's character set. ... A type that defines the implementation of a particular kind of object. A class definition defines instance and class fields, methods, and inner classes as well as specifying the interfaces the class implements and the immediate superclass of the class. If the superclass is not explicitly specified, the superclass is implicitly Object. The class keyword can also be used in the form Class.class to get a Class object without needing an instance of that class.
🌐
W3Schools
w3schools.com › java › java_ref_keywords.asp
Java Keywords
Access Modifiers Non-Access Modifiers Java Encapsulation Java Packages / API Java Inheritance Java Polymorphism Java super Keyword Java Inner Classes Java Abstraction Java Interface Java Anonymous Java Enum ... Java Data Structures Java Collections Java List Java ArrayList Java LinkedList Java List Sorting Java Set Java HashSet Java TreeSet Java LinkedHashSet Java Map Java HashMap Java TreeMap Java LinkedHashMap Java Iterator Java Algorithms