Chapter II Flashcards
Working with java primitive data types and string APIs Describing and using objects and classes
Primitive type
boolean byte short int long float double char
boolean
true or false
byte
8-bit integral value - 123 → Stores whole numbers from -128 to 127
short
16-bit integral value - 123 → Stores whole numbers from -32,768 to 32,767
int
32-bit integral value - 123 →Stores whole numbers from -2,147,483,648 to 2,147,483,647
long
64-bit integral value -123L → Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float
32-bit floating-point value - 123.45f →Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits
double
64-bit floating-point value - 123.456 →Stores fractional numbers. Sufficient for storing 15 decimal digits
char
16-bit Unicode value - ‘a’
Conventions
Method and variable names are written in camelCase with the first letter being lowercase Class and interface names are written in camelCase with the first letter being uppercase. Also, don’t start any class name with $, as the compiler uses this symbol for some files
var
A var is used as a local variable in a constructor, method, or initializer block. A var cannot be used in constructor parameters, method parameters, instance variables, or class variables. A var is always initialized on the same line (or statement) where it is declared. The value of a var can change, but the type cannot. A var cannot be initialized with a null value without a type. A var is not permitted in a multiple variable declaration. A var is a reserved type name but not a reserved word, meaning it can be used as an identifier except as a class, interface, or enum name.
Local variables scope
In scope from declaration to end of block
Instance variables
In scope from declaration until object eligible for garbage collection. (field of objects)
Class variables
In scope from declaration until program ends. (static variables)
Object is not longer reachable when
The object no longer has any references pointing to it.
All references to the object have gone out of scope.