Object-Oriented Programming Flashcards

1
Q

What is an object?

A
Software rep (abstraction) of real world entity (book) or less tangible concept (bank account). Instance of class. 
Look at the STATE of you, what USE are you? (state + behaviour)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the code for JOptionPane?

A

JOptionPane: JOptionPane.showMessageDialog() to display info.
JOptionPane.showInputDialog() to ask for user input

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

What are the types of variables?

A

Primitives + refs to objects.

Primitive: (Int: byte, short, int, long.) (Float: float, double), char + Boolean.

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

What is UML?

A

Unified Modelling Language

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

What are methods?

A

Named statement sequences that can be repeatedly executed as required, support code reuse + program clarity/structure. Also used in definition of object behaviour. Data may be shared with methods via parameters, may be defined with formal parameter list, must be called with actual parameter list which matches formal list.

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

What is an object-oriented program?

A

Implementation of algorithm to solve problem, contains collection of interacting objects.

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

What is a string?

A

Non-primitive type repping sequence of characters, an object. Referenced by identifier e.g. firstName.
If declare string but don’t assignto anything, value is null as doesn’t ref any object. State = char data (len). Behaviour = method calls made via object ref (charAt)

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

What is instantiation?

A

The process of creating objects.

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

What is a class?

A

Describes state + behaviour of objects of same type. Use UML notation to describe them. Need object class + tester class (with main).

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

What is an instance variable?

A

Describes state of objects, methods describe object behaviour. Object must exist before behaviour method used. Static method isn’t associated with object.

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

What are constructors?

A

Used in building objects, special methods to initialise object data (instance variables), syntax diff from other methods. Shares class name, no return type. E.g. public Car () {} Can define own constructors, parameter list describes info constructor needs. Can directly assign/modify values of instance variables via object ref. Private prevents direct external access.

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

What is encapsulation?

A

Fundamental concept of OOP, describes bundling data + methods to work on data within class. Often involves hiding data (state) of object from ext manip. Involves getters + setters to control how info accessed, all data private unless good reason otherwise.

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

What is a destructor?

A

Explicit method, some OOP languages provide this automatically called when object no longer refd. In Java, objects no longer refd garbage collected by system (JRE). Finalise method maybe added to class, called by garbage collection, out of programmer control.

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

What are strings, accessor methods + mutator methods?

A

Strings are immutable objects – can’t be changed. Accessor methods e.g. charAt, mutator methods change values. Must protect object integrity.

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

How do you refer to an object under construction?

A

Use this. to refer to it e.g. this.studentId = id;

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

What should we do when inputting int/double values?

A

Use input.nextLine() to clear scanner + move on to next line.

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

How do we make array data available to other methods?

A

Use them as parameters, ref to data copied to method. E.g. public static void display (int values[])

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

What are exceptions + how do we handle them?

A

Circumstances that may arise in executing program, without management, program will stop. Use try {} catch {} to handle. Can also use Boolean variable + loop so keep trying until user enters valid value.

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

What are class variables + class methods?

A

Variables – single copy available across all class instances. Methods – defined as static, accessed via class name. Underlined in UML.

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

What can enums include?

A

Variables + methods, including constructors.

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

What are the naming conventions for classes?

A

Nouns, first letter words capitalised, whole words, avoid abbreviations. Don’t write to console in object classes.
Utility classes have static constants & methods, don’t create instances.

22
Q

What are the naming conventions for methods?

A

Verbs, first letter internal words capitalised.

Place Javadoc comment above each method for method purpose & parameters.

23
Q

What are the naming conventions for variables?

A

Short, meaningful, not start _/$, mnemonic, first letter internal words capital. Initialise these & don’t leave unused variables in code.

24
Q

What are the naming conventions for constants?

A

Uppercase, underscore space.

25
Q

What are the naming conventions for packages?

A

Prefix lowercase ASCII letters, top-level domain names, subsequent varies.

26
Q

What is method overloading/compile-time polymorphism/one name, multiple methods/static binding?

A

More than 1 method with same name, difference is parameters. Enhances code flexibility. Method call bound to associated method definition at compile-time. Often used with object construction. Dependencies should be minimised e.g. I/O.

27
Q

What do the lines in a UML rep?

A

Relationships/association between classes/components.

28
Q

What is true of class dependencies?

A

Classes can be dependent on other classes. If many depend on one another, coupling is high, which means updates to class may require other dependent classes to be updated also.

29
Q

What are the class relationships?

A

Arrows at both end means bidirectional association, so classes refer to one another. No arrows means same. Multiplicity annotations give more info on association, may also have role names. Bit like entity-relationship diagram. There’s 1/1:1 (1 to 1 relationship), 1..* (ref to 1+ items), 0..1 (0 or 1 items), /0… (ref to many or 0 items).

30
Q

What is aggregation?

A

Special form of association specifying whole-part relationship between aggregate (whole) + component (part). Implies 1 class can exist independently of other. 1 class reps larger thing consisting of smaller things.

31
Q

What is composition?

A

Composition is form of aggregation with strong ownership implication, object from class can’t exist independently of other.

32
Q

What is inheritance?

A

Inheritance is relationship between more gen class (superclass) + more specialised class (subclass), concept allowing us to define gen object classes, these have states + behaviours. Can create further object subclasses based on/inheriting from gen classes. Subclasses maintain same behaviour as parent class but can have individual behaviours also. Subclass inherits data + behaviour from superclass. Defined in UML via IS_A relationship. Private methods of superclass not visible within subclass.

33
Q

What are the benefits of inheritance?

A

Allows us to reuse code, customisation, easy maintenance, model real world + save time. .

34
Q

What are some of the rules of inheritance?

A

InstanceOf tells us if an instance of an object is a member of a certain class (Boolean). Constructor of child must call parent constructor using super(name etc), must be done in first line of constructor.

35
Q

How do you override methods?

A

Can override unwanted methods from parent class in subclass (like overloading but not quite). Use # in UML to signify protected access modifier.

36
Q

What is linear/sequential searching?

A

Not very efficient, only good for small amounts of data.

37
Q

What is binary search?

A

Much more efficient, takes advantage of data order. Starts at 0 + ends at length-1. Pivot at middle. If target value is value at pivot, great, ends. If not, check whether pivot greater or less than target, then +1 or -1 depending on this. (-1 if pivot more).

38
Q

How do we create a random, ordered array?

A

Using insertion sort. Starts at pos 0, adds random number, if next number bigger, puts in next, if smaller, moves up at puts in its position.
String has useful methods e.g. .trim() and .split(). We can do bubble sort on strings by using compareTo().

39
Q

What is black box testing?

A

Behavioural testing/specification-based testing is software testing method in which internal structure/design/implementation of item being tested not known to tester. (Unit, integration, system, acceptance testing). Design suitable test cases, should provide as close to 100% coverage as possible. Can ensure this using equivalence partitioning, boundary value analysis, decision table testing, state transition testing + use case testing.

40
Q

What is equivalence testing?

A

Can be applied at any level, divide test conditions into sets, just do 1 test case from each section, partitions may be valid or invalid.

41
Q

What is boundary value analysis?

A

Boundary Value Analysis is based on testing boundaries between partitions, both valid + invalid.

42
Q

What is a linked list?

A

Example of dynamic data structure, used for storing + managing data of given type. Such structures change in size (resource requirements). Unlike arrays which are fixed, dynamic data structures can continue to grow in size so long as resources are available. Array Lists make use of such dynamic data structures. Basic component of linked list of node, each node in singly-linked list has 2 components (data object ref + link to next node in list) Typical list can have 0+ nodes in sequence. Entire list can be maintained with 1 ref to top of list, commonly have more than 1.

43
Q

What is a stack?

A

A stack is a data structure designed to hold data (objects) in specific order. Similar to list. Data pushed (added) + popped (removed) in specific way.

44
Q

What is recursion?

A

Process of defining a problem in terms of itself, it can apply to the definition of functions + to data structures. Often used as alternative to iterative solutions but must ensure that recursive method terminates – in same way we need to avoid infinite loops.

45
Q

What are the 2 steps of recursion?

A

Defined using 2 steps: recursive step (smaller version of original problem), base case (concrete answer to smallest problem). List contains element + sub List, defined recursively.

46
Q

What is a binary tree?

A

Each node has max 2 kids (left + right child). Used to maintain data in sorted state.

47
Q

What is a full binary tree?

A

Each node has 0 or 2 kids.

48
Q

What is a perfect binary tree?

A

All internal nodes have 2 kids + leaf nodes at same level. Leaf node has no kid.

49
Q

What is a balanced binary tree?

A

Diff between left + right sub-tree height is no more than 1.

50
Q

What is a degenerate binary tree?

A

Every (internal) parent node has 1 kid note (left/right). Skewed binary tree is type of degenerate tree, contains only left/right nodes, not both.

51
Q

What is Quicksort?

A

Sorting algorithm using recursion to define sorting problem in terms of smaller version of itself, partitioning around pivot reduces problem size.