This document gives a concise description of the Java programming language, version 1.1 and later.
It is a quick reference for the reader who has already learnt (or is learning) Java from a standard
textbook and who wants to know the language in more detail.
The document presents general rules (on left-hand pages), and corresponding examples (on righthand
pages). All examples are fragments of legal Java programs. The complete examples are available
at the book website; see below.
It is a quick reference for the reader who has already learnt (or is learning) Java from a standard
textbook and who wants to know the language in more detail.
The document presents general rules (on left-hand pages), and corresponding examples (on righthand
pages). All examples are fragments of legal Java programs. The complete examples are available
at the book website; see below.
Running Java: compilation, loading, and execution
Before a Java program can be executed, it must be compiled and loaded. The compiler checks that
the Java program is legal: that the program conforms to the syntax (grammar) for Java programs,
that operators (such as +) are applied to the correct type of operands (such as 5 and x), etc. If so, the
compiler generates so-called class files. Execution then starts by loading the needed class files.
Thus running a Java program involves three stages: compilation (checks that the program is
well-formed), loading (loads and initializes classes), and execution (runs the program code).
Names and reserved names
A legal name (of a variable, method, field, parameter, class, or interface) must start with a letter or
dollar sign ($) or underscore (_), and continue with zero or more letters or dollar signs or underscores
or digits (0–9). Do not use dollar signs in class names. Java is case sensitive: upper case letters are
distinguished from lower case letters. A legal name cannot be one of the following reserved names:
abstract boolean break byte case catch char class const continue
default do double else extends false final finally float for goto if
implements import instanceof int interface long native new null
package private protected public return short static strictfp super switch
synchronized this throw throws transient true try void volatile while
Java naming conventions
The following naming conventions are often followed in Java programs, although not enforced by
the compiler:
If a name is composed of several words, then each word (except possibly the first one) begins
with an upper case letter. Examples: setLayout, addLayoutComponent.
Names of variables, fields, and methods begin with a lower case letter. Examples: vehicle,
currentVehicle.
Names of classes and interfaces begin with an upper case letter. Examples: Layout, FlowLayout.
Named constants (that is, final variables and fields) are written entirely in upper case (and the
parts of composite names are separated by underscores _). Examples: CENTER, MAX_VALUE.
A package name is a sequence of dot-separated lower case names. Example: java.awt.event.
.
.
ไม่มีความคิดเห็น:
แสดงความคิดเห็น