A Simplified Grammar for Java

The following is a simplified grammar for the Java language, written using BNF notation and taken from the official Java site at java.sun.com. In particular, the following BNF notations are used:

The grammar has been simplified for pedagogical purposes to avoid many of the more complex aspects of the Java language that we won't need to understand until later. It nevertheless covers a fairly large portion of Java and should be useful as an adjunct to the smaller quotations in the text (esp. starting in Chapter 5). (Some of the language features which have been eliminated are: generics, type arguments and type parameters (Java 1.5 features); enumerated constants (a Java 1.5 feature); conditional expressions; instanceOf, exceptions, annotations, interfaces, inner classes, labelled statements, synchronization and assertions; and the "this", "super" and "default" keywords.)

Some of the important broad syntactic categories ("phrase types") in the Java language are:

Finally, here is a list of keywords which have special significance in Java (you shouldn't use these for variable, method or class names):

abstract     assert     boolean     break     byte     case     catch     char     class     const     continue     default    

do     double     else     extends     final     finally     float     for     goto     if     implements     import    

instanceof     int     interface     long     native     new     package     private     protected     public     return     short    

static     strictfp     super     switch     synchronized     this     throw     throws     transient     try     volatile     void     while