SCJP Study Guide:
Fundamentals


Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend


Previous Next vertical dots separating previous/next from contents/index/pdf Contents
XyzWs SCJP Study Guide: Shift Operators

Miscellaneous



Shortcut Operators


x += 4 x = x + 4
x -= 4 x = x - 4
x *= 4 x = x * 4
x /= 4 x = x / 4
x %= 4 x = x % 4


Type Conversions


A cast-expression is used to explicitly convert an expression to a given type.

A cast-expression of the form (T)E, where T is a type and E is a unary-expression, performs an explicit conversion of the value of E to type T. If no explicit conversion exists from the type of E to T, a compile-time error occurs. Otherwise, the result is the value produced by the explicit conversion. The result is always classified as a value, even if E denotes a variable.

Conversion from a lower range type to higher range type is called widening and is done automatically. However, to go from a higher range type to lower range type (narrowing) you have to explicitly use type casting.

float x = 5.67;
int i = (int) x;

Operator Precedence


In Java Operator Precedence (click the link for the table), you have a table showing the list of operators in Java and their precedence. When two operators have the same precedence, their associativity determines the order of evaluation. All binary operators are left associative. The assignment operators are right associative.

Operand Evaluation Order

The left hand operand of a binary operator is evaluated before any part of the right hand operand is evaluated. The order for evaluating operands takes precedence over the operator precedence rule.

 


Previous Next vertical dots separating previous/next from contents/index/pdf Contents

  |   |