Objectives
- Identify data types based on value
- Recall how to declare and initialize various primitive datatypes in Java
- Recall how basic mathematical operators work in Java
Data Type | Can Store | Storage Size |
---|---|---|
double | Floating point numbers, with up to 8 significant digits of precision | 8 bytes |
float | Floating point numbers, with up to 7 significant digits of precision | 4 bytes |
long | Whole numbers in range [-9223372036854775807, 9223372036854775807] | 8 bytes |
int | Whole numbers in range [-2147483647, 2147483647] | 4 bytes |
short | Whole numbers in range [-32767, 32767] | 2 bytes |
byte | Whole numbers in range [-127, 127] | 1 byte |
char | Single alpha-numeric or punctuation character | 2 bytes |
boolean | True or False | 1 byte |
// Examples of declaring and initializing each datatype double myDouble = 543.222987; float myFloat = 983.2f; // note that you need the 'f' here to specify it as a float long myLong = 456778866554433l; // note that you need the 'l' here to specify it as a long int myInt = 35698742; short myShort = -3566; byte myByte = 120;
+
-
/
*
%
++
--
double
or float
.int
.int x = 3; double y = 55.7; y = x; // no problem here!
int x = 3; double y = 55.7; x = y; // this will generate an error because you would lose the .7 by doing this // and Java won't do it for you, unless you tell the compiler you really want to x = (int)y; // this works - you are telling Java that it's okay to lose the .7
The address of the house is: 3 William St., Unit 5 It is listed for sale at $368000 A 10% downpayment would be $36800.0