Notes on Java Syntax.

Burton Rosenberg
July 20, 1998

  1. Class declarations:
    class-modifiers class class-identifier
    	[extends class-name]
    	[implements interface-name [, interface-name]*]
    	{
    	   class body
    	}
    

  2. Field declarations:
    field-modifiers type variable-declarator [, variable-declarator]* ;
    
  3. Method declarations:
    method-modifiers result-type method-identifier
        ( formal-parameters )
        [throws exception-name [, exception-name]*]
        {
            method body
        }
    

  4. Constructor declarations:
    constructor-modifiers class-identifier ( formal-parameters )
        [throws exception-name [, exception-name]*]
        {
           constructor body
        }
    

  5. Statements
    expression ;
    
    if ( expression )
    {
        statments
    }
    [else {
        statements
    }]
    
    while ( expression )
    {
         statements
    }
    
    do {
       statements
    } while ( expression ) ;
    
    switch ( expression )
    {
        case constant : statments
        [case constant : statments]*
        [ default: statements ]
    }
    
    
    for ( local-variable-declarator or expression ;
        expression ; expression )
    {
        statments
    }
    
    label : statment
    
    break ;
    
    continue ;
    
    return expression ;
    
    throw expression ;
    
    synchronized ( expression ) 
    {
        statements 
    }
    
    try {
        statemnts
    }
    catch ( formal-parameter ) {
       statements
    }
    [catch ( formal-parameter ) {
        statements
    } ]*
    [finally {
        statements
    }]
    

  6. Local variable declarations:
    type variable-identifier [=  variable-initializer ]
        [, variable-identifier [= variable-initializer]]*
        ;
    

  7. Formal parameters:
    type variable-identifier [, type variable-identifier]*
    

  8. Type:
    primitive-type or reference-type []*
    

  9. Expressions:
    Literal
    
    Identifier[.name]*
    
    expression [ expression ]
    
    expression( expression, expression ... )
    
    ( expression )
    
    prefix-operation expression
    
    expression postfix-operation
    
    expression operation expression
    
    ( type ) expression
    
    ( expression ) ? expression : expression ;
    
    this
    
    new class-identifier ( expression, expression, ... )
    
    new primitive-type [] []*
    

  10. Packages:
    package package-name ;
    
    import fully-qualified-type-name ;
    
    import package-name.* ;