0% found this document useful (0 votes)
2 views14 pages

Java Compilation Unit Syntax Guide

This document contains syntax diagrams that describe the structure and grammar of the Java programming language. It shows the different elements that make up Java programs including classes, interfaces, methods, fields, and other language constructs. The diagrams use shapes like rectangles and ovals to represent literal keywords and further definitions in other diagrams.

Uploaded by

Mouhamad Bazzi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views14 pages

Java Compilation Unit Syntax Guide

This document contains syntax diagrams that describe the structure and grammar of the Java programming language. It shows the different elements that make up Java programs including classes, interfaces, methods, fields, and other language constructs. The diagrams use shapes like rectangles and ovals to represent literal keywords and further definitions in other diagrams.

Uploaded by

Mouhamad Bazzi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

This appendix contains syntax diagrams that collectively describe the way in

which Java language elements can be constructed. Rectangles indicate something


that is further defined in another syntax diagram, and ovals indicate a literal
word or character.
L

java syntax
Compilation Unit

Package Declaration Import Declaration Type Declaration

Package Declaration

package Name ;

Import Declaration

import Name . Identifier ;

Type Declaration

Class Declaration
Interface Declaration
748 APPENDIX L java syntax

Class Declaration

class Identifier Class Associations Class Body


Modifier

Class Associations

extends Name implements Name List

Class Body

{ }
Class Member

Class Member

Field Declaration
Constructor Declaration
Method Declaration
Class Declaration
Interface Declaration

static Block

Interface Declaration

interface Identifier Interface Body


Modifier extends Name List

Interface Body

{ }
Interface Member

Interface Member

Field Declaration
Method Declaration
Class Declaration
Interface Declaration
APPENDIX L java syntax 749

Field Declaration

Type Variable Declarator ;


Modifier ,

Variable Declarator

Identifier
= Expression
Array Initializer

Type

Primitive Type

Name [ ]

Modifier Primitive Type

public boolean
private char
protected byte
static short
final int
abstract long
native float
synchronized double
transient
volatile

Array Initializer

{ }
Expression
Array Initializer

Name
Name List

Identifier
Name
.
,
750 APPENDIX L java syntax

Method Declaration

Type Identifier Parameters Throws Clause Method Body


Modifier void

Parameters

( )
Type Identifier

Throws Clause

throws Name List

Method Body

Block
;

Constructor Declaration

Identifier Parameters Throws Clause Constructor Body


Modifier

Constructor Body

{ }
Constructor Invocation Block Statement

Constructor Invocation

this Arguments ;

super Arguments
Expression .
APPENDIX L java syntax 751

Block

{ }
Block Statement

Block Statement

Local Variable Declaration ;

Statement

Class Declaration

Local Variable Declaration

Type Variable Declarator


final
,

Statement

Block
Statement Expression
Basic Assignment
If Statement
Switch Statement
While Statement
Do Statement
For Statement
Return Statement
Throw Statement
Try Statement
Synchronized Statement
Empty Statement
Break Statement
Continue Statement
Labeled Statement
752 APPENDIX L java syntax

If Statement

if ( Expression ) Statement

else Statement

Switch Statement

switch ( Expression ) { }
Switch Case

Switch Case

case Expression :
Block Statement
default :

While Statement

while ( Expression ) Statement

Do Statement

do Statement while ( Expression ) ;

For Statement

for ( ; ; ) Statement
For Init Expression For Update

For Init For Update

Local Variable Declaration Statement Expression


,
Statement Expression
,
APPENDIX L java syntax 753

Basic Assignment

Identifier = Expression ;

Return Statement

return ;
Expression

Throw Statement

throw Expression ;

Try Statement

try Block catch ( Type Indentifier ) Block

finally Block

Synchronized Statement

synchronized ( Expression ) Block

Empty Statement

Break Statement

break ;
Identifier

Continue Statement

continue ;
Identifier

Labeled Statement

Identifier : Statement
754 APPENDIX L java syntax

Expression

Primary Expression
Assignment
Arithmetic Expression
Equality Expression
Relational Expression
Logical Expression
Bitwise Expression
Conditional Expression
Instance Expression
Cast Expression
Unary Expression

Primary Expression

Literal
Primary Suffix
Name

this

super . Identifier

( Expression )

Allocation

Primary Suffix

. Identifier

. this

. class
. Allocation

[ Expression ]

Arguments
APPENDIX L java syntax 755

Arguments

( )
Expression
,

Allocation

new Primitive Type Array Dimensions


Array Initializer
Name
Arguments
Class Body

Array Dimensions

[ Expression ]
[ ]

Statement Expression

Assignment ;
Prefix Expression
Postfix Expression

Assignment

Expression = Expression
+=
-=
*=
/=
%=
<<=
>>=
>>>=
&=
^=
|=
756 APPENDIX L java syntax

Arithmetic Expression

Expression + Expression
-
*
/
%

Equality Expression

Expression == Expression
!=

Relational Expression

Expression < Expression


>
<=
>=

Logical Expression

Expression && Expression


||

Bitwise Expression

Expression & Expression


|
^
<<
>>
>>>

Conditional Expression

Expression ? Expression : Expression

Instance Expression

Expression instanceOf Type

Cast Expression

( Type ) Expression
APPENDIX L java syntax 757

Unary Expression Prefix Expression

Prefix Expression ++ Expression

Postfix Expression --

+ Expression
Postfix Expression
-
! Expression ++
~ --

Literal

Integer Literal
Floating Point Literal
Character Literal
String Literal
Boolean Literal
null

Integer Literal

Decimal Integer Literal


Octal Integer Literal
Hex Integer Literal

Decimal Integer Literal

0
1-9 0-9 L
l

Octal Integer Literal Hex Digit

0 0-7 0-9
L a-f
l A-F

Hex Integer Literal

0 X Hex Digit
L
x
l
758 APPENDIX L java syntax

Floating Point Literal

0-9 .

. 0-9 Exponent Part

0-9 Float Suffix

Exponent Part Float Suffix

e 0-9 f
E + F
- d
D

Character Literal Boolean Literal

' any character ' true


Escape Sequence false
Unicode Escape

String Literal

" "
any character
Escape Sequence
Unicode Escape

Escape Sequence

\ n
t
b
r
f
\
'
"
0-3 0-7 0-7
APPENDIX L java syntax 759

Identifier

Java Letter
Java Letter
Java Digit

Java Letter

a-z
A-Z
_
$
*
other Java letter
Unicode Escape

* The "other Java letter" category includes letters


from many languages other than English.

Java Digit

0-9
*
other Java digit
Unicode Escape

* The "other Java digit" category includes


additional digits defined in Unicode.

Unicode Escape*

\ u Hex Digit Hex Digit Hex Digit Hex Digit

* In some contexts, the character represented


by a Unicode Escape is restricted.

You might also like