Here is the array of all the Java reserved keywords (taken from here and keep being updated from here):

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"
};

You have to navigate to the library where is Hashtable class using the JAVA_HOME system variable.

System.getenv("JAVA_HOME");

The java.util.Hashtable (and others) is located at %JAVA_HOME%/jre/lib/rt.jar library.

You have to find a way to extract the package, find the required file, decompile it and read lane by lane (using f.e. Regex). I recommend you to start reading answers of this question.

Unfortunately, there is NO other way.

Answer from Nikolas on Stack Overflow
🌐
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. true, false, and null might seem like keywords, but they are actually literals; you cannot use them as identifiers in your programs. ... Copyright © 1995, 2024 Oracle ...
🌐
Oracle
docs.oracle.com › cd › E13226_01 › workshop › docs81 › pdf › files › workshop › JavaKeywordReference.pdf pdf
Java Language Keywords
boolean Java Keyword.......................................................................................................................................4
🌐
Oracle
docs.oracle.com › javase › specs › jls › se17 › html › jls-3.html
Chapter 3. Lexical Structure
September 16, 2025 - The tokens are the identifiers (§3.8), keywords (§3.9), literals (§3.10), separators (§3.11), and operators (§3.12) of the syntactic grammar. Programs are written using the Unicode character set (§1.7). Information about this character set and its associated character encodings may be found at https://www.unicode.org/. The Java ...
🌐
Oracle
oracle.com › java › technologies
Glossary - Java
... An act whereby one entity assumes ... place. Impersonation is a case of simple delegation. ... A Java keyword included in the class declaration to specify any interfaces that are implemented by the current class....
🌐
Oracle
docs.oracle.com › javase › specs › jls › se16 › preview › specs › contextual-keywords-jls.html
Contextual Keywords
September 16, 2025 - This document describes changes to the Java Language Specification to clarify the use of context when applying the lexical grammar, particularly in the identification of contextual keywords (formerly described as "restricted identifiers" and "restricted keywords").
🌐
Wikipedia
en.wikipedia.org › wiki › List_of_Java_keywords
List of Java keywords - Wikipedia
October 20, 2025 - The abstract keyword cannot be used with variables or constructors. Note that an abstract class isn't required to have an abstract method at all. ... Assert describes a predicate (a true–false statement) placed in a Java program to indicate that the developer thinks that the predicate is always true at that place.
🌐
Javatpoint
javatpoint.com › java-keywords
Java Keywords - Javatpoint
Java Database Connectivity with 5 Steps · Connectivity with Oracle · Connectivity with MySQL · Access without DSN · DriverManager · Connection · Statement · ResultSet · PreparedStatement · ResultSetMetaData · DatabaseMetaData · Store image · Retrieve image ·
Find elsewhere
🌐
W3Schools
w3schools.com › java › java_ref_keywords.asp
Java Keywords
Variables Print Variables Multiple Variables Identifiers Constants (Final) Real-Life Examples Java Data Types · Data Types Numbers Booleans Characters Real-Life Example Non-primitive Types The var Keyword Java Type Casting Java Operators
Top answer
1 of 2
4

DO NOT build SQL queries using string concatenation - you should be using bind parameters.

Your query string should be:

query="select * from books where BookName LIKE ?";

and then you can do something like:

Class.forName( "oracle.jdbc.OracleDriver" ); // If you are using the Oracle driver.

Connection con = DriverManager.getConnection(
  "jdbc:oracle:thin:@localhost:1521:XE",
  "username",
  "password"
);

final String query="select * from books where BookName LIKE ?";
PreparedStatement ps = conn.prepareStatement(query);            
ps.setString( 1, "%" + txt1.getText() + "%" );
ResultSet rs = ps.executeQuery();
// Loop through the result set.
// Close statement/connections

(you will need to handle exceptions, etc.)

and:

  • You should not need to change the query to swap between MySQL and Oracle (just change the driver and connection string).
  • You do not need to escape any single or double quotation marks in the input string.
  • You are protected from SQL injection attacks.
  • Oracle can cache the query with the bind parameter and does not have to re-parse / re-compile it when the bind parameter changes.

If you are going to write the query as a string then string literals are surrounded by single quotes (not double quotes) in SQL:

query="select * from books where BookName LIKE '%your_string%'";

and you need to make sure that any single quotes in your string are properly escaped (but just use a bind parameter instead).

2 of 2
0

problem solved with this..

query="select * from books where BookName LIKE '%" +txt1.getText()+"%'";

thanks everyone :)

🌐
Quora
quora.com › Why-did-Oracle-introduce-the-var-keyword-to-Java-and-when-is-it-appropriate-to-use
Why did Oracle introduce the `var` keyword to Java, and when is it appropriate to use? - Quora
Answer (1 of 4): This is a popular feature in many languages. It is called type inference. Most modern languages have it: C#, modern C++, kotlin, swift, go, rust. It is also a polarizing feature, many people think it is evil and should never be used. It makes the code more readable when you decl...
🌐
YouTube
youtube.com › associative
Oracle Java 17 Keywords - YouTube
#oracle #java #javaprogramming #javadeveloper #java17 #javalts #fullstackjavadeveloper #javafullstackdeveloper #javadevelopment #javafullstack #javajobs #jav...
Published   July 19, 2023
🌐
University of North Carolina
cs.unc.edu › ~weiss › COMP14 › 18-JavaKeyWords.html
Java Keywords or Reserved Words (52)for jdk1.4
Keywords for catch-exception are: try catch finally throw · Keywords for loops or decision-makers are: break case continue default do while for switch if else · Keywords for class functions are: class extends implements import instanceof new package return interface this throws void super ·
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.

🌐
Oracle
docs.oracle.com › javase › tutorial › java › javaOO › thiskey.html
Using the this Keyword (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
From within a constructor, you can also use the this keyword to call another constructor in the same class. Doing so is called an explicit constructor invocation.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-keywords
Java Keywords - GeeksforGeeks
August 27, 2018 - As of Java 21, there are 53 keywords, categorized below by their usage and purpose.
🌐
GitHub
github.com › querydsl › querydsl › issues › 2225
Incorrect Reserved Word Set for Oracle · Issue #2225 · querydsl/querydsl
September 9, 2017 - I traced the cause to the Keywords.ORACLE field, which loads the "oracle" text file as a resource. The link at the top of that resource calls out an Oracle 10g doc, but I don't think that doc is an appropriate reference, as it pertains to the Oracle Enterprise Manager.
Published   Nov 30, 2017
🌐
Oracle
oracle.com › technical resources › topics
Java Technology Terminology
The loop's exit condition can be specified with the while keyword. ... Document Object Model. A tree of objects with interfaces for traversing the tree and writing an XML version of it, as defined by the W3C specification. ... A Java keyword used to define a variable of type double.
🌐
Oracle
docs.oracle.com › javase › specs › jls › se7 › html › index.html
The Java® Language Specification
September 16, 2025 - Java SE > Java SE Specifications > Java Language Specification