2017-01-17 - Hand in Prototypes

posted Jan 17, 2017, 6:36 AM by Samuel Konstantinovich   [ updated Jan 17, 2017, 5:40 PM ]
I want to collect all of the prototypes at once, please have them! I forgot to ask for them so bring them tomorrow.

1. Volunteer order for final project demos.
2. Review For Final Exam:

-Java Operations and types


All the primitive types have a fixed size. Thus, the primitive types are limited to a range of values. 

A smaller primitive type (byte) can contain a smaller ranger of values than a bigger one (long).

Integerbyte8-128127From +127 to -128byte b = 65;
char160216-1All Unicode characterschar c = 'A';
char c = 65;
short16-215215-1From +32,767 to -32,768short s = 65;
int32-231231-1From +... to -...
(big values you can calculate)
int i = 65;
long64-263263-1From +... to -...  
(big values you can calculate)
long l = 65L;
float322-149(2-2-23)·2127From 3.402,823,5 E+38
to      1.4 E-45
float f = 65f;
double642-1074(2-2-52)·21023From 1.797,693,134,862,315,7 E+308
      to 4.9 E-324
double d = 65.55;
Otherboolean1----false, trueboolean b = true;


Each operator in java wants to perform the operation on the same type, and give a result of that type.
1/2 results in 0
1.0 / 2.0  results in 0.5

Notice that INTEGER division truncates the result! This is potentially dangerous if you forget about it.

This means something special has to happen when you mix types:
1 / 2.0  ->  ???   (it is 0.5 also)

This is due to Type Promotion - when one of the operands is promoted to a broader type. A temporary variable is created to store this converted value, and that is used
to perform the calculation. The hierarchy of types from broad to narrow is as follows:  (as you might predict by knowing about types from before)
  1. double
  2. float
  3. long
  4. int
  5. char or short
  6. byte
So if you perform:    1.0 * 2.0f   (double times float)   
The float is converted to a double, and then multiplied to give you 2.0 (a double)