Is there any package to store the set of java keywords


Where All the Keywords are stored in java? Is there any package to store the set of keywords(predefined thing) Because these are not related to any "Classes(capital C), but "class"(small c) itself is a keyword, and all primitive types,all specifiers, interface are keywords. but where they are stored? Definitely not in any Class(they must have defined in some package or somewhere) but where??


It is doubtful that all keywords are stored somewhere in the java <em>runtime</em> library, as they are not needed there.
Where they are needed, however, is in the compiler.

After giving the JDK langtools repo a quick look, I found that:


com.sun.tools.javac.antlr.Java.g4 (A text file)
Contains a list of keywords:

// §3.9 Keywords ABSTRACT : 'abstract'; ASSERT : 'assert'; BOOLEAN : 'boolean'; BREAK : 'break'; BYTE : 'byte'; CASE : 'case'; CATCH : 'catch'; CHAR : 'char'; CLASS : 'class'; CONST : 'const'; CONTINUE : 'continue'; DEFAULT : 'default'; DO : 'do'; DOUBLE : 'double'; ELSE : 'else'; ENUM : 'enum'; EXTENDS : 'extends'; FINAL : 'final'; FINALLY : 'finally'; FLOAT : 'float'; FOR : 'for'; IF : 'if'; GOTO : 'goto'; IMPLEMENTS : 'implements'; IMPORT : 'import'; INSTANCEOF : 'instanceof'; INT : 'int'; INTERFACE : 'interface'; LONG : 'long'; NATIVE : 'native'; NEW : 'new'; PACKAGE : 'package'; PRIVATE : 'private'; PROTECTED : 'protected'; PUBLIC : 'public'; RETURN : 'return'; SHORT : 'short'; STATIC : 'static'; STRICTFP : 'strictfp'; SUPER : 'super'; SWITCH : 'switch'; SYNCHRONIZED : 'synchronized'; THIS : 'this'; THROW : 'throw'; THROWS : 'throws'; TRANSIENT : 'transient'; TRY : 'try'; VOID : 'void'; VOLATILE : 'volatile'; WHILE : 'while';

I'm unsure whether that file is also included in the distributed javac, and thus could be retrieved at run time.

</li> <li>com.sun.tools.javac.parser.Tokens (A normal java class)
Contains a subclass enum TokenKind, which holds all tokens.
While these could definitely be retrieved at run time, they also include operators, an end-of-file representation, etc., so you'd have to filter them first.</li> </ul>

In theory, there is no need for the Java runtime environment, where your compiled code runs, to keep the keywords. Once compiled, all the code becomes bytecode. A private method, for example, would be marked by a flag rather than the string of letters p-r-i-v-a-t-e. A for loop would be represented by some byte code that sets the initial value of the variable, performs the operation, increments the value, checks the condition, and jumps back to the beginning of the operation. No need for the three letters f-o-r to be stored anywhere for this.

However, standard Java does have a class in the runtime library which contains all of the Java keywords - the SourceVersion enum in the javax.lang.model package. This enum has a method which accepts a CharSequence and checks whether it is a keyword in the latest release of Java (the running version, obviously).

The javax.lang.model package is offered for purposes of modeling the Java language. For example, it's being used by programs that process annotations or by programs that themselves compile Java programs.

The SourceVersion enum <em>stores</em> all the keywords, but it doesn't make them available to you. The API merely allows you to check if a string is a keyword or not.



  • Can I check which function templates have, or have not, been instantiated at least once?
  • Force repaint after button click
  • Firefox overriding style of html select option
  • How do I position a div relative to the mouse pointer exactly when scroll page?
  • Add missing rows within combinations of factors
  • jQuery update image src on hover
  • Keep play application running after putty terminal closed
  • Upload synthesized speech from firebase function node.js server's tmp directory
  • Isabelle matrix arithmetic: det_linear_row_setsum in library with different notation
  • Intersection of characters in two strings
  • how to change the black color to Red with opencv python
  • Unable to generate cucumber reports in jenkins. net.masterthought.cucumber.ValidationException: None
  • Caffe : train network accuracy = 1 constant ! Accuracy issue
  • Multiple git user in single device
  • List using with references, changes behavior when used as a member
  • Send HTML Mail with Unicode
  • programatically send a form with POST
  • Immutability and synchronization in Java
  • Complex multiple if statements
  • Align microsoft access queries
  • How to reduce a DAG by replacing each longest non-branching path by an edge connecting the start and
  • How to debug iBeacons and Passbook
  • Custom progress dialog not working
  • Convert current tmux session to configuration file
  • Videos won't upload
  • SpringBoot don't replacen System variable {user.home} in Spring Tool Suite Version: 3.8.4.RELEA
  • Populating a database table with returned JSON
  • jQuery Ajax call to WCF service returning “Method not allowed (405)”
  • Yii Bootstrap not loading JS files
  • Modifying native query cannot have named parameter bindings?
  • Adding native code to an existing Worklight hybrid app
  • PHP: Need to close STDIN in order to read STDOUT?
  • Swift manually rotate view controller
  • Multiplying polynomials/simplifying like terms
  • java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/SpringDispatcher-ser
  • PHPMailer return to AJAX
  • Error handeling in antlr 3.0
  • Will this work on all screen sizes?
  • Debug `Unexpected end of JSON input Error` on content script
  • Codeigniniter insert data through models and controller