Midterm Superdeck Flashcards

1
Q

What is procedural programming?

A

Methods/functions calling each other.

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

Downside of procedural programming?

A

It can become unmanageable/harder to manage as they become larger.

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

How does OOP handle complexity?

A

Decomposition. Design objects to contain data and related behaviors.

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

Benefits of OOP?

A

Maintainability and extensibility.

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

What is a class.

A

A blueprint or instruction on how to make an object.

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

What is an object.

A

An instance of a class that has been created.

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

What is a field?

A

An attribute. Data relevant to the systems purpose.

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

What is an entity?

A

Models a real “thing”.

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

What is a container?

A

A data structure to hold entities.

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

What is an interface?

A

Communicates with the “outside world”.

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

What is a control object?

A

Organizes computation.
I.e. The main program.

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

Types of entitites?

A

Concrete objects. People, buildings, etc.
Conceptual objects. Organizations, agreements, etc.
Event and state-change objects. I.e. purchase, sale, birth.

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

Types of methods.

A

Accessors/getters.
Mutators/setters.
Hybrid. Access and mutate, but this is discouraged.

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

5 stages to software development.

A

Requirements.
Design.
Implementation.
System testing and verification.
Maintenance.

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

UMLs describe…

A

What it does, not how.

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

What is a primary actor?

A

Triggers a use case to happen.

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

What is a supporting actor?

A

Indirectly involved with a use case. I.e. A user (primary actor) tries to withdraw money. The bank (supporting actor) verifies there’s enough money.

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

Extends. (non-class uml)

A

Base use case may conditionally execute the associated use case. Dashed line, solid arrow, «extend» in the middle

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

Include.

A

The base case will always execute the associated use case. Dashed line, solid arrow, «include» in the middle.

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

Generalization. (non-class uml)

A

A child use case inherits from parent. Solid line, hollow arrow, from child to parent.

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

Visibility symbols in UML.

A

+ public
- private
# protected

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

Class UML inheritance.

A

Solid line, hollow arrow, child to parent.

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

Class UML generalization.

A

Dashed line, hollow arrow, “child to parent”. “Class B implements A”.

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

Class UML association.

A

A and B call eachother.
Solid line.

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

Class UML one way association.

A

B can call A. Arrow from B to A, solid line, arrow is not complete triangle.

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

Class UML reflexive association.

A

A class may have multiple functions or responsibilities. A smaller box in the lower right underneath.

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

Aggregation.

A

A contains B, B can survive if A is deleted. Solid line from B to A. Hollow diamond.

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

Composition.

A

A contains B. B cannot exist without A. Solid line from B to A. Filled diamond.

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

When are multiplicities used in class UML?

A

For association, aggregation, composition.
I.e. 1 teacher may call at least 1 student ( 1..* ).
A classroom (1) holds at least one student (1..*).

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

Encapsulation.

A

Group related variables and functions. Reduce complexibility and increase reusability.

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

Abstraction.

A

Hide details and show the essentials. Isolate impacts of change.

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

Inheritance benefit.

A

Eliminate redundant code.

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

Polymorphism.

A

Refactor ugly if and switch/case statements.

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

What is the substitution principle?

A

You can always use a subclass object when a superclass object is expected.

I.e. Cat is an Animal, so if you ask for an Animal, I can give you a Cat.

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

What is dynamic method lookup?

A

Methods called are from the actual objects, not the variable type. I.e. You have a bunch of Animals, and you want them to make noises. Calling something like “makeNoise()” on each animal checks the actual object, so you might get a Cat, a Dog, a Bird making different noises, even though the variable type is just Animal.

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

What is an interface made for?

A

To group related methods with empty bodies, deferring implementation to subclasses. Something that implements an interface must implement it’s methods. This way, if you know an object implements an interface, you know what functions it will have from that.

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

What is an abstract class?

A

Cannot be instantiated. However, its subclasses can. I think this means we could have an abstract “Animal” class, since you don’t want to have general “Animals”, but you can have “Cats” or “Dogs” that inherit from it and can be instantiated.

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

What is static typing?

A

Expressions are checked at compile time. Code must be fixed before it can be ran.

Illegal expression - Compile-time error

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

What is dynamic typing?

A

Expressions are checked at run time.
You can run the program, but it may crash.

Illegal expression - Run-time error

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

Java. main function syntax.

A

public static void main(String[] args)

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

What are Java’s numeric types similar to?

A

Very similar to C/C++.

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

What are Strings in java?

A

A class, not a primitive.

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

Where does java keep primitive types?

A

On the stack.

44
Q

Where does java keep objects?

A

On the heap.

45
Q

Constants in java.

A

Use the “final” keyword in the beginning.
Note that by convention, final variables are in all caps.

46
Q

Does java let you type cast float to integer?

A

Only if you use the cast operator.
I.e. (int) some_double;
This truncates the decimal.

47
Q

What is the lifetime of a variable?

A

Within its scope. ( the curly braces {} )

48
Q

Java if, elif, else, syntax.

A

if (condition)
{
{
else if (condition)
{
}
else
{
}

49
Q

Java for loop.

A

Just like in C.

50
Q

Java do while?

A

do
{
stuff;
} while(condition);

51
Q

Java console output.

A

System.out.println(“hello world”);

Note that println automatically adds a newline.

52
Q

How to get keyboard input in java?

A

import java.util.Scanner;

Scanner in = new Scanner(System.in);
in.next();
in.nextInt();
in.nextDouble();
etc…

53
Q

How to parse strings to other data types?

A

Integer.parseInt(String s);
Float.parseFloat(String s);
Byte.parseByte(String s);

54
Q

String comparison.

A

== is for objects. Two strings may have the same value but won’t evaluate to true here.
Use s1.equals(s2)

55
Q

Testing is a _____ process.

A

proactive
They help us identify bugs.

56
Q

Debugging is a _____ process.

A

Reactive. There is a problem so you act to fix it.

57
Q

What is the goal to testing?

A

To detect faults in our code.

57
Q

Types of errors.

A

Commission. You made errors in your code. Syntax mistakes. Minor logic errors. Stuff is there, but not working.
Omission. You didn’t prepare for some behavior. Stuff is missing entirely.

58
Q

What is a fault?

A

The appearance/form/manifestation of an error.
Incorrect output,
Run-time errors,
Failure to achieve the stated purpose

59
Q

What does the presence of a fault mean?

A

It implies the presence of an error.
Note that one error may create many faults.

60
Q

What is debugging?

A

Deducing the error from the fault.

61
Q

What are the testing levels?

A

Unit testing: On each method individually.

Integration testing: Some methods work together. Limited combinations.

System testing: The whole application. Very testing. Do the previous two as much as possible before to find most of the faults.

62
Q

What is test driven developmetn?

A

Design stubs, parameters, return, effect.
Design test cases.
Implement methods.
All test cases should fail initially.
Work on method implementation until all test cases pass.

63
Q

What is bottom-up testing?

A

Start with things that don’t use other units.
Repeatedly test the integration of modules that only use already tested module.
Continue until whole system tested.

64
Q

What is top-down testing?

A

Implement top-level methods first.
Write test cases for the top-level.
Leave low-level methods as stubs.

65
Q

Top down or bottom up?

A

Bottom-up for well understood modules or well structured designs (like assignments).
Top-down for nebulous modules (or open-ended free-form projects).

66
Q

Inheritance relationship description.

A

“is-a”

67
Q

What is polymorphism?

A

Lets subtypes be treated as their supertypes.
Lets classes be treated as interface types that they implement.

68
Q

What is cohesion?

A

How many things or concepts does something do/represent? Low cohesion is when classes do too many things, which is bad.
High cohesion would have each class be doing a specific and limited number of things well.

69
Q

What is coupling?

A

How many calls between classes are there?
High coupling is when classes call each other too much, which is bad. Low coupling is when the calls between classes is reduced, which is good.

70
Q

Useful methods and operators of Object as given in class?

A

toString()
getClass()
Equals()
instanceof operator

71
Q

Java arrays.

A

Fixed single block of memory. Accessed by index. All values the same type. Primitive or reference types. Duplicate values permitted. NOT part of Java Collections Framework.

Remember to use new keyword.
i.e. int[] someArray = new int[99];

72
Q

ArrayList

A

Accessed by index. Variable size. All the same type. Only reference types. Duplicate lists permitted.

73
Q

LinkedList

A

A sequence of values. Accessed in order. All the same type. Reference types only. Exactly as much space as needed.

74
Q

Maps

A

key-value pairs. Organized by key to access the values.
HashMap - array-like
TreeMap - tree-like

75
Q

Creating a new map in Java.

A

Map<keytype, valuetype> varname = new HashMap<keytype, valuetype>();

76
Q

Adding, removing, and getting entries from a map.

A

.put(key, value)
.get(key)
.remove(key)

77
Q

What is a benefit of Hash Maps?

A

I.e. A bunch of 10 digit ids. It would be far too costly to make space for all possible, so make an array for roughly the right size. Use a function to convert each id into an index. (if there’s duplicates, have strategies to try elsewhere, but beyond cmpt270).

78
Q

Sets

A

Unordered collection. Can store, remove, and check for value. Like a map that only stores keys. HashSet and TreeSet

79
Q

What factors into choosing a collection type?

A

How do you want to access values?
What types or key/value types are needed?
Does order matter?
What operations need to be fast?
Do you need to implement .equals() and .hashCode() for Hash Sets/Maps?
Do you need to implement the Comparable interface for trees?

80
Q

Generics.

A

Let you avoid specifying a type.
I.e.
public class Zoo<i> {
This lets us omit the specific type until we make an instance.</i>

81
Q

Can you restrict generics?

A

Yes.
I.e. <i></i>

82
Q

What are exceptions within the context of Java?

A

Objects. Created when an event is detected, passed to the JVM, and halting the normal execution of code (passed upwards until something deals with it).

83
Q

What makes exceptions different from error codes?

A

Error codes could be ignored. They were somewhat informal.

84
Q

What ways can exceptions be used?

A

To detect and handle exceptions that can be managed by the application. I.e. user enters bad data. A file is missing. Etc.

To signal errors that need to be debugged and fixed. These are the programmers’ fault and need to be fixed to solve them.

85
Q

Java try catch statement.

A

try
{
// code goes here
}
catch (NameOfException exception)
{
// do something about it
}
catch (OtherNameOfException exception)
{
// do something about it
}
finally
{
// do this thing always (i.e. close a file).
}

‘exception’ replaced by things like ‘e’ normally or ‘ignored’ when testing to see if it’s thrown like in our assignments.

86
Q

Throws clause

A

If a method could throw a checked exception, it must be declared in the method.
i.e.
public String readData(String filename)
throws FileNotFoundException, NumberFormatException

Note that this clause is not required if the method catches the exception.

87
Q

How do you throw an exception?

A

I.e.
throw new NameOfException(“message to accompany exception”);

88
Q

A UML Use Case diagram is a type of…

A

behavioral diagram

89
Q

Is a UML Class diagram a type of behavioral diagram?

A

No.

90
Q

A house and a wall would have a ____ relationship?

A

Composition.

91
Q

A hammer and nail would have a ___ relationship.

A

Association.

92
Q

What principle lets you use one method to have different behaviors based on the class?

A

Polymorphism.

92
Q

How do you show polymorphism in a UML class diagram?

A

You don’t.

93
Q

Polymorphism helps to…

A

Refactor ugly if and switch/case statements.

94
Q

Can you use single quotes to denote a string literal?

A

No.

95
Q

Validation helps to…

A

Increase confidence in the correctness of a system.

96
Q

An error is…

A

The cause of an undesired behavior.

97
Q

Debugging is…

A

Inferring the cause of undesired behavior or incorrect results.

98
Q

A fault is…

A

An undesired behavior or incorrect result.

99
Q

Can there be fault’s without errors?

A

No.

100
Q

What keywords indicates inheritance in Java?

A

extends

101
Q

Benefits to polymorphism.

A

Reduces the amount of code you need to write.
Makes your code simpler and more concise.
Reduces coupling.
Can make your code more flexible/adaptable.

102
Q

What keyword is used to define the use of an interface in Java?

A

implements

103
Q

How do you let your custom classes be comparable with ‘<’ and ‘>’ operators?

A

You can’t.

104
Q

Where should exceptions be caught and handled?

A

The method that has the enough information to most effectively handle the problem.

105
Q

Can you compile code that doesn’t acknowledge unchecked exceptions?

A

No.