The Best Technical Blog Ever

twitterrss

Java Statements & Expressions

Statement:

  • The statements specify the sequence of actions to be performed when a method or constructor is invoked. They appears inside the methods and the classes and they describe all activities of a Java program by instructions.
  • Statements must end with a semi-colon.

Expression:

  • An expression is made up of operands, operators, and method invocations, which are constructed according to the syntax of the language, that evaluates to a single value.
  • It produces values as results and will be used as part of another expression or in a statement.
  • These expressions can be made into a statement by terminating the expression with a semicolon (;).

Example:
int result = a + b;

Block:

  • In Java, any sequence of statements can be grouped together to perform as a single statement by enclosing the sequence in curly braces. These groupings are called statement blocks.
  • A block is a group of zero or more statements between balanced braces ({...}).
  • Although every statement in the block must end with a semicolon, the block ({...}) itself does not end with a semicolon.

Types of Java Statement

1.Declaration statements -

declares a variable.


Example:
int age, a, b, c;

2.Expression statements -

includes statements such as assignment expression, increment and decrement, method invocations and object creation.


Example:
age = 30; 	// assignment statement
a=b+c; // assignment statement
a++; // increment statement
Student s1 = new Student(); // object creation statement
s1.add(); // method invocation statement

3. Control flow Statement -
regulate the sequence of the program in which statements get executed. It allows repetitive execution of statements and conditional execution of statements. Java has the following types of control flow statements.
  1. Decision making statements or conditional execution and selection:
    • if statement
    • if..else statement
    • if..else if statement
    • nested if..else
    • switch statement

    Decision making statements are covered in more detail in the text on Decision making statements.


  2. Looping
    • for loop
    • while loop
    • do..while loop

    Looping statements are covered in more detail in the text on Looping control.


  3. Branching Statement
    • return statement
    • continue statement
    • break statement

    Branching statements are covered in more detail in the text on Branching statements.

Keypoints to remember in java

1. Java is a high level, robust, secured , platform independent and object oriented programming.... more info

Back to Basics:- Java Syntax

In this session, you are going to refresh some basic set of rules(java syntax), defining how a ... more info

Total Visits
Traffic feed status