Reputation: 125
Is it possible with the Java System Library to get all Java keywords like for,while, etc. in a HashTable etc.
Or do i need to write them all down by myself?
I want to scan a String for the keywords.
Upvotes: 2
Views: 140
Reputation: 44496
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.
Upvotes: 3
Reputation: 359
A list of Java keywords can be found in the Java documentation: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html
With a list like this, you can create a String array that you can search.
Upvotes: 0