COMP401 Final Exam Study Guide
Object-Oriented Programming:
- Programs expressed as a set of software “objects”.
- Each object is associated with
... [Show More] data and a set of functions or
procedures that operate with that data.
- Objects are defined by their “class.”
- Each class represents an abstraction
- Abstractions often layered on top of each other and/or composited into
more complex abstractions.
- The operation of the program is the result of creating objects and having
them interact with each other.
Major Themes Of This Course:
1. Abstraction
2. Encapsulation
3. Inheritance
4. Polymorphism
5. Delegation
6. Design Patterns
7. Asynchronous Programming
Value vs. Reference Types:
Value Types: Reference Types:
- Integers - Strings
- Real Numbers - Arrays
- Booleans - Objects typed by their class
- Characters - Classes themselves
Value Types are defined entirely by their value
Reference Types are structures in memory.
Method Signature:
Almost everything you need to know about a method is in its signature
- 5 parts to a method signature
1. Access Modifier
a. Public, private, protected
2. Method Type
a. Static or default
b. The keyword static indicates that this is a “class method”.
c. If the keyword static is not present, then this is an “instance
method”.
3. Return Type
a. The type of value returned by the method as a result.
b. If there is no result, then this is indicated by the keyword void.
4. Method Name
a. Must start with a letter, $, or _
b. Can contain letters, numbers, $, or _ (no spaces or other
punctuation)/
5. Parameter List
a. In parenthesis, comma-separated list of parameter typed
variable names.
b. Each parameter variable name is preceded by a type
Declaration.
Calling Methods:
- Calling a class method defined in the same class:
- methodName(parameters);
- Calling a class method defined in a different class (same package):
- ClassName.methodName(parameters);
- Calling a class method defined in a different package:
- PackageName.ClassName.methodName(parameters);
- In the above “parameters” is a comma separated list of values.
- A value can also be an expression that results in a value.
- Must match in number and type according to method’s signature.
Java Execution Model:
- Your program is always executing within the context of some method.
- Starts off in the “main” class method defined in whatever class you
told the program to start with.
Strings:
- String class:
- Sequence of chars.
- Strings are immutable.
Arrays:
- Container for a fixed number of values with the same type.
- Zero based indexing
- Variables for arrays declared by using [] after type.
- Empty arrays can be created with new keyword.
- Literal array syntax can be used to create array from literal values.
Classes and Objects:
- Fundamental units of abstraction
- Physical Analogy
- Classes are like factories
- Contains a blueprint for an object
- Defines the inner workings (i.e., fields aka members).
- Defines what it can do (instance methods).
- Factory itself may have some capabilities
- Class members and class methods
- Relate to the abstraction as a whole and not to a specific
instance.
- Objects are what the factory builds
- Each object is an instance of a class
- Name of the class is the datatype of the object
- Which means it is the datatype of any variable that can
reference the objec [Show Less]