コンテンツにスキップ

Javaの文法

出典: フリー百科事典『ウィキペディア(Wikipedia)』

これはこのページの過去の版です。Hsz (会話 | 投稿記録) による 2007年2月17日 (土) 19:59個人設定で未設定ならUTC)時点の版 (en:Java syntax(07:08, 8 February 2007 Quuxplusone)を翻訳)であり、現在の版とは大きく異なる場合があります。

(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)

Java言語文法はJavaプログラムを記述し解釈する方法を定義するルールの集合である。

データ構造

Although the language has special syntax for them, arrays and strings are not primitive types: they are reference types that can be assigned to java.lang.Object.

基本データ型

整数型
byte 8-bit 符号付き
short 16-bit 符号付き
int 32-bit 符号付き
long 64-bit 符号付き
浮動小数点数型
float 32-bit 符号付き
double 64-bit 符号付き
  • 浮動小数点数は決して例外をスローしない
  • 0(ゼロ)で割った値はInf(無限大)と等値である
  • Infで割った値は0(ゼロ)と等値である。
文字
char 16-bit 符号無しUnicode
ブール代数
boolean true または false
  • falseは0(ゼロ)またはnulを表現することはできない
  • trueは非ゼロを表現することはできない
  • boolean型から非boolean型へのキャストとその逆はできない
プリミティブラッパークラス
使用法
  • 値はある型から他の型へと変換できる
  • 参照に対して基本データ型を渡して使用できる
その他
  • メソッドへは値渡しとなる。
  • デフォルトでは0、nullまたはfalseに初期化される。
整数
8進数 0365, 0[0..7]*
16進数 0xF5, 0x[0..9, A..F, a..f]*
10進数 245, [1..9][0..9]*
浮動小数点数
float 23.5F, 23.5f; 1.72E3F, 1.72E3f, 1.72e3F, 1.72e3f
double 23.5, 23.5D, 23.5d; 1.72E3, 1.72E3D, ...
文字リテラル
char 'a', 'Z', '\u0231'
文字列リテラル
String "Hello, world"
エスケープシーケンス
Unicode文字 \u 16進数Unicode文字を表現するときに使用する
タブ文字 \t
後退(Backspace)文字 \b
キャリッジリターン(復帰文字) \r
改ページ \f
バックスラッシュ \\
シングルクォーテーション(単一引用符) \'
ダブルクォーテーション(二重引用符) \"
ラインフィード(改行文字) \n

文字列

文字列

  • Stringオブジェクトはイミュータブルである
  • Stringオブジェクトは生成時に初期化されなければならない
  • コンパイラが文字列リテラル (ダブルクォーテーションで囲まれた文字列)を見つけたとき、Stringオブジェクトが生成される
  • 演算子 "+" と "+=" は文字列を連結するためにオーバーロードされる
String str1 = "alpha"; 
String str2 = new String("alpha");

StringBufferとStringBuilder

  • StringBufferStringBuilderオブジェクトは可変である
  • StringもStringBufferもどちらももう一方から派生したものではない
StringBuffer str1 = new StringBuffer("beta");
StringBuffer str2 = new StringBuffer(50);
  • Javaはプリミティブ型クラスインタフェースそれぞれの配列型はもちろん、配列の多次元配列をも持つ。
  • すべての配列要素は同じ型を引き継がなければならない。
  • すべての配列クラスはクラスjava.lang.Objectを引き継ぎ、それらを含む型階層を反映する。
  • 配列オブジェクトは配列要素の数を持っている読み取り専用のlength属性を持つ。
  • 配列は実行時に領域確保される。それで配列生成宣言するときの配列のサイズは可変である(むしろ、Cでは定数表現)。
  • Java配列は一次元である。多次元配列は言語サポートされているが、配列の配列として扱われる。
// Declare the array - name is "myArray", element type is references to "SomeClass"
SomeClass[] myArray = null;
// Allocate the array
myArray = new SomeClass[10];
// Or Combine the declaration and array creation
SomeClass[] myArray = new SomeClass[10];
// Allocate the elements of the array (not needed for simple data types)
for (int i = 0; i < myArray.length; i++)
    myArray[i] = new SomeClass();

国際化サポート

言語はbyte文字型とを見分ける。文字は内部でUCS-2で保存されるが、J2SE 5.0以降は、言語はUTF-16とそのサロゲートもサポートする。JavaプログラムソースはそれゆえUnicode文字を持つ。

以下にこのような正しいJavaコードを示す。文字列リテラルだけでなくクラスと変数名にも日本語を使うことができる:

public class こんにちは世界 {
    private String 文字列 = "こんにちは世界";
}

演算子

計算

二項演算子
文法 意味
+ 加算
- 減算
* 乗算
/ 除算
% 剰余 (整数の余りを返す)
単項演算子
文法 意味
- 単項マイナス (符号反転)
++ インクリメント (変数の前か後につけることができる)
-- デクリメント (変数の前か後につけることができる)
! ブール補数演算
~ ビット単位反転
(type) キャスト

代入

文法 意味
= 代入
+= 加算と代入
-= 減算と代入
*= 乗算と代入
/= 除算と代入
%= 剰余と代入
&= ビット演算 ANDと代入
|= ビット演算 ORと代入
^= ビット演算 XORと代入
<<= 左シフト(ゼロ埋め)と代入
>>= 右シフト (符号伝達と代入)
>>>= 右シフト (ゼロ埋め) と代入

比較

文法 意味
== 同値
!= 否定
> 大なり
>= 大なりイコール
< 小なり
<= 小なりイコール
instanceof ~のインスタンス

参照型を使うとき、同値演算子(==!=)は参照値を比較し、参照オブジェクトの比較を含まない–比較演算子は、二つの参照が同じオブジェクト(またはnull)を参照しようが、二つのオブジェクトが等価であろうとテストする。.equals(Object)メソッドはオブジェクトの内容を比較するために使われる。instanceof演算子はオブジェクトがクラスのインスタンスであるかどうかを判定するために使われる。

条件式

条件式は複合?:演算子を使用する。三項演算子とも呼ぶ。文法:

condition ? expression1 : expression2

条件conditionの評価は、それがtrueであるとき、条件式は式expression1の値を持ち、そうでない場合は条件式はexpression2の値を持つ。

例:

String answer = (p < 0.05)? "reject" : "keep";
// これは以下のコードと等価である:
String answer;
if (p < 0.05)
  answer = "reject";
else
  answer = "keep";

ブール代数

  • 短絡回路論理演算(結果が判定するまでオペランドを左から右へと評価する)
  • 必要なだけ最小数の式を評価する
  • 部分計算 (むしろ完全評価(計算))
文法 意味
&& AND (左のオペランドがfalseのとき、式はfalseを返し右のオペランドは評価されない)
|| OR (左のオペランドがtrueのとき、式はtrueを返し右のオペランドは評価されない)
! NOT (論理否定)
二項演算子
& AND (完全評価ではブール演算子として使われる)
| OR (完全評価ではブール演算子として使われる)
^ XOR
<< 左シフト (ゼロ埋め)
>> 右シフト (符号伝達)
>>> 右シフト (ゼロ埋め)
単項演算子
~ NOT (ビット反転)

文字列演算子

Syntax Meaning
+ 連結
+= 連結と代入

制御構造

If ... else

if (expr) {
    statements;
}
else if (expr) {
    statements;
}
else {
    statements;
}
  • The expr value must evaluate to a boolean value so for example "if(String a1 == String a2)" will not evaluate

to true even if they are equal, but instead it will compare values, not its boolean equivalent. Instead use "if(String a1.equals(String a2))" or a instance of comparison.

Switch文

switch (expr) {
    case VALUE: 
        statements;
        break;
    case VALUE: 
        statements;
        break;
    default:
        statements;
        break;
}
  • The expr value must be a byte, short, int, or char.
  • Each case value must be a unique literal value; variables cannot be used.

Forループ

for (initial-expr; cond-expr; incr-expr) {
    statements;
}

For-each ループ

J2SE 5.0 added a new feature called the for-each loop, which greatly simplifies the task of iterating through every element in a collection. Without the loop, iterating over a collection would require explicitly declaring an iterator:

public int sumLength(Set<String> stringSet) {
  int sum = 0;
  Iterator<String> itr = stringSet.iterator();
  while (itr.hasNext())
    sum += itr.next().length();
  return sum;
}

The for-each loop greatly simplifies this method:

public int sumLength(Set<String> stringSet) {
  int sum = 0;
  for (String s : stringSet)
    sum += s.length();
  return sum
}

This loop is read as, for each String in stringSet, add the length to sum.

Whileループ

while (expr) {
    statements;
}

Do ... while

do {
    statements;
} while (expr);

分岐文

文法 意味
break; Break from the innermost enclosing loop immediately.
continue; Continue on to the next iteration of the loop.
break LABEL Jump to the statement immediately after the labeled statement (terminate the labeled statement).
continue LABEL Jump to the labeled statement (restart a labeled statement or continue execution of a labeled loop)

例:

int sum = 0;
int i = 1;
while (i < 10) {
    if (i == 3) {
        continue;  // Skip the rest of this loop iteration.
    }
    sum += i;
                          
    if (sum > 15) {
        break;  // Exit the loop.
    }
}

ラベル

  • Consists of an identifier followed by a colon
  • Used to identify the statement or block of code that the jump statements refer to
  • If the label is omitted, the jump statements refer to the innermost enclosing loop

LABEL1: statement;
LABEL2: { statements; }

注、"goto" 文について

The "goto" statement is a reserved keyword in Java, however, it does not have any function in the Java Programming Language.

オブジェクト

クラス

Java has nested classes that are declared within the body of another class or interface. A class that is not a nested class is called a top level class. An inner class is a non-static nested class.

Classes can be declared with the following modifiers:

  • abstract – cannot be instantiated. Only interfaces and abstract classes may contain abstract methods. A concrete (non-abstract) subclass that extends an abstract class must override any inherited abstract methods with non-abstract methods. Cannot be final.
  • final – cannot be subclassed. All methods in a final class are implicity final. Cannot be abstract.
  • strictfp – all floating-point operations within the class and any enclosed nested classes use strict floating-point semantics. Strict floating-point semantics guarantee that floating-point operations produce the same results on all platforms.

Note that Java classes do not need to be terminated by a semicolon (";"), which is required in C++ syntax.

継承

// ChildClass inherits from ParentClass
class ChildClass extends ParentClass { ... }  
  • The default parent of a class is the Object class.
  • A class can only extend a single parent class (no multiple inheritance of implementation).

スコープ

  • this – Reference to the current subclass (assumed by default) (i.e. this.someMethod()).
  • super – Reference to the parent class (i.e. super.someMethod()). Can be used in a subclass to access inherited methods that the subclass has overridden or inherited fields that the subclass has hidden.

インタフェース

An interface is an abstract class with no implementation details. Its purpose is to define how a set of classes will be used. Classes that implement a common interface can be used interchangeably within the context of the interface type. Interfaces also help to enforce the concept of abstraction—hiding the details of how a class is implemented.

An interface can only contain abstract methods and static final fields. Interface methods are public and abstract by default (unimplemented), and interface fields are public, static and final by default.

Java does not support full orthogonal multiple inheritance. Multiple inheritance in C++ has complicated rules to disambiguate fields and methods inherited from multiple superclasses and types inherited multiple times. By separating interface from implementation, interfaces offer much of the benefit of multiple inheritance with less complexity and ambiguity. The price of no multiple inheritance is some code redundancy; since interfaces only define the signature of a class but cannot contain any implementation, every class inheriting an interface must provide the implementation of the defined methods, unlike in pure multiple inheritance, where the implementation is also inherited.

Java interfaces behave much like the concept of the Objective-C protocol.

インタフェースの実装

A class can implement one or more interfaces using the implements keyword, in addition to extending another class.

interface MyInterface {
    void foo();
}
interface Interface2 {
    void bar();
}
class MyClass implements MyInterface {
    void foo() {...}
    ...
}
class ChildClass extends ParentClass implements MyInterface, Interface2 {
    void foo() {...}
    void bar();
    ...
}

In the following example,

public interface Deleteable {
    void delete();
}

any non-abstract class that implements the Deleteable interface must define a non-abstract method named delete that has no parameters and a void return type. The implementation and function of the method are determined by each class. There are many uses for this concept, for example:

public class Fred implements Deleteable {
    // This method satisfies the Deleteable interface
    public void delete() {
        // Code implementation goes here
    }
    public void someOtherMethod() {
    }
}
public void deleteAll(Deleteable[] list) {
    for (int i = 0; i < list.length; i++) {
        list[i].delete();
    }
}

Because any objects in the above array are guaranteed to have the delete() method, the deleteAll() method needn't differentiate between the Fred objects or any other Deleteable objects.

インタフェースの継承

An interface can extend one or more interfaces using the extends keyword.

interface ChildInterface extends ParentInterface, AnotherInterface {
    ...
}

A class that implements the resulting interface must define the combined set of methods.

public interface MyInterface {
    foo();
}
public interface Interface2 extends MyInterface {
    bar();
}
public class MyClass implements Interface2 {
    void foo() {...}
    void bar() {...}
    ...
}

アクセス修飾子

Access modifiers determine which code may access classes and class members.

トップレベルクラスアクセス

  • public – accessible outside the package in which it's defined.
  • default – accessible only within the package in which it's defined.

クラスメンバアクセス

Class members are fields, methods, constructors and nested classes declared within the body of a class. In order of increasing restrictions on access, the access modifiers for class members are:

  • public – accessible by any class.
  • protected – accessible within the class; by any derived class; and by other classes within the package.
  • default – accessible by any class within the package.
  • private – accessible only within the class (includes access from within enclosed inner classes). Members that are declared private are not inherited by subclasses.

When overriding a method, the method access modifier can't be made more restrictive—to do so would break the interface contract of the parent class. Thus when overridden, a public method must be declared public and a protected method cannot be given default access. However, it is permissible to override a method to make it more accessible. Thus when overriding, a default (package) access method can be declared as protected or public and a protected method can be declared as public.

フィールド

In addition to the access modifiers, data fields may be declared with the following modifiers:

  • final – the value cannot be changed. Must be initialized exactly once. A final field declared without an initializer is a blank final field—a static blank final field must be definitively initialized by a static initializer; a non-static blank final field must be initialized during the execution of each and every constructor. Cannot be volatile.
  • static – belongs to the class, rather than to an instance of the class.
  • transient – not a part of the persistent state of an object. The value should not be saved and later restored.
  • volatile – informs the compiler that it may be accessed by separate threads asynchronously. Cannot be final.

定数

Fields that are declared as both static and final are effectively constants; static means there is one occurrence of the field associated with the class, and final means that the field is assigned a value exactly once.

初期化子

Initializers are blocks of code that are executed at the same time as initializers for fields.

スタティックイニシャライザ

Static initializers are blocks of code that are executed at the same time as initializers for static fields. Static field initializers and static initializers are executed in the order declared. The static initialization is executed after the class is loaded.

static int count = 20;
static int[] squares;
static {  // a static initializer
    squares = new int[count];
    for (int i = 0; i < count; i++)
        squares[i] = i * i;
}
static int x = squares[5];  // x is assigned the value 25

インスタンスイニシャライザ

Instance initializers are blocks of code that are executed at the same time as initializers for instance (non-static) fields. Instance field initializers and instance initializers are executed in the order declared.

Both instance initializers and instance field initializers are executed during the invocation of a constructor. The initializers are executed immediately after the superclass constructor and before the body of the constructor.

メソッド

In addition to the access modifiers, methods may be declared with the following modifiers:

  • abstract – the method is undefined in the class, and must be defined by any concrete (non-abstract) subclass. Cannot be static, final or native.
  • final – the method cannot be redefined in a subclass. For instance (non-static) methods, this allows the compiler to expand the method (similar to an inline function) if the method is small enough. Cannot be abstract.
  • native – the method links to native machine-dependent code. Declared without a body. Cannot be abstract.
  • static – belongs to the class, rather than to an instance of the class. Cannot be abstract.
  • strictfp – all floating-point operations in the method and enclosed inner classes use strict floating-point semantics. Strict floating-point semantics guarantee that floating-point operations produce the same results on all platforms.
  • synchronized – causes the current thread to acquire the lock for the associated object before executing the body of the method. If the lock is currently held by another thread, the current thread will block until the lock is released and the thread is able to obtain the lock. The associated object is the Class object for static methods and the object instance for non-static methods. While it is allowed to declare an abstract method as synchronized, it is meaningless to do so since synchronization is an aspect of the implementation, not the declaration, and abstract methods do not have an implementation.

Note that a private method can't be abstract and is implicitly final.

可変引数

Java SE 5.0 added syntactic support for methods with a variable number of arguments (varargs) [1], which simplifies the typesafe usage of methods requiring a variable number of arguments. The last parameter can be followed with ..., and Java will box all the arguments into an array:

public void drawPolygon (Point... points) {…}

When calling the method, a programmer can simply separate the points by commas, without having to explicitly create an array of Point objects. Within the method, the points can be referenced as points[0], points[1], etc. If no points are passed, the array has a length of zero. To require the programmer to use a minimum number of parameters, those parameters can be specified before the variable argument:

// A polygon needs at least 3 points.
public void drawPolygon (Point p1, Point p2, Point p3, Point... otherPoints) {…}

コンストラクタ

A constructor is called to initialize an object immediately after the object has been allocated. Typically, a constructor is invoked using the new keyword, although constructors can also be invoked using reflection provided by the java.lang.reflect package.

The access modifiers are the only modifiers that may be used for declaring constructors.

  • When possible, the object should be a valid, meaningful object once it is constructed, as opposed to relying on a separate initialization method.
  • By convention, a copy constructor is a constructor that accepts an object of its own type as a parameter and copies the data members.
  • If no explicit constructor is defined, then the compiler provides an implicit empty default constructor that takes no parameters.
  • Constructors can be overloaded.
  • The first statement in a constructor may invoke a superclass constructor: super(...); or another constructor in the same class: this(...);
  • If there is no explicit call to super(...) or this(...), then the default superclass constructor super(); is called before the body of the constructor is executed.

Objectクラスのメソッド

Methods in the Object class are inherited, and thus shared in common by all classes.

cloneメソッド

The Object.clone() method returns a new object that is a copy of the current object. Classes must implement the marker interface Cloneable to indicate that they can be cloned.

equalsメソッド

The Object.equals(Object) method compares the object to another object and returns a boolean result indicating if the two objects are equal. Semantically, this method compares the contents of the objects whereas the equality comparison operator "==" compares the object references. The equals method is used by many of the data structure classes in the java.util package. Some of these data structure classes also rely on the Object.hashCode method—see the hashCode method for details on the contract between equals and hashCode.

finalizeメソッド

The Object.finalize() method is called exactly once before the garbage collector frees the memory for object. A class overrides finalize to perform any clean up that must be performed before an object is reclaimed. Most objects do not need to override finalize.

There is no guarantee when the finalize method will be called, or the order in which the finalize method will be called for multiple objects. If the JVM exits without performing garbage collection, the OS may free the objects, in which case the finalize method doesn't get called.

The finalize method should always be declared protected to prevent other classes from calling the finalize method.

protected void finalize() throws Throwable { ... }

getClassメソッド

The Object.getClass() method returns the Class object for the class that was used to instantiate the object. The class object is the base class of reflection in Java. Additional reflection support is provided in the java.lang.reflect package.

hashCodeメソッド

The Object.hashCode() method returns an integer (int) that is used as a hash code for storing the object in an associative array. Classes that implement the java.util.Map interface provide associative arrays and rely on the hashCode method. A good hashCode implementation will return a hash code that is stable (does not change) and evenly distributed (the hash codes of unequal objects tend to be unequal and the hash codes are evenly distributed across integer values).

Because associative arrays depend on both the equals and hashCode methods, there is an important contract between these two methods that must be maintained if the objects are to be inserted into a Map:

For two objects a and b
  • a.equals(b) == b.equals(a)
  • if a.equals(b) then a.hashCode() == b.hashCode()

In order to maintain this contract, a class that overrides the equals method must also override the hashCode method, and vice versa, so that hashCode is based on the same properties (or a subset of the properties) as equals.

A further contract that the map has with the object is that the results of the hashCode and equals methods will not change once the object has been inserted into the map. For this reason, it is generally a good practice to base the hash function on immutable properties of the object.

toStringメソッド

The Object.toString() method returns a String that contains a text representation of the object. The toString method is implicitly called by the compiler when an object operand is used with the string concatenation operators (+ and +=).

wait と notifyスレッドシグナルメソッド

Every object has two wait lists for threads associated with it. One wait list is used by the synchronized keyword to acquire the mutex lock associated with the object. If the mutex lock is currently held by another thread, the current thread is added to the list of blocked threads waiting on the mutex lock. The other wait list is used for signaling between threads accomplished through the wait and notify and notifyAll methods.

Use of wait/notify allows efficient coordination of tasks between threads. When one thread needs to wait for another thread to complete an operation, or needs to wait until an event occurs, the thread can suspend its execution and wait to be notified when the event occurs. This is in contrast to polling, where the thread repeatedly sleeps for a short period of time and then checks a flag or other condition indicator. Polling is both more computationally expensive, as the thread has to continue checking, and less responsive since the thread won't notice the condition has changed until the next time to check.

waitメソッド

There are three overloaded versions of the wait method to support different ways to specify the timeout value: wait(), wait(long timeout) and wait(long timeout, int nanos). The first method uses a timeout value of zero (0), which means that the wait does not timeout; the second method takes the number of milliseconds as a timeout; the third method takes the number of nanoseconds as a timeout, calculated as 1000000 * timeout + nanos.

The thread calling wait is blocked (removed from the set of executable threads) and added to the object's wait list. The thread remains in the object's wait list until one of three events occurs:

  1. another thread calls the object's notify or notifyAll method (see the notify methods below for details);
  2. another thread calls the thread's interrupt() method; or
  3. a non-zero timeout that was specified in the call to wait expires.

The wait method must be called inside of a block or method synchronized on the object. This insures that there are no race conditions between wait and notify. When the thread is placed in the wait list, the thread releases the object's mutex lock. After the thread is removed from the wait list and added to the set of executable threads, it must acquire the object's mutex lock before continuing execution.

notifynotifyAllメソッド

The Object.notify() and Object.notifyAll() methods remove one or more threads from an object's wait list and add them to the set of executable threads. notify removes a single thread from the wait list, while notifyAll removes all threads from the wait list. Which thread is removed by notify is unspecified and dependent on the JVM implementation.

The notify methods must be called inside of a block or method synchronized on the object. This insures that there are no race conditions between wait and notify.

入出力

See also: Java Platform, Standard Edition#java.io and New I/O

Versions of Java prior to J2SE 1.4 only supported stream-based blocking I/O. This required a thread per stream being handled, as no other processing could take place while the active thread blocked waiting for input or output. This was a major scalability and performance issue for anyone needing to implement any Java network service. Since the introduction of NIO (New I/O) in J2SE 1.4, this scalability problem has been rectified by the introduction of a non-blocking I/O framework (though there are a number of open issues in the NIO API as implemented by Sun).

The non-blocking IO framework, though considerably more complex than the original blocking IO framework, allows any number of "channels" to be handled by a single thread. The framework is based on the Reactor Pattern.

実行コード

アプリケーション

public class MyClass {
    public static void main (String[] args) {...}
    ...
}

アプレット

  • Java code that runs in a web browser, in a designated display area
  • init and destroy are only called once, but start and stop are called as many times as the user visits the web page.
// MyApplet.java
import java.applet.*;
public class MyApplet extends Applet {
    init() {...}     // Called when the browser first loads the applet.
    destroy() {...}  // Called when the user quits the browser.
    start(){...}     // Called when the applet starts running.
    stop() {...}     // Called when the user leaves the web page,
                     // reloads it, or quits the browser.
}
<applet code="MyApplet" width=200 height=200>
</applet>

appletタグの埋め込み

  • The HTML applet tag can be embedded in the applet source code.
  • Inclusion of the applet tag allows the applet to be run directly by a simple applet viewer, without the need for an .html file.
  • Typically, the applet tag immediately follows the import statements.
  • It must be enclosed by /* */ comments.
// MyApplet.java
...
/*
<applet code="MyApplet" width="200" height="200">
</applet> 
*/
...

サーブレット

  • Java code that runs on a Web server, with the output (generally HTML or XML) typically sent to a Web browser.
  • Servlets are the Java equivalent to CGI programming.

JSP (JavaServer Pages)

  • Java code that's embedded in a Web page
  • JSP tags are processed on a Web server; the resulting output (generally HTML or XML) is sent to the client.
  • JSP code is compiled into a Java Servlet before it's run.
  • JSP is an extension of Java Servlets.
  • The usage of JSP tags is comparable to the usage of PHP or ASP tags.

JSPタグ

文法 意味
<% Java構文 %> スクリプトレット
<%= 単一Java構文の出力 %> 構文
<%! Java宣言文 %> 宣言
<%@ [page, include, taglib] JSPディレクティブ %> ディレクティブ

その他

ケースセンシビティ(大文字小文字区別)

Javaはケースセンシティブ(大文字小文字を区別する)である。

コメント

// 一行コメント
/* 複数行
   コメント */
/**
 * この行はクラス、インタフェース、メソッド、データメンバ宣言の直前に記述する。
 * このコメントはクラスのドキュメンテーションを自動生成する
 * ユーティリティで使用することができる。
 */

関連項目

参考文献

外部リンク

サン・マイクロシステムズ