12  previous  | toc  | next 
How about the meaning?

Operational semantic
their effect on a computer

In Java, all variables/identifiers must be declared before they can be used. Why?
to set aside an appropriate amount of space in memory to hold values associated with variables
enable the compiler to instruct the machine to perform specified operation correctly

a = b + c (int = int + int or float = float + float)
b + c is an example of expression, like variables, has both value and type which depends critically on the types and value of the constants, variables ,and function calls making up the expression
+, = are examples of Java operator

Operator: one of
	=	>	<	!	~	?	:
	==	<=	>=	!=	&&	||	++	--
	+	-	*	/	&	|	^	%	<<	>>	>>>
	+=	-=	*=	/=	&=	|=	^=	%=	<<=	>>=	>>>=
Properties of Operators
have rules of precedence and associatively that determine precisely how expressions are evaluate (P.1307 Appendix A)
e.g. 1 + 6 / 3 * 3 - 6 = 1 why? ((1 + ((6 / 3) * 3)) - 6)
Unary: -a, -9, !true
Binary: a + b; c - d; e % f, 3 > 2
ternary: x ? 1:2

prefix: + 1 2
infix: 1 + 2
postfix: 1 2 +

Relational: <, >, <=, >=, == ,!=
Logical: &&, ||, !
Bitwise: ~ (negation), << (left shift), >> (right shift), & (and), | (or), ^ (exclusive or)

++ (increment) , and -- (decrement) operator
when ++i or i++ is evaluated, the timing of side effect depends on the notation (prefix or postfix)
(i = i + 1) == i++ or ++i;
(i = i - 1) == i-- or --i;
however value(++i or --i) is different from value(i++ or i--)
e.g. if i = 3, after execute y = i++, i = 4 & y = 3
execute y = ++i, i = 4 & y = 4

Increment.java

// Fig. 4.14: Increment.java
// Preincrementing and postincrementing operators.

public class Increment {

   public static void main( String args[] )
   {
      int c;
   
      // demonstrate postincrement
      c = 5;                     // assign 5 to c
      System.out.println( c );   // print 5
      System.out.println( c++ ); // print 5 then postincrement
      System.out.println( c );   // print 6

      System.out.println();      // skip a line

      // demonstrate preincrement
      c = 5;                     // assign 5 to c
      System.out.println( c );   // print 5
      System.out.println( ++c ); // preincrement then print 6
      System.out.println( c );   // print 6

   } // end main

} // end class Increment
The cast operators
Automatic type conversions:

if i is an int and f is a float, in the expression i + f, the operand i gets promoted to a float and expression i + f as a whole has type float. similarly, if d is double and i is int, expression statement d = i causes the value of i to be converted to a double and then assigned to d, and double is the type of the expression as a whole. (what if i = d ?)

Explicit type conversion:

Syntax of casting:

(type_name) variable name/expression

(long) ('A' + 1.0)
float x;
x = (float) ((int) y + 1);

 12  previous  | toc  | next