01-11-2012, 01:48 PM
Assignments & Operations
Assignments.ppt (Size: 47 KB / Downloads: 22)
Persistence Modifiers
Java has a persistence modifier
static
similar to, but not quite the same as in C or C++
A static variable or method is shared among all objects of the same class.
Unless we have a good reason for making something static, don't!
Static methods can't access non-static data
In Applications, declare your variables within main(), rather than within the class.
Assignment Incompatibilities
Consider that we have different types
which have different accuracy
Some assignments may loose precision
byteValue = intValue;
Some assignments won't loose precision
intValue = byteValue;
We also have types which represent different things
floatValue = charValue; // ?
Java Operations
Five Mathematical Operations
Additive
addition: operand + operand
subtraction: operand - operand
Multiplicative
multiplication: operand * operand
division: operand / operand
remainder: operand % operand
Parentheses
We can control the order of operations by using parenthesis.
Things within parentheses are evaluated before they are used
as if it was a single value
Anything within a parenthesis is evaluated using the standard precedence rules
Strings
String objects are declared like any other object or primitive data item
Same restrictions as before with respect to where they can be declared
All object require instantiation before use
That is we must make the storage for them before we use them
Strings are the only object we can do this with assignment
All other objects require a special procedure