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 › 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").
🌐
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....
🌐
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
🌐
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...
🌐
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 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 :)

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.

Top answer
1 of 3
2

Classes don't have keyword "new" as a personal method or anything like that. It is the Java language itself that has the keyword "new". So in other words you put "new" in the code the compiler would recognize it and instantiate a new Object.

http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.9- this link is the documentation of Java language, in section 3.9 it shows all the keywords.

Edit: Like others are saying, what the snippet of code in your question indicates an inner class, so for instance, like it says in http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html

public class ShadowTest {

public int x = 0;

class FirstLevel {

    public int x = 1;

    void methodInFirstLevel(int x) {
        System.out.println("x = " + x);
        System.out.println("this.x = " + this.x);
        System.out.println("ShadowTest.this.x = " + ShadowTest.this.x);
    }
}

public static void main(String... args) {
    ShadowTest st = new ShadowTest();
    ShadowTest.FirstLevel fl = st.new FirstLevel();
    fl.methodInFirstLevel(23);
}
}

The following is the output of this example:

x = 23
this.x = 1
ShadowTest.this.x = 0

This shows that the innerclass or class B(FirstLevel) is like or similar to the outer class's variables and methods(for it is associated with the instance of the outer class) of class A(ShadowTest).

2 of 3
0

As all the languages ,Java has Keywords. Here the new keyword is used for initialization purposes.here the object of the class A is initialised in the first statement. in second statement the object of class B is initialised with class A's object A

🌐
Oracle
docs.oracle.com › en › database › other-databases › nosql-database › 21.1 › java-driver-table › supported-keywords-query-methods.html
Java Direct Driver Developer's Guide
Previous Next JavaScript must be enabled to correctly display this content ... The following is the list of supported keywords for prefix in the dynamic query method name.
🌐
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
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 keyword but is a reserved word.
🌐
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.
🌐
Coderanch
coderanch.com › t › 323883 › java › Checking-SQL-Oracle-reserved-words
Checking for SQL/Oracle reserved words in java applications (Java in General forum at Coderanch)
Can anyone recommend a way in which my standalone java application can validate fields to ensure that SQL Server/ Oracle reserved words are not used. Would using a stored procedure (sp_validname) be the best way? This will result in a dependancy on SQLServer/Oracle running.