\documentstyle{article}
\begin{document}

\raggedright

\begin{center}
{\Large\bf
Notes on Java Syntax.
}
~\\
Burton Rosenberg\\
July 20, 1998
\end{center}

~\\

\noindent
{\bf 
Class declarations:} 
\begin{itemize}
\item[]
{\em class-modifiers} {\bf class }{\em class-identifier}
	\begin{itemize}
	\item[] [{\bf extends} {\em class-name}]
	\item[] [{\bf implements} {\em interface-name [, interface-name]*}]
	\item[] {\bf \{}
	\item[] \begin{itemize}\item[]{\em class-body}\end{itemize}
	\item[] {\bf \}}
	\end{itemize}
\end{itemize}

\noindent
Notes:
\begin{itemize}
\item A file contains one class declaration, and is the same name as the public class.
\item {\em class-modifiers} are {\bf public, abstract, final}, or none.
\item {\em class-identifier} is a name, by convention beginning with an upper-case letter.
\item The super-class of this class is named in the optional {\bf extends} clause.
A class extends java.lang.Object by default.
\item Any interfaces the class implements are named in the optional {\bf implements} clause.
\item Class body include {\em field declarations, method declarations,}\/
and {\em constructor declarations,}\/ among others. These have
{\em  class scope}.
\end{itemize}

\noindent
{\bf
Field declarations:}
\begin{itemize}
\item[]
{\em field-modifiers}
{\em type}
{\em variable-declarator
[, variable-declarator]*}
{\bf ;}
\end{itemize}

\noindent
Notes:
\begin{itemize}
\item {\em field-modifiers} include the visibility modifiers
{\bf public, protected, private}; {\bf static} for class variables
; {\bf final} for constants, or none.
\item If a field is not static, then it is an instance variable.
\item If the field has no visibility modifier, than it has {\em package scope}.
\item {\em Variable-declarators} are of the form {\em variable-identifier}
or 
\begin{itemize}\item[]
{\em variable-identifier} {\bf =} {\em variable-intializer}.\end{itemize} 
Scalars are initialized by an expression. Arrays are initialized
using the syntax
\begin{itemize}\item[]
{\bf \{} {\em expression, expression, ...} {\bf \}}.\end{itemize}
\end{itemize}

\noindent
{\bf
Method declarations:}
\begin{itemize}
\item[]
{\em method-modifiers}
{\em result-type}
\begin{itemize}
\item[] {\em method-identifier} {\bf (}{\em formal-parameters} {\bf )}
\item[]
[{\bf throws} {\em exception-name [, exception-name]*}]
\item[]
{\bf \{}
\item[] \begin{itemize}\item[]{\em method-body}\end{itemize}
\item[]
{\bf \}}
\end{itemize}
\end{itemize}

\noindent
Notes:
\begin{itemize}
\item {\em Method-modifiers} include the visibility modifiers
{\bf public, protected, private}; {\bf static} for class methods
; {\bf final} for methods which cannot be overriden; {\bf synchronized} and
{\bf abstract}; or none.
\item If a method is not static, then it is an instance method.
\item If the method has no visibility modifier, than it has {\em package scope}.
\item If the method is {\bf abstract}, the {\em method-body,}\/ including the braces,
is replace with a semi-colon.
\item The {\em return-type} is either a type or {\bf void}.
\item The {\em method-body} is a series of {\em statements}, 
including {\em local-varaible-declarations.}
\end{itemize}

\noindent
{\bf
Constructor declarations:}
\begin{itemize}
\item[]
{\em constructor-modifiers} {\em class-identifier} {\bf (}{\em formal-parameters} {\bf )}
\begin{itemize}\item[]
[{\bf throws} {\em exception-name [, exception-name]*}]
\item[]
{\bf \{}
\item[] \begin{itemize}\item[]{\em constructor-body}\end{itemize}
\item[]
{\bf \}}
\end{itemize}
\end{itemize}

\noindent
Notes:
\begin{itemize}
\item {\em constructor-modifiers} include are the visibility modifiers
{\bf public, protected, private}, or none.
\item The {\em constructor-identifier} must be the class name. The constructor has no return type,
not even void.
\item If the constructor has not visibility modifier, than it has {\em package scope.}
\item If no constructors are defined, a default, no argument constructor is automatically
provided.
\item Constructors are not inherited from the super-class.
\item The {\em constructor-body} is a series of {\em statements}, 
including {\em local-variable-declarations.}
\end{itemize}

\noindent
{\bf
Statements:}
\begin{itemize}
\item
{\em expression} {\bf ;}
\item
{\bf if (} {\em expression } {\bf )}
	%\begin{itemize}
	\item[] {\bf \{} 
	\begin{itemize}
	\item[]{\em statements}
	\end{itemize}
	\item[] {\bf \}}
	\item[] [ {\bf else \{ }
	\begin{itemize}
	\item[]{\em statements}
	\end{itemize}
	\item[] {\bf \}}]
	%\end{itemize}
\item
{\bf while (} {\em expression} {\bf )}
	%\begin{itemize}
	\item[] {\bf \{}
	\begin{itemize}
	\item[] {\em statements}
	\end{itemize}
	\item[] {\bf \}}
	%\end{itemize}
\item
{\bf do }
	\item[] {\bf \{}
	\begin{itemize}
	\item[] {\em statements}
	\end{itemize}
	\item[] {\bf \}}
	\item[] {\bf while (} {\em expression} {\bf ) ;}
\item
{\bf switch (} {\em expression} {\bf )}
	\item[] {\bf \{}
	\item[] {\bf case} {\em constant} {\bf :} {\em statements}
	\item[] [ {\bf default: } {\em statements} ]
	\item[] {\bf \}}
\item
{\bf for ( } {\em local-variable-declaration or expr.} {\bf ; }
{\em expr.} {\bf ; } {\em expr. } {\bf )}
	\item[] {\bf \{}
	\begin{itemize}\item[] {\em statements}\end{itemize}
	\item[] {\bf \}}
\item
{\em label } {\bf : } {\em statement }
\item
{\bf break } [{\em label}] {\bf ;}
\item
{\bf continue } [{\em label}] {\bf ;}
\item
{\bf return } [{\em expression}] {\bf ;}
\item
{\bf throw } {\em expression} {\bf ;}
\item 
{\bf synchronized ( } {\em expression} {\bf )}
	\item[] {\bf \{}
	\begin{itemize}\item[] {\em statements} \end{itemize}
	\item[] {\bf \}}
\item
{\bf try \{}
	\begin{itemize}\item[] {\em statements} \end{itemize}
	\item[] {\bf \}}
	\item[] {\bf catch ( } {\em formal-parameter} {\bf ) \{}
	\begin{itemize}\item[] {\em statements} \end{itemize}
	\item[] {\bf \}}
	\item[] [{\bf catch ( } {\em formal-parameter} {\bf ) \{}
	\begin{itemize}\item[] {\em statements} \end{itemize}
	\item[] {\bf \}}]*
	\item[] {\bf finally \{}
	\begin{itemize}\item[] {\em statements} \end{itemize}
	\item[] {\bf \}}]
\end{itemize}

\noindent
Notes:
\begin{itemize}
\item The expressions in the if, while and do-while statements must evaluate to type boolean,
as must the middle expression in the for statement.
\item The expression in the switch statement must be of type char, byte, short or int.
\item The expression in the throw statement must be throwable.
\item The expression in the synchronized statement must be a reference type.
\end{itemize}

\noindent
{\bf
Local variable declarations:}
\begin{itemize}
\item[]
{\em type}
{\em variable-identifier} [{\bf = } {\em variable-initializer} ]
\begin{itemize}\item[]
[{\bf ,} {\em variable-identifier} [{\bf = } {\em variable-initializer}]]*
{\bf ;}
\end{itemize}
\end{itemize}

\noindent
{\bf
Formal parameters:}
\begin{itemize}
\item[]
{\em type variable-identifier}
[{\bf ,} {\em type variable-identifier}]*
\end{itemize}

\noindent
{\bf
Type:}
\begin{itemize}
\item[]
{\em primitive-type or reference-type }
{\bf []}*
\end{itemize}

\noindent
Notes:
\begin{itemize}
\item The primitive types are: {\bf boolean},
the integer types {\bf byte, short, int, long, char},
and the floating-point types {\bf float, double}.
\item Reference types is any type which is not primitive, including classes, interfaces,
and arrays.
\item Arrays are of array type, and can be cast to Object.
\end{itemize}

\noindent
{\bf
Expressions:}
\begin{itemize}
\item
Literal
\item
{\em Identifier[.name]*}
\item
{\em expression} {\bf [} {\em expression} {\bf ]}
\item
{\em expression}{\bf (} {\em expression, expression ... } {\bf )}
\item
{\bf (} {\em expression } {\bf)}
\item
{\em prefix-operation expression}
\item
{\em expression postfix-operation}
\item
{\em expression operation expression}
\item
{\bf (} {\em type} {\bf )} {\em expression}
\item
{\bf (} {\em expression} {\bf) ?} {\em expression} {\bf : } {\em expression} {\bf ;}
\item
{\bf this}
\item {\bf new} {\em class-identifier} {\bf (} {\em expression, expression, ...
} {\bf )}
\item {\bf new} {\em primitive-type} {\bf []} {\bf []}*
\end{itemize}

\noindent
Notes:
\begin{itemize}
\item Literals include: integer (e.g. 1, 03, 0xff), floating-point (e.g.
\verb:1.0, 1.0e-3:), boolean ({\bf true, false}), character (e.g. \verb.'a'.),
string (e.g. \verb."hi".), and {\bf null}.
\item Operations include assignment (e.g. \verb.=., \verb.+=., etc.);
short-circuit conditional; equality and relational (e.g. \verb.==., \verb.!=., \verb.>.);
bitwise logical; arithmetic including remainder (\verb.%.);
unary pre-/post- increment/decrement; string concatentation using \verb.+.;
shift operators.
\item
The right-shift \verb.>>. sign-extends. The right-shift \verb.>>>. zero-fills. Two operations
are needed since all Java integral types are signed. 
\item There are no derefernce (\verb.*.) or address-of (\verb.&.) operators in Java.
\end{itemize}

\noindent
{\bf Packages:}
\begin{itemize}
\item {\bf package} {\em package-name} {\bf ;}
\item {\bf import} {\em fully-qualified-type-name} {\bf ;}
\item {\bf import} {\em package-name}{\bf.* ;}
\end{itemize}

\noindent
Notes:
\begin{itemize}
\item The import of java.lang.* is automatic.
\item Import-on-demand syntax uses a * to import all public types in a package
\item These must be the first non-comment lines in the file.
\end{itemize}

\end{document}
