Title: Classes - Basics summary
Course: CPS 161: An Intro to Programming with Java - DL MM MASTER

Classes - Basics summary

Defining Classes 1

- instance variables - definition and access
- methods - definition and access
- formal parameters, actual parameters
- Examples: simple MyDate, and VendingMachine

Defining Classes 2: Rectangle

- Rectangle Example
- Point class - small utility class
- Passing classes as method parameters: equals, and overlap
- "this" keyword

Authors" Data Sixth Try"

- private instance variables
- "getters" - methods that start with "get" such as getDay, getMonth, getYear
- "setters" - methods that start with "set" such as setDate, setMonth, setDay, setYear
- method overloading

Classes Part3: Summary, Constructors

- methods can return any primitive or any class
- local variables versus instance variables
- Default Constructors
- Constructor concepts - purpose is to initialize class
- Overloading constructors is very common
- keyword "this" can be used to have a constructor call another constructor
- Constructors are associated with calls with "new" keyword and memory is allocated from the "memory heap"

Defining Classes 4: Miscellaneous

- buzz words: Information hiding, Abstraction, Encapsulation, API (Application Programming Interface), ADT (Abstract Data Type), Accessor methods, Mutator methods
- Overloading rules and method signatures (note return type is not part of the signature)
- Initialization of Variables
- StringTokenizer example

Static Things

- static instance variables and static methods
- 3 kinds of memory: local variables(stored on stack), instance variables(stored on heap using "new"), static variables (global memory)
- static method limitations and static examples
- static things in the System class
- static things in the Math class

Wrapper classes

- Wrapper classes associated with primitives: Byte, Character, Short, Integer, Long, Float, Double
- Wrapper classes are Immutable with no default constructor
- Compiler provides "Boxing" and "UnBoxing"
- Useful methods in the Number Wrapper classes: parseInt, parseDouble, etc.
- Useful methods in the Character class: isLetter, isDigit, isWhitespace, isUpperCase, etc.

Parameters and References

- References (addresses) are used for classes
- Parameter passing to methods
  - primitives (int, char, double, etc.) are passed as a copy
  - Mutable classes(Most normal classes) passed by reference and can be changed
  - Immutable classes (String, Integer, Double, other wrapper classes) passed by reference but can't be changed
- null - the keyword for the special "undefined" reference
- Side effects of passing Mutable classes and the use of "Copy-Constructors"

Packages, Access Levels

- Package is similar to a folder ... default package
- public, private access level and file naming rules for public classes
- default, friendly access method (i.e. no public or private)
- import statements and package statements
- Sample mytools package example with "P" and "In" classes

Last Modified: May 18, 2014 11:24 PM