Last Time
Java's Eight Primitive Types | |
---|---|
byte | 8 bit signed integer |
short | 16 bit signed integer |
int | 32 bit signed integer |
long | 64 bit signed integer |
float | 32 bit IEEE 754 single precisions floating-point number |
double | 64 bit IEEE 754 double-precision floating-point number |
boolean | true/false |
char | unicode character |
Differences
- 4 different integer types. All are of limited size.
- variables have type as well as data
- worker statements end with a ;
- Boss statements have no mark at the end
- Block delimiter is {....}. In Python we use whitespace.
- Rules for variable names
- Boss statements own blocks of code.
Things that are the same
Relational Operators and Primitives
<, <=, >, >= only work for primitives.
Primitives point directly at their datum. x = 5
x 0000000000000000000000000000000101
- Primitive types: variables store data directly. TYpes are lower-case.
- Object types: variables store memory addresses of object that live on the heap.
Object Type vs. Primitive
== and != are OK for all data.
Objects have three properties.
- state: This is what an object KNOWS.
- identity: this is what an object IS. It's a thing stored in memory (on the heap).
- behavior: This is what and object DOES.
The Case of String
- state: character sequence.
- identity: place where string is stored in memory (on the heap).
- behavior: This is what and object DOES. Behavior is expressed by methods.
The API Guide
The Java API Guide is an on-line searchable comprehensive encyclopaedia of core Java. You will see that this is extremely useful. We will use it to learn about Java Strings. Strings are immutible character sequences, just as they are in Python. You will see cosmetic differences in how you handle them.