1/21
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
primitive type
a basic data type that Java predefines.
- takes up different amounts of memory
Object reference type
Only need enough memory to hold a pointer to the object in question
- Declared with either a name of an interface or a class
8 primitive types (in order)
byte, short, int, long, float, double, char, boolean
Byte
(byte) 8 bits of interger
Short
(short) 16 bits of interger
Interger
(int) 32 bits of interger
Long
(long) 64 bits of interger
Float
(float) 32 bits of floating point
Double
(double) 64 bits of floating point
Character
(char) 16 bits of a letter
Boolean
(boolean) true or false
Variables
Fields of memory inside an object
- Can only hold one type of thing
- type, name
- Each variable can be seen by as few things as possible for as short a period of possible
Private declaration
Only seen inside the class
Protected declaration
Only seen in the class, package, and subclasses
Public declaration
Visible to all
Method
Declared with a return type, a name, and a list of parameters
- Each parameter is declared with a type and a name
Constructor method
Method that creates a new instance of a class
- Two kinds (object constructor and arrary object constructor)
- Always begins with the word new
Object constructor
Method that has the same name as the class and no declared return type
Array object constructor
Not a method we write, but we must specify that kind of thing the array holds and how many of that items are in said array
Array
A sequence of values of a given type.
-An object w/ a fixed size once it is created
- [array]
Examples of how arrays can e made (two)
- int[ ] myArray = we int[9]; (nine element arry of ints)
- int[ ] myArray = { 1, 1, 2, 5, 8, 13, 21, 34}; (nine element array w/ specific values)
Two dimensional array
An array of arrays
carton = new Egg[2][6];
for(int row = 0; row < carton.length; ++row){
carton[row][column] = we Egg();
}