Expressions and Statements

An expression in Java is any valid combination of operators, constants and variables, i.e., a legal combination of Java tokens. The type of operators used in an expression determines the expression type. Arithmetic expression uses arithmetic operators. Arithmetic expressions may contain variables, constants and arithmetic operators together to produce a meaningful result. Boolean expression uses Boolean operators. Boolean expressions involve logical and relational operators and result into ‘true’ or ‘false’. When constants and variables of different types are mixed in an expression, they are converted to the same type. There are two types of conversions: Implicit Type Conversion and Explicit Type Conversion. Implicit type conversion is performed by compiler. Java compiler converts all operands up to the type of largest operand called type promotion. This process of conversion wherein data types are promoted is known as coercion. Explicit type conversion is performed by the programmer using (type) operator. This process is known as type casting.

A Java statement generally contains expressions. The statements must end with a semi-colon. The various types of Java statements are: Expression Statements, Declaration Statements, Control Flow Statements and Empty/Null Statement. Expressions that are made into statements by terminating with semicolon (;) are called expression statements. Declaration statements are used to declare variables. Control Flow statements regulate the order in which statements get executed. Null statement is a semicolon (;) only. It is used when syntax demands a statement but the logic does not. A block is a group of zero or more statements between curly braces and can be used anywhere in a program.

To Access the full content, Please Purchase