Anda di halaman 1dari 4

Chapter 2.

0 Intro to Objects
Software Objects are similar to real-world objects because they share two characteristics: state and
behavior.
A software object stores its state in fields(variables) and shows its state in its methods.
Java can manage 2 types of primitive data:
1. Byte (-128-127)
2. Short (-32,768 -32,767)
3. Int Default for most people.
4. Long
5. Float Mainly used to save memory in large arrays of floating point numbers.
6. Double Used as the default data type for decimal values.
7. Boolean true or false
8. Char symbols on a keyboard
Operators are special symbols that perform specific operations multiple operands, and then return a
result. ( +, - ,*, /, ==, !=, < ,> ,<= ,>=, &&, ||, % is the remainder operator)
An attribute is a member variable of a class.
-Example: Video game player class ; name and score are attributes.
Class can be defined as a template or blueprint.
Introduces idea or topic
Defines the data type and the methods an object will use/have
Encapsulation means that each object protects and manages its own information.
Class: Bank account ; Methods: withdraw, deposit
We should design objects so other objects cannot change its state.
Inheritance: Basing the definition of one class on an existing one. (Type of software reuse)
Polymorphism is the idea that we can refer to objects of a different but related type in the same way.

Chapter 2.1 Using Objects
System.out is an object that reps an output device or file(monitor)
Object is out and it is stored in the System class
println is a method of System.out
Print v. Println Methods
ptintln prints info and moves to next line
print does not move to the next line when completed
The Count class has a method (main) that invokes the println method of System.out
An object is an abstraction this means that the details are hidden from the user.
When more details are hidden from the user it is called level of abstraction

Chapter 2.2 String Literals
A character string is an object in Java, defined by the class String
Concatenation
Achieved with a + sign.
If in parentheses (+) with numbers, the math operation will be performed
If one operand is a string, all else is seen as a string
Escape Sequence
Special ways to represent special characters in a string
Always start with a backslash (\)
\n newline \* double quote \\ backslash

2.3 Variables and Assignments
A VARIABLE is a name for a location in memory used to hold a data value.
A VARIABLE DECLARATION tells the name of the value and the compiler to reserve space in
RAM.
The modifier final before the declaration makes it a constant
If you dont give an initial value for a variable , it is undefined (ERROR)
If you have many variables of the same data type, you can declare them on the same
line.
Using recursion, you can change the value of a variable.
Java is Strongly Typed, the assigned values must match the variable type.
Format for declaring a Final variable : final int MAX_OCCUPANCY = 427;

2.4 Primitive Data Types
Int and double can be positive or negative
Overflow occurs when there is not enough storage space for your result
Underflow occurs when the number is too small
A literal is a specific data value used in a program
True and false are Boolean Literals
Primitives are values. Objects are references.

What are the three main parts of a class?
Data, construct, method

Anda mungkin juga menyukai