Java basic syntax

Source: Internet
Author: User
    Identifier:
        IDENTIFIER

    QualifiedIdentifier:
        Identifier { . Identifier }

    Literal:
        IntegerLiteral     
        FloatingPointLiteral     
        CharacterLiteral     
        StringLiteral     
        BooleanLiteral
        NullLiteral

    Expression: 
        Expression1 [AssignmentOperator Expression1]]

    AssignmentOperator: 
        = 
        += 
        -= 
        *= 
        /= 
        &= 
        |= 
        ^= 
        %= 
        <<= 
        >>= 
        >>>= 

    Type: 
        Identifier {   .   Identifier } BracketsOpt
        BasicType

    StatementExpression: 
        Expression

    ConstantExpression: 
        Expression

    Expression1: 
        Expression2 [Expression1Rest]

    Expression1Rest: 
        [  ?   Expression   :   Expression1]

    Expression2 : 
        Expression3 [Expression2Rest]

    Expression2Rest: 
        {Infixop Expression3}
        Expression3 instanceof Type

    Infixop:
        || 
        && 
        | 
        ^ 
        & 
        == 
        != 
        < 
        > 
        <= 
        >= 
        << 
        >> 
        >>> 
        + 
        - 
        * 
        / 
        % 

    Expression3: 
        PrefixOp Expression3
        (   Expr | Type   )   Expression3
        Primary {Selector} {PostfixOp}

    Primary: 
        ( Expression )
        this [Arguments]
        super SuperSuffix
        Literal
        new Creator
        Identifier { . Identifier }[ IdentifierSuffix]
        BasicType BracketsOpt .class
        void.class

    IdentifierSuffix:
        [ ( ] BracketsOpt   .   class | Expression ])
        Arguments
        .   ( class | this | super Arguments | new InnerCreator )

    PrefixOp:
        ++ 
        -- 
        ! 
        ~ 
        + 
        - 

    PostfixOp: 
        ++ 
        -- 

    Selector: 
        . Identifier [Arguments]
        . this
        . super SuperSuffix
        . new InnerCreator
        [ Expression ]

    SuperSuffix: 
        Arguments 
        . Identifier [Arguments]

    BasicType: 
        byte 
        short 
        char 
        int 
        long 
        float 
        double 
        boolean

    ArgumentsOpt: 
        [ Arguments ]

    Arguments: 
        ( [Expression { , Expression }] )

    BracketsOpt: 
        {[]}

    Creator: 
        QualifiedIdentifier ( ArrayCreatorRest  | ClassCreatorRest )

    InnerCreator: 
        Identifier ClassCreatorRest

    ArrayCreatorRest: 
        [ ( ] BracketsOpt ArrayInitializer | Expression ] {[ Expression ]} 
    BracketsOpt )

    ClassCreatorRest: 
        Arguments [ClassBody]

    ArrayInitializer: 
        { [VariableInitializer {, VariableInitializer} [,]] }

    VariableInitializer: 
        ArrayInitializer
        Expression

    ParExpression: 
        ( Expression )

    Block: 
        { BlockStatements }

    BlockStatements: 
        { BlockStatement }

    BlockStatement : 
        LocalVariableDeclarationStatement
        ClassOrInterfaceDeclaration
        [Identifier :] Statement

    LocalVariableDeclarationStatement:
        [final] Type VariableDeclarators   ;  

    Statement:
        Block
        if ParExpression Statement [else Statement]
        for ( ForInitOpt   ;   [Expression]   ;   ForUpdateOpt ) Statement
        while ParExpression Statement
        do Statement while ParExpression   ; 
        try Block ( Catches | [Catches] finally Block )
        switch ParExpression { SwitchBlockStatementGroups }
        synchronized ParExpression Block
        return [Expression] ; 
        throw Expression   ; 
        break [Identifier]
        continue [Identifier]
        ; 
        ExpressionStatement
        Identifier   :   Statement

    Catches:
        CatchClause {CatchClause}

    CatchClause: 
        catch ( FormalParameter ) Block

    SwitchBlockStatementGroups: 
        { SwitchBlockStatementGroup }

    SwitchBlockStatementGroup: 
        SwitchLabel BlockStatements

    SwitchLabel: 
        case ConstantExpression   :
        default:  

    MoreStatementExpressions: 
        { , StatementExpression }

    ForInit: 
        StatementExpression MoreStatementExpressions
        [final] Type VariableDeclarators

    ForUpdate: 
        StatementExpression MoreStatementExpressions

    ModifiersOpt: 
        { Modifier }

    Modifier: 
        public 
        protected 
        private 
        static 
        abstract 
        final 
        native 
        synchronized 
        transient 
        volatile
        strictfp

    VariableDeclarators: 
        VariableDeclarator { ,   VariableDeclarator }

    VariableDeclaratorsRest: 
        VariableDeclaratorRest { ,   VariableDeclarator }

    ConstantDeclaratorsRest: 
        ConstantDeclaratorRest { ,   ConstantDeclarator }

    VariableDeclarator: 
        Identifier VariableDeclaratorRest

    ConstantDeclarator: 
        Identifier ConstantDeclaratorRest

    VariableDeclaratorRest: 
        BracketsOpt [  =   VariableInitializer]

    ConstantDeclaratorRest: 
        BracketsOpt   =   VariableInitializer

    VariableDeclaratorId: 
        Identifier BracketsOpt

    CompilationUnit: 
        [package QualifiedIdentifier   ;  ] {ImportDeclaration} 
    {TypeDeclaration}

    ImportDeclaration: 
        import Identifier {   .   Identifier } [   .     *   ] ;  

    TypeDeclaration: 
        ClassOrInterfaceDeclaration
        ;

    ClassOrInterfaceDeclaration: 
        ModifiersOpt (ClassDeclaration | InterfaceDeclaration)

    ClassDeclaration: 
        class Identifier [extends Type] [implements TypeList] ClassBody

    InterfaceDeclaration: 
        interface Identifier [extends TypeList] InterfaceBody

    TypeList: 
        Type {  ,   Type}

    ClassBody: 
        { {ClassBodyDeclaration} }

    InterfaceBody: 
        { {InterfaceBodyDeclaration} }

    ClassBodyDeclaration:
        ; 
        [static] Block
        ModifiersOpt MemberDecl

    MemberDecl:
        MethodOrFieldDecl
        void Identifier MethodDeclaratorRest
        Identifier ConstructorDeclaratorRest
        ClassOrInterfaceDeclaration

    MethodOrFieldDecl:
        Type Identifier MethodOrFieldRest

    MethodOrFieldRest:
        VariableDeclaratorRest
        MethodDeclaratorRest

    InterfaceBodyDeclaration:
        ; 
        ModifiersOpt InterfaceMemberDecl

    InterfaceMemberDecl:
        InterfaceMethodOrFieldDecl
        void Identifier VoidInterfaceMethodDeclaratorRest
        ClassOrInterfaceDeclaration

    InterfaceMethodOrFieldDecl:
        Type Identifier InterfaceMethodOrFieldRest

    InterfaceMethodOrFieldRest:
        ConstantDeclaratorsRest ;
        InterfaceMethodDeclaratorRest

    MethodDeclaratorRest:
            FormalParameters BracketsOpt [throws QualifiedIdentifierList] ( 
    MethodBody |   ;  )

    VoidMethodDeclaratorRest:
            FormalParameters [throws QualifiedIdentifierList] ( MethodBody |   ;  )

    InterfaceMethodDeclaratorRest:
        FormalParameters BracketsOpt [throws QualifiedIdentifierList]   ;  

    VoidInterfaceMethodDeclaratorRest:
        FormalParameters [throws QualifiedIdentifierList]   ;  

    ConstructorDeclaratorRest:
        FormalParameters [throws QualifiedIdentifierList] MethodBody

    QualifiedIdentifierList: 
        QualifiedIdentifier {  ,   QualifiedIdentifier}

    FormalParameters: 
        ( [FormalParameter { , FormalParameter}] )

    FormalParameter: 
        [final] Type VariableDeclaratorId

    MethodBody:
        Block

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.