Chapter 3 Flashcards
Abstraction
The ability to ignore details of parts to focus attention on a higher level of a problem
modularization
Process of dividing a whole into well-defined parts which can be built and examined separately, and which interact in well defined ways
Classes define ___
types. A class name can be used as the type for a variable. Variables that have a class as their type can store objects of that class.
What are the 2 types in Java?
primitive and object types
Primitive type
- stored directly in variable
- non-object type
- Types suchas int, boolean, char, double, and long are the most common primitive types.
- Primitive types have no methods.
- pre-defined in the java language
object types
- not stored directly in variable but the reference of the object is stored (object references)
- defined by classes
Internal method call
- no variable name required
- method is in the same class as the call of the method
- syntax:
methodName(parameter-list)
ie.
updateDisplay();
External method call
- method call to a method of another object using dot notation
- syntax:
object.methodName(parameter-list)
ie.
minutes.increment();
object.methodName(parameter-list)
this syntax is know as___
dot notation:
It consists of an object name, a dot, the method name, and parameters for the call
name overloading
- the same name being used for 2 different entities.
- a class may contain more than one constructor, or more than one method of the same name, as long as each has a distinctive set of parameter types
What keyword is used in the case of name overloading to refer to the field instead of the closest parameter?
“this” such as:
this.from
“this” refers to current object so this particular “this” refers to the “from” field in the current object.
class diagram
- shows the classes of an application and the relationships b/t them
- gives info about the source code
- presents static view of a program
object diagram
- shows the objects and their relationships at one moment in time during the execution of an application
- gives info about objects at runtime and presents the dynamic view of a program
&&
Logical “and” operator that causes the condition in the if-statement to be true if both the conditions on either side of the “&&” symbol are true
What are the 3 most important logical operators?
and, or and not
II
“or” logical operator,
“a II b” is true if either a or b or both are true - false if they are both false
!
“not” logical operator
- “! a” is true if a is false and false if a is true
What would happen if one of the operands of a plus operation is a string and the other is not? as in :
“answer: “ + 42
If one of the operands of a plus operation is a string and the other is not, then the other operand is automatically converted to a string, and then a string concatenation is performed.
“answer: 42”
What would be the result of this concatenation?
“Java” + “with BlueJ”
“Javawith BlueJ”
note: if you want a space, include it within one of the strings.
What would the result of this be?
return “” + value;
“value”
If we concatenate “value” with an empty string, it will be converted to a string and no other characters will be prefixed to it.
Object creation
- objects can create other objects, using the new operator
- syntax:
new ClassName (parameter-list) - new operation:
1. creates a new object of the named class
2. executes the constructor of that class
debugger
- A software tool that helps in examining how an application executes.
- can be used to find bugs
Breakpoint
- A flag attached to a line of source code that will stop the execution of a method at that point when it is reached.
- represented in the BlueJ editor as a small stop sign
Primitive vs object types
Primitive
- predefined
- held in stack
- 2 distinct variables are overrated + 2 separate assignments. Values should be same
- do not null value as default value
- examples: byte, float, double, char, Boolean, etc
Object
- user-defined
- original object kept in the heap & ref variable kept in stack
- 2 ref variables are generated, both highlight similar article on the heap
- ref variable default value is null
- example: array, String etc