Header Ads

  • Breaking Now

    What are expressions,statements and blocks in Java?

    An expression is a construct made up of variables, operators, and method invocations, which are built-up according to the syntax of the language, that evaluates to a single value.

    Some examples of expression:
    int val = 0;
    iArr[0] = 20;
    int var = 4 + 2; // var is now 6

    A statement is complete unit of execution.Any expression which is :

    • An assignment expression

    • ++ or --

    • Method invocation

    • Object creation

    terminated with ';' is a statement.


    x = 123.24; // assignment statement
    x++; // increment statement
    System.out.println("Hello World!"); // method invocation statement
    Person person = new Person(); // object creation statement

    A block is zero or more statements grouped together with balanced braces.



    No comments

    Post Top Ad

    Post Bottom Ad