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, double

  • The boolean type

The reference types are

  • Classes such as String or Employee

  • Enumeration types such as enum Sex { FEMALE, MALE }

  • Interfaces such as Comparable

  • Array types such as Employee[] or int[][]

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 ...

Get Big Java, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.