「1.1. 仕様の構成」の編集履歴(バックアップ)一覧に戻る

1.1. 仕様の構成 - (2012/09/02 (日) 22:10:09) の編集履歴(バックアップ)


1. はじめに

1.1. 仕様の構成

2章では、言語の字句と構文文法を表す文法と表記法を記述します。

3章では、CやC++に基づいて、Javaプログラミング言語の字句構造を記述します。言語はUnicode文字セットで記述します。言語はASCIIのみをサポートするシステム上でもUnicode文字をサポートします。

4章では、型や値や変数について記述します。型はプリミティブ型と参照型に分けられます。
プリミティブ型は全てのマシンと全ての実装で同一なものが定義されており、多様なサイズの2の補数の整数や、単精度・倍精度IEEE754規格浮動小数点数、boolean型、Unicode文字char型が定義されています。プリミティブ型はステートを共有しません(1箇所からしか見えない)。
参照型はクラス型やインタフェース型や配列型です。参照型はクラスのインスタンスか配列のいずれかの動的作成オブジェクトによって実装されています。一つのオブジェクトに対し複数から参照することが可能です。全てのオブジェクト(配列を含む)はクラス階層の(唯一の)ルートであるObjectクラスのメソッドをサポートします。組込みStringクラスはUnicode文字列をサポートします。プリミティブ値をオブジェクト内にラッピングするためのクラスがあります。多くの場合、ラッピング・ラッピング解除はコンパイラによって自動的に実行されます(この場合、ラッピングをボックス化、ラッピング解除をボックス化解除と呼びます)。クラスとインタフェース宣言はジェネリックであっても構いません。つまり、それらは他の参照型による引数付きがなされていても構いません。そのような宣言は通常特定の型引数を伴って呼び出します。
変数とは型付けされた記憶領域です。プリミティブ型の変数は同じプリミティブ型の値を保持します。クラス型の変数はヌル参照か型がそのクラス型かそのクラスの任意のサブクラスであるオブジェクトへの参照を保持できます。インタフェース型の変数はヌル参照かそのインタフェースを実装する任意のクラスのインスタンスへの参照を保持することができます。配列型の変数はヌル参照か配列への参照を保持することができます。Objectクラス型の変数はヌル参照かクラスインスタンスや配列のどちらのオブジェクトへの参照も保持できます。

5章では、変換と数値昇格について記述します。変換はコンパイル時の型を、場合によっては式の値も変更します。この変換にはプリミティブ型と参照型の間のボックス化・ボックス化解除変換が含まれます。数値昇格は数値演算子のオペランドを演算が実行される共通型へと変換するためのものです。Javaには抜け穴はありません。参照型のキャストは型の安全性が確保されているか実行時に検査されます。

6章では、宣言と名前、名前が何を意味するものかを決定する方法について記述します。Javaでは型やメンバーを使う前にそれらが定義されている必要はありません。宣言の順序は局所変数や局所クラス、クラスやインスタンス内のフィールドの初期化子の順序の場合のみ重要です。
Javaプログラミング言語は名前のスコープに対する制御を提供しており、パッケージやクラスやインタフェースのメンバーに対する外部アクセスの制限をサポートしています。これは巨大なプログラムを書く際に型の実装をそれを使用する人や拡張する人から独立させることができます。プログラムを読みやすくする標準的な名前付けもここで記述します。

7章では、Modulaのモジュールに似たパッケージで構成される、プログラムの構造を記述します。パッケージのメンバーはクラスとインタフェースとサブパッケージです。パッケージはコンパイル単位に分割されます。コンパイル単位は型宣言を含み短い名前を与えて他のパッケージから型をインポートすることができます。パッケージは階層構造の名前空間内に名前を持ち、一意なパッケージ名を与えるためにインターネットのドメインネームシステムを使用することができます。

8章では、クラスについて記述します。クラスのメンバーはクラスやインタフェースやフィールド(変数)やメソッドです。クラス変数はクラスにつき1つ存在します。クラスメソッドは特定のオブジェクトへの参照なし動作します。インスタンス変数はクラスのインスタンスであるオブジェクト内に動的に作成されます。インスタンスメソッドはクラスのインスタンス上で呼び出されます。そのようなインスタンスはその実行中に現オブジェクトthisとなり、オブジェクト指向プログラミングスタイルをサポートします。
クラスは実装の単一継承をサポートします。個々のクラスの実装は単一のスーパークラスの実装、究極的にはクラスObjectから継承されます。クラス型の変数はそのクラスまたは、新しい型が既存のメソッドで使用することができるよう、そのクラスのサブクラスのインスタンスを多相的に参照することができます。
クラスはsynchronizedメソッドにより並行プログラミングをサポートします。メソッドは実行時に発生する検査済み例外を宣言します。これにより例外条件の処理が確実に行っているかコンパイル時に検査されます。オブジェクトはガーベージコレクターによってオブジェクトが解放される前に呼び出されるfinalizeメソッドを宣言します。これによりオブジェクトがそのステートを綺麗に片づけることができます。
簡単化のため、言語はそのクラスの実装から分離した"ヘッダー"宣言を持たなく、型とクラスの階層構造も持ちません。

クラスの特別形の1つ、列挙子は値の小集合の定義と型安全な記述によるその運用をサポートします。他の言語の列挙子と異なり、Javaの列挙子はオブジェクトでそれ自身メソッドを持ちます。

Chapter 9 describes interface types, which declare a set of abstract methods, member types, and constants. Classes that are otherwise unrelated can implement the same interface type. A variable of an interface type can contain a reference to any object that implements the interface. Multiple interface inheritance is supported.

Annotation types are specialized interfaces used to annotate declarations. Such annotations are not permitted to affect the semantics of programs in the Java programming language in any way. However, they provide useful input to various tools.

Chapter 10 describes arrays. Array accesses include bounds checking. Arrays are dynamically created objects and may be assigned to variables of type Object. The language supports arrays of arrays, rather than multidimensional arrays.

Chapter 11 describes exceptions, which are nonresuming and fully integrated with the language semantics and concurrency mechanisms. There are three kinds of exceptions: checked exceptions, run-time exceptions, and errors. The compiler ensures that checked exceptions are properly handled by requiring that a method or constructor can result in a checked exception only if the method or constructor declares it. This provides compile-time checking that exception handlers exist, and aids programming in the large. Most user-defined exceptions should be checked exceptions. Invalid operations in the program detected by the Java virtual machine result in run-time exceptions, such as NullPointerException. Errors result from failures detected by the Java virtual machine, such as OutOfMemoryError. Most simple programs do not try to handle errors.

Chapter 12 describes activities that occur during execution of a program. A program is normally stored as binary files representing compiled classes and interfaces. These binary files can be loaded into a Java virtual machine, linked to other classes and interfaces, and initialized.

After initialization, class methods and class variables may be used. Some classes may be instantiated to create new objects of the class type. Objects that are class instances also contain an instance of each superclass of the class, and object creation involves recursive creation of these superclass instances.

When an object is no longer referenced, it may be reclaimed by the garbage collector. If an object declares a finalizer, the finalizer is executed before the object is reclaimed to give the object a last chance to clean up resources that would not otherwise be released. When a class is no longer needed, it may be unloaded.

Chapter 13 describes binary compatibility, specifying the impact of changes to types on other types that use the changed types but have not been recompiled. These considerations are of interest to developers of types that are to be widely distributed, in a continuing series of versions, often through the Internet. Good program development environments automatically recompile dependent code whenever a type is changed, so most programmers need not be concerned about these details.

Chapter 14 describes blocks and statements, which are based on C and C++. The language has no goto statement, but includes labeled break and continue statements. Unlike C, the Java programming language requires boolean (or Boolean) expressions in control-flow statements, and does not convert types to boolean implicitly (except through unboxing), in the hope of catching more errors at compile time. A synchronized statement provides basic object-level monitor locking. A try statement can include catch and finally clauses to protect against non-local control transfers.

Chapter 15 describes expressions. This document fully specifies the (apparent) order of evaluation of expressions, for increased determinism and portability. Overloaded methods and constructors are resolved at compile time by picking the most specific method or constructor from those which are applicable.

Chapter 16 describes the precise way in which the language ensures that local variables are definitely set before use. While all other variables are automatically initialized to a default value, the Java programming language does not automatically initialize local variables in order to avoid masking programming errors.

Chapter 17 describes the semantics of threads and locks, which are based on the monitor-based concurrency originally introduced with the Mesa programming language. The Java programming language specifies a memory model for shared-memory multiprocessors that supports high-performance implementations.

Chapter 18 presents a syntactic grammar for the language.
目安箱バナー