Option D: Object Oriented Programming in Java Flashcards

1
Q

Outline the general nature of an object.

A

An object is an abstract entity that describes the data the entity has (properties, attributes, or instance variables) and the actions that this entity can perform (methods).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Distinguish between an object (definition, template, or class) and instantiation.

A

A class is a template that describes the data and actions an entity might have, but does not contain any specific data itself. An instantiation is a specific object created from the template. For example, a Vehicle class might describe the properties (make, model) and actions of the Vehicle (drive, refuel), but an instance of a Vehicle represents a specific car (e.g. make: “Toyota”, model: “Corola”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Construct unified modeling language (UML) diagrams to represent object designs.

A

Place the class name in the top box, the instance variables or data in the box below (include data types), and the actions or methods in the box below that.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Represent object relations using UML diagrams.

A

Arrows represent inheritance (“is a”) and diamond arrow heads represent composition and aggregation (“has a”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe the process of decomposition into several related objects.

A

Example: A Company object may have an Employer and Employee objects that each inherit from a Person object. The Company also has a Budget object since the company adheres to a budget.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe the relationships between objects for a given problem.

A

Aggregation: “has a” relationship. One object belongs to another object.
Inheritance: “is a” relationship. One object is a specialized form of another object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Outline the need to reduce dependencies between objects in a given problem.

A

The more that objects depend on one another, the system becomes less modular and harder to maintain. Modifying one object would require us to modify the objects that depend on it as well. Reducing the number of dependencies makes systems more flexible.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Construct related objects for a given problem.

A

Example: A store sells different kinds of Vehicles and needs to develop a computer program to keep track of all its vehicles that have common and unique characteristics.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain the need for different data types to represent data items.

A

int (integers) represent whole numbers, real numbers or floating points (float or double) represent numbers with fractional values, booleans (true or false), Strings (text)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Describe how data items can be passed to and from actions as parameters.

A

Parameters allow data to be input into methods, enabling dynamic behavior. E.g., getPriceWithTax(double rate). The parameter is the name defined in the method (rate). The argument is a value passed into a method when it is called. (e.g. getPriceWithTax(7.2) the argument would be 7.2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Define the term encapsulation

A

The inclusion of both data and actions ina single component. Classes contain use public/private fields and methods to only give the user of the class access to specific data and actions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Define the term inheritance

A

A relationship where one object (the child of subclass) is a specialized form of another object (the parent or superclass). The derived object inherits the data and actions of the superclass.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Define the term polymorphism.

A

Polymorphism allows objects of a derived class to be used in place of their superclass. For example, if the class Dog inherits from a class Animal, anywhere Java expects an Animal object, we could use a Dog object instead, since it is a specialized form of the Animal class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Explain the advantages of encapsulation.

A

By making data and actions only accessible in a predefined way: data can be made read-only or write-only, a class can restrict the way that data can be altered (i.e. add validation logic), a class can hide the way data is stored so that implementation can change without affecting how the class is used (this makes the class easier to maintain).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Explain the advantages of inheritance.

A

Extensibility: a subclass can extend or redefine functionality of a parent class
Reusability: a child class will reuse code from the parent class, any changes to common behavior only needs to be done once in the parent class
Information hiding: the parent class can determine what actions and data are available to child classes
Overriding of actions: child classes may override parent actions in order to implement meaningful actions for their needs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Explain the advantages of polymorphism

A

Allows subclasses to have their own unique actions as well as being able to override or improve on parent actions.
Allows subclasses with different behavior to use a common interface (for example different subclasses of an Animal class may all have the makSound method; which can be called without having to know which object implements the specific action)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Explain the advantages of using libraries of objects.

A

Allow for code reuse, application developers do not need to rewrite code for common functionality. Can be used as an “balck box” without having to understand the implementation. Examples include various built-in Java classes: Scanner, Random, ArrayList, Arrays, etc.

18
Q

Describe the disadvantage of object oriented programming.

A

For small projects, may lead to unecessary complexity and overhead. When used improperly can introduce uneeded levels of abstraction making development more cumbersome and programs more difficult to understand.

19
Q

Discuss the use of programming teams.

A

Programming in teams can provide the following advantages: larger projects can be taken on, more developers bring more diverse ideas, the strengths and weaknesses of various team members may offset each other, team members do not need ot know the workings of the whole project and can concentrate their time and energy on a specific portion.

However, to work successfully, developers need well-managed communication system between developers. Project planning takes longer compared to a single developer project.

20
Q

Explain the advantages of modularity in program development.

A

Modularity is the process of dividing a program into separate, smaller sub-programs that can be implemented or tested on their own before combining them togethre. Modularity provides the following advantages:
A sub-program used for one application can be reused for another.
Different developers or teams can work on sub-programs in parallel.
Programs that are comprised of short, simple and easy to understand smaller sub-programs are easier to understand, maintain and debug.

21
Q

Define the term “class”

A

Defines a template, including data (fields, attributes, instance variables) and actions (methods) from which objects may be instantiated. For example, a Person class may describe template for a Person object including data like a name, a height, and an age. This class can be instanced to represent a specific person (e.g. “Mike” with height 1.8m, and age 25)

22
Q

Define the term “identifier”

A

A name that identifies an entity, e.g. a class name, a variable name, the name of a method.

23
Q

Define the term “primitive”

A

Common data types that are available in most programming languages as basic building blocks. Includes characters (char), integers (int, short, long), floating point numbers (float, double), and Booleans (boolean)

24
Q

Define the term “instance variable”

A

Data unique to a specific instance of an object. For example, a Person class may define a name, height, and age as instance variables, but their values will be different to each specific instance of the Person class created.

25
Define the term "parameter variable"
The variable defined in a method that holds the values passed into the method as input. For example, in the method sleep(int hours), hours is a parameter variable.
26
Define the term "local variable"
Variables declared inside a block of code, like in a method. These are only visible within a declared block of code (i.e. a variable declared inside a function can not be used outside of the function).
27
Define the term "method"
Methods are functions defined inside a class. They represent the actions associated with the object. Can operate on the object's instance variables.
28
Define the term "accessor" (getter)
A method that reads a specific data value from an object. Often used to return a private instance variable. For example, a Person class may have a "getAge()" accessor. Also called a "getter"
29
Define the term "mutator" (setter)
A method that is used to modify a specific data value of an object. For example, a Person class may have a "setAge(int age)" method.
30
Define the term "constructor"
A special kind of method that is called when an object is instantiated so that it initializes its data with specific values. In Java, they have the same name as the class and are not declared with a return type. For example a Person class may have the constructor with the header "Person(String name, double height, double weight, String gender, int age)"
31
Define the term "signature"
A method signature includes the name of the method as well as its parameters. We declare multiple methods with the same name, provided their signatures differ. For example, a Calculator class could implement both "int add(int x, int y)" and "double add(double x, double y)" since they have different parameter lists. Note that return type is not a part of the signature so "int add(int x, int y" and "double add(double x, double y)" are not allowed.
32
Define the term "return value"
The value that is passed back or returned to the code that calls a method. For example, in the method pictured alongside, the add method returns an int value.
33
Define the term "private"
If an instance variable or method has the "private" access modifier, it can only be accessed from within the class that defines it.
34
Define the term "protected"
If an instance variable or method has the "protected" access modifier, it can only be accessed from the class that defines it, subclasses, or classes in the same package.
35
Define the term "public"
If an instance variable or method has the "public" access modifier, any class can access it.
36
Define the term "extends"
The keyword use to extend one class from another via inheritance. For example suppose we have an Animal class. If we want to create a Cat class that inherits from Animal, we declare it as "class Cat extends Animal"
37
Define the term "static"
When a method or variable is declared as static (e.g. "static int numAnimals" or a method "static void printAnimal(Animal a)") it is associated with the class a whole rather than a specific instance. Static variables are shared between all instances of the class and static methods can be called without creating an instance of the class. For example, Java's Math class defines many static methods including Math.abs() which can be used to get the absolute value of a value. Static methods are variables can be accessed using the class name.
38
Describe the use of the primitive data types.
Primitive types in Java are the only data types that are not objects. They include integer types (byte, short, int, long), floating-point numbers (float, double), character types (char), Booleans (boolean). All data stored in Java programs are derived from these primitive types.
39
Describe the use of the Java String class.
An built-in object in Java. Can be created like String s = "hello". String values are immutable, though a String variable can be reassigned.
40
Declare an array in Java.
To declare an array of certain size: dataType[] arrayName = new dataType[arraySize];
41
Discuss features of modern programming languages that enable internationalization.
Support for display of international fonts and text. Support for language and local specific needs, such as date and time formatting. Support for different keyboard layouts. Support for user language auto detection and tailoring of the user experience according to it.
42
Discuss the moral and ethical obligations of programmers.
Example: Programs should be throughouly tested before providing them to the public. Credit should be given if the intellectual property of others is used.