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
What is the value of the expression(x>3) || (y < 3) if x has the value 1 and y has the value 5?Marks:1
What is meant by variable?Marks:1
Variables are locations in memory that can hold values. Before assigning any value to a variable, it must be declared.
What is the other name for ‘implicit casting’?Marks:1
Differentiate between pure expressions and mixed expressions.Marks:1
Pure expressions have all operands of same data types, contrary to mixed expressions that have operands of mixed data types.
Write the given numeric expression into Java expression.