Appendix E. Java Syntax Summary
In this syntax summary, we use a monospaced font for actual Java reserved words and tokens such as while. An italic font denotes language constructs such as condition or variable. Items enclosed in brackets [ ] are optional. Items separated by vertical bars | are alternatives. Do not include the brackets or vertical bars in your code!
The summary reflects the parts of the Java language that were covered in this book. For a full overview of the Java syntax, see .http://java.sun.com/docs/books/jls/
As always, please be careful to distinguish an ellipsis ... from the ... token. The latter appears twice in this appendix in the "variable parameters" discussion in the "Methods" section.
Types
A type is a primitive type or a reference type. The primitive types are
The numeric types
int, long, short, char, byte, float, doubleThe
booleantype
The reference types are
Classes such as
StringorEmployeeEnumeration types such as
enum Sex { FEMALE, MALE }Interfaces such as
ComparableArray types such as
Employee[]orint[][]
Variables
Local variable declarations have the form
[final]Type variableName[=initializer];
Examples:
double x = 0;
String harry = "Harry Handsome";
Rectangle box = new Rectangle(5, 10, 20, 30);
int[] a = { 1, 4, 9, 16, 25 };The variable name consists only of letters, numbers, and underscores. It must begin with a letter or underscore. Names are case-sensitive: totalscore, TOTALSCORE, and totalScore are three different variables.
The scope of a local ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access