Software Development Flashcards

1
Q

What are characteristics of Waterfall software development approaches?

A

Waterfall is a linear and sequential approach to software development. Each phase must be completed before moving on to the next. It emphasizes documentation and is less flexible to changes once the project has started.

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

What are Characteristics of Agile software development?

A

Agile development is characterized by flexibility and collaboration. Scrum and Pair programming are indeed agile methodologies. User engagement is encouraged throughout the development process, and rapid delivery of a working product is a key principle of agile development.

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

How are static nested classes and inner classes accessed

A

Static nested classes are accessed using the enclosing class name, while inner classes are accessed using an instance of the enclosing class. This distinction is crucial in Java programming.

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

What are local classes

A

Local classes in Java are defined within a method. Their declarations can contain access modifiers such as public, and they can also access all members of the enclosing class instance.

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

What are anonymous classes

A

Anonymous classes in Java are declared without a class name. They can be defined both within and outside a method, but they are often used within methods for concise implementation of interfaces or abstract classes.

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

What are important aspects of multithreading in software development?

A

Multithreading involves the concurrent execution of multiple threads. Notable points include:

  • A thread can be treated as a lightweight process.
  • Every process has at least one thread.
  • The operating system can run multiple threads virtually in parallel on a single processor.
  • The operating system can run multiple threads actually in parallel on a multicore processor.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What defines race conditions in Java programming, and how can they be addressed?

A

Race conditions occur when two or more threads attempt to change data simultaneously. To address them:

  • They happen when one thread tries to change data.
  • They happen when two or more threads try to change data at the same time.
  • They can be avoided by using either “synchronized” blocks or “synchronized” methods.
  • They can be avoided through proper synchronization mechanisms.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What constitutes liveness problems in multithreading, and are they avoidable?

A

Liveness Problems in Multithreading:
Types:

Deadlock: Threads wait for each other indefinitely.
Livelock: Threads are actively trying to resolve a conflict but make no progress.
Starvation: Thread is perpetually denied access to a needed resource.
Priority Inversion: Higher-priority thread is blocked by a lower-priority thread.
Resource Deadlock: Similar to deadlock but involves non-lock resources.
Circular Wait: Threads wait for each other in a circular chain.
Mutex Locking: Overuse of mutex locks leading to contention.
Solutions:

Deadlock: Acquire locks in a consistent order, use tryLock() with timeouts.
Livelock: Introduce randomness or timeouts in retrying mechanisms.
Starvation: Adjust thread priorities, use fair locks, ensure fair resource access.
Priority Inversion: Use priority inheritance.
Resource Deadlock: Acquire resources in a consistent order, use timeouts.
Circular Wait: Establish a global order for resource acquisition.
Mutex Locking: Use fine-grained locking, lock-free structures, or alternative synchronization.

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

How do wait() and sleep() methods function in Java programs?

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

What stages define the lifecycle of a thread in Java programs?

A

he lifecycle of a thread in Java involves several states and transitions, such as:

(A) The thread scheduler selects a thread to go from the runnable to the running state.
(B) In the running state, a thread starts executing by entering the run() method.
(C) When an instance of the thread is created using the new operator, it is in the runnable state.
(D) The thread is alive when it’s in the waiting state.

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

What are the potential issues associated with stale data in software development?

A

Stale data in software development can lead to various issues such as:

(A) They may cause unexpected exceptions.
(B) They may cause corrupted data structures.
(C) They may cause inaccurate computations.
(D) They may cause infinite loops.

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

What Design Pattern does the Memento Pattern apply to?

A

Behavioral Patterns

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

What Design pattern does Iterator patterns belong to?

A

Behavioral Patterns

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

What Design pattern does Singleton pattern belong to

A

Creational Patterns

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

What Design pattern does decorator pattern belong to?

A

Structural Pattern

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

How do polling and event-driven programming differ in terms of event handling in Java?

A

Polling and event-driven programming have distinctive characteristics, including:

(A) Polling is easy to implement.
(B) Event-driven programming is more complex to implement than polling.
(C) Event-driven programming is wasteful of system resources.
(D) Polling is considered a much better use of system resources than event-driven programming.

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

Define polymorphism

A

Any code working with an interface can work with other classes that implement that interface

-An interface in the context of design patterns is a way to define a contract or a set of methods that a class must implement. It serves as a blueprint for classes that adopt it, ensuring consistency in behavior. Interfaces are essential components in many design patterns, promoting flexibility and polymorphism.
e.g.
public interface Shape { -
void draw();
}
-Any class that implements this interface must provide concrete implementations for method draw.

Note: in design patterns, we say “implement an interface” has a general meaning, not only implementing an interface, but also a concrete class implementing a method from a superclass.

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

What is a concrete class?

A

A concrete class is a class that provides a complete, tangible implementation of an interface or an abstract class. It can be instantiated, and it provides specific functionality based on the requirements defined by its superclass or implemented interface. Concrete classes play a crucial role in design patterns by realizing the contracts specified by interfaces or abstract classes.

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

What are the different levels of testing in software development?

A

Different levels of testing in software development include unit testing, which tests individual blocks of code; integration testing, which tests the entire system as a whole; system testing, which also tests the entire system as a whole; and user acceptance testing, ensuring that the delivered system meets user requirements.

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

How do white box and black box testing differ, and what are their characteristics?

A

White box testing may introduce bias in designing tests, and it allows designing tests to target specific paths through the program. In contrast, black box testing may also introduce bias, but it involves designing tests without knowledge of the internal code structure and focuses on testing the program’s functionality.

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

What factors should be considered when conducting unit tests in software development?

A

When performing unit tests in software development, it’s crucial to consider factors such as boundary conditions, inverse relationships, boundary results, and performance characteristics.

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

What qualities define good tests in software development?

A

Good tests in software development should possess certain properties: they should be automatic, repeatable, and contribute to comprehensive test coverage, ensuring that the testing process is efficient and effective.

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

What practices contribute to effective unit testing in software development?

A

Good practices of unit testing involve promptly fixing any failing tests, not continuing to add features to the code while tests are failing, and maintaining a disciplined approach to ensuring test integrity.

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

When should mock objects be utilized in software testing?

A

Mock objects are useful in software testing when dealing with real objects with non-deterministic behaviors, when the real object is challenging to set up, or when the real object does not yet exist.

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

What are the benefits and characteristics of test-driven development?

A

Test-driven development (TDD) aids programmers in designing code better by promoting a systematic approach where tests are written before the code. TDD enables programmers to see the code from the user’s perspective and encourages iterative development with a focus on passing tests.

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

What principles guide design patterns in software development?

A

Design patterns in software development focus on promoting code reuse and experience reuse. Some design patterns are based on the “program to an interface, not an implementation” principle, while others follow the “identify the aspects of your application that vary and separate them from what stays the same” principle.

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

What are the three types of design patterns?

A

Creational Patterns, Structural Patterns, Behavioral Patterns

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

How do factory patterns and abstract factory patterns differ in terms of their design principles?

A

 Factory Pattern uses inheritance (extend a class and override a factory method) and gives you a complete object in one shot.

 Abstract Factory Pattern uses composition (defines an abstract type for creating a family of products and lets subclasses decide how those products are produced) and returns a family of related classes.

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

What functionalities do builder patterns provide in the context of constructing complex objects?

A

Builder patterns encapsulate the construction process of complex objects, allowing for multistep and varying processes. They also hide the internal representation of the product from the client.

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

How do factory patterns and builder patterns differ in the way they construct objects?

A

Factory patterns construct a complete object in one step, whereas builder patterns construct a complete object step by step, providing more flexibility in the construction process.

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

What are key characteristics of decorators in the decorator design pattern?

A

In the decorator design pattern:

An object can be wrapped by multiple decorators.
Decorators have the same supertype as the objects they decorate.
Objects can be decorated at runtime, allowing for dynamic modifications.

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

How do generics contribute to program development in Java?

A

Generics in Java make many bugs in a program detectable at compile time, ensuring type safety and enhancing code robustness.

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

What are generic types in Java programming, and how are they represented?

A

Generic types in Java programming include generic classes parameterized over types, and a single uppercase letter is commonly used to represent the type.

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

What functionalities do bulk operations in the Set interface provide?

A

Bulk operations in the Set interface include:

s1.containsAll(s2) returns true if s2 is a subset of s1.
s1.addAll(s2) transforms s1 into the union of s1 and s2.

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

: What distinguishes HashSet<E> and TreeSet<E> in terms of order guarantees?</E></E>

A

HashSet<E> has no order guarantees, while TreeSet<E> maintains order guarantees based on natural ordering or a provided comparator.</E></E>

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

How is reflection utilized in Java programming, and what functionalities does it provide?

A

Reflection in Java allows dynamic invocation of methods, construction of new objects, and changing values of fields during runtime.

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

What distinctions exist between the getFields() and getDeclaredFields() methods in Java programming?

A

getFields() returns an array of Field instances, including inherited ones.
getDeclaredFields() returns an array of Field instances, not including inherited ones.

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

What considerations and characteristics are associated with reflective operations in Java programs?

A

Reflective operations in Java programs might have slower performance than their non-reflective counterparts and may require runtime permissions not guaranteed under a security manager.

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

What are the fundamental characteristics and functionalities of Transmission Control Protocol (TCP)?

A

TCP establishes a reliable link between two communication machines and guarantees the order of data transmission, ensuring data integrity during communication.

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

What is the purpose of the Factory Design Pattern?

A

The Factory Design Pattern aims to centralize object creation by defining an interface for creating objects but letting subclasses decide which class to instantiate. This pattern allows a class to defer instantiation to its subclasses, promoting flexibility and encapsulation.

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

In the context of the Factory Pattern, what is the role of the abstract creator, using an example?

A

An abstract class or interface defines a factory method (e.g., createPizza).
This class is made abstract to allow subclasses to provide specific implementations.

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

Explain Concrete creators in the Factory pattern

A

Subclasses extend the abstract creator (e.g., NaplesPizzaShop).
They provide concrete implementations of the factory method, often with parameters.
Concrete creators decide which concrete product (e.g., NaplesCheesePizza) to instantiate.

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

Explain Product creation in the Factory Design Patterns

A

The abstract creator still provides a concrete method (e.g., orderPizza).
The orderPizza method internally calls the abstract factory method (createPizza).
The actual operation is defined by the concrete creator classes and the products they return.

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

Give an overview of the builder pattern

A

Separates the construction of a complex object from its
representation so that the same construction processes can create different representations
 Let you vary a product’s internal representation
 Isolate code for construction and representation
 Finer control over the construction process

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

How does the builder pattern work?

A

The Builder specifies the interface for creating parts of the
complex (Product) object.
◼ The ConcreteBuilder objects create and assemble the parts that make up the Product through the Builder interface.
◼ The Director object takes responsibility for the construction process of the complex (Product) object, however it delegates
the actual creation and assembly to the Builder interface.
◼ The Product represents the complex object that is created by the ConcreteBuilder object(s). The Product consists of multiple parts that are created separately by the ConcreteBuilder objects.

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

What are advantages of the builder pattern

A

 Encapsulates the way a complex object is constructed
 Allows objects to be constructed in a multistep and varying process
(as opposed to one-step factories)
 Hides the internal representation of the product from the client.

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

Difference between Factory, Abstract factory and builder patterns

A

 Factory pattern constructs a complete object in one shot
 Abstract Factory pattern returns a family of related classes
 Builder pattern constructs a complex object step by step

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

What state changes will happen in the thread lifecycle when calling yield() in Java?

A

From the running state to the runnable state.

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

What is a correct statement about the use of the Lock interface?

A

Two or more objects can share a lock.

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

Name the Creational Design Patterns

A

Factory Pattern, Abstract Factory Pattern, Singleton Pattern,
Prototype Pattern, Builder Pattern

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

Name the Structural Design Patterns

A

Adapter Pattern, Bridge Pattern, Composite Pattern, Decorator
Pattern, Facade Pattern, Flyweight Pattern, Proxy Pattern

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

Name the Behavioural Design Patterns

A

Chain Of Responsibility Pattern, Command Pattern, Interpreter
Pattern, Iterator Pattern, Mediator Pattern, Memento Pattern,
Observer Pattern, State Pattern, Strategy Pattern, Template Pattern,
Visitor Pattern

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

What Pattern type does Composite pattern apply to

A

Structural pattern

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

Give a simple overview of the Singleton Design pattern

A

Ensures that a class has only one instance, and provides a global
point of access to it

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

What are some examples of things that follow the Singleton pattern Design methodology

A

Window Managers, File Systems, Print Spoolers

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

In the Singleton design pattern a class employs a technique called lazy instantiation, what is this?

A

The Singleton class employs a technique known as lazy instantiation to create the singleton, to ensure that the singleton instance is not created until the getInstance() method is called for the first time (i.e.,
created only when needed).

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

How can a thread safe singleton class be created?

A

The easier way to create a thread-safe singleton class is to make the
global access method synchronized, so that only one thread can
execute this method at a time.

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

What is the double checked locking principle in relation to thread safe singleton classes

A

Is used to ensure there is only a single instance of a class created, the process entails:
First Check: Quickly verifies if the instance exists.
Enter Lock: If not, enters a lock to create it, ensuring only one thread does.
Double-Check: Ensures instance creation didn’t happen concurrently.

This technique balances efficiency with the need for thread safety when creating a singleton instance in a multithreaded environment.

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

Give a short overview of the Decorator pattern

A

Attaches additional behavioural responsibilities to an object
dynamically. Decorators provide a flexible alternative to
subclassing for extending functionality.
An example of this could be adding “Decorations” to a Christmas tree which add functionality

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

What are some principles of the Decorator design pattern

A

-Code should be open for extension, but closed for modification
-Aim is to design classes that are easy to extend to incorporate
new behaviour, but without modify the existing code base
-Code extension doesn’t only have to come through inheritance
in OO programming

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

What are some facts about Decorators in the Decorator design pattern

A

◼ You can use one or more decorators to wrap an object
◼ Decorators have the same supertype as the objects they decorate
 So we can pass around a decorated object in place of the original
object
◼ Objects can be decorated at any time, so we can perform
dynamic runtime decoration
◼ Behaviour comes through the composition of decorators with
the base components (and other decorators)
◼ Some limitations
 Takes time and effort
 Introduces new levels of abstraction

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

Summerise the Command Design Pattern

A

Encapsulates a request as an object, thereby letting you
parameterise other objects with different requests, queue or log
requests, and support undoable operations.

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

What Type of design pattern is Command Design

A

Behavioral

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

What are all the design patterns we need to know and a small summary about each of them

A

 Factory pattern: constructs a complete object in one step
 Abstract factory pattern: creates a family of related classes
 Builder pattern: constructs a complex object (with parts) step by
step
 Singleton pattern: creates just a single instance of a class
 Decorator pattern: dynamically attaches additional functionalities
 Command pattern: encapsulates a request as an object

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

In the Decorator design pattern, can more than one decorator wrap an object?

A

Yes

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

Is statement true for the decorator design pattern?
Decorators have the same supertype as the objects they
decorate, so we can pass around a decorated object in place of
the original object.

A

Yes this statement is true:
Common Supertype:

Decorators and the objects they decorate share a common supertype (interface or abstract class).
This common supertype ensures that decorators can be used interchangeably with the original objects.
Passing Decorated Objects:

Since decorators and the original objects share the same supertype, you can pass around a decorated object wherever the original object is expected.
This allows for dynamic and flexible behavior modification at runtime.

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

At what times can objects be decorated in the decorator design pattern?

A

In the Decorator design pattern, objects can be decorated at any time, allowing for dynamic runtime decoration. This is one of the key advantages of the Decorator pattern.`

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

What are some of the more important design principles in Object Oriented programming?

A

 Encapsulate what varies
 Program to an interface, not an implementation
 Favor ‘object composition’ over class inheritance
 “Open-close principle” – Classes should be open for extension but close for modification
0 “Dependency inversion principle” – Depend upon abstractions. Do not depend upon concrete classes

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

In the command pattern give a short explanation of what each of these things do?
Invoker, Command, ConcreteCommand, Receiver, Client

A

◼ Invoker: holds a command and at some point asks the
Command to carry out a request by calling its execute() method
◼ Command: declares interface for all commands (concrete
implementors therefore interchangeable)
◼ ConcreteCommand: defines the binding between an action and a
Receiver. Once bound (due to work by the Client) the Invoker
can make a request of its Command object (execute())– resulting
in the ConcreteCommand calling one or more actions on the
Receiver
◼ Receiver: Performs the work required to carry out the request.
Effectively any class can act as a Receiver.
◼ Client: Responsible for instantiating the ConcreteCommand and
setting its Receiver

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

What are Java generics

A

Java generics provide a way to create classes, interfaces, and methods that operate on different types (data types) while ensuring type safety. It allows you to write code that can be reused with different data types without sacrificing compile-time type checking.

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

Why should we use Java generics

A

◼ Facilitates the generic programming style, which allows
algorithms to be written for types to be specified ‘at some later
point’.
◼ Type parameters provide a way for you to re-use the same code
with different inputs
◼ Use can lead to safer code, as bugs that may appear at runtime
(due to casts and then accessing illegal methods), can be detected
at compile time
 Allows compile time checking of Java types
 Removes the requirement to cast objects

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

What are the three types of Java Generics

A

Generic Types
Generic methods
Generic Constructors

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

How can Java generics be implemented in code?

A

Via the use of a type variable - conventionally a Single Uppercase
Letter ( usually T)

public class Container<T> {
private T contents;
public void add(T contents) {
this.contents = contents;
}
public T get() {
return contents;
}
}</T>

◼ To use this version of Container, you need to specify what
concrete type will be used in the place of T (the type argument),
Like:
Container<Double> containedDouble;
//instantiation also needs the chevrons:
containedDouble = new Container<Double>();</Double></Double>

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

In Java generics is the score of argument class wide or limited to the method?

A

Limited to the method

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

What are Double and Integer subtypes of?

A

Number, however Container<Double> and Container<Integer> are not subtypes of Container<Number</Integer></Double>

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

What is type erasure?

A

Type erasure in Java refers to the process where the type information (generic types) is removed or “erased” during compilation. It’s a mechanism used to support backward compatibility with older Java code that does not have generics.

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

What is heap pollution?`

A

Heap pollution occurs in Java when a variable of a parameterized type (generic type) refers to an object that is not of that specific type. This can lead to unexpected behavior, unchecked warnings, and potential runtime exceptions.

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

What is a Java collection

A

Collection - an object that groups multiple elements into a single unit

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

What is the difference between a collection and a map in Java

A

Collection vs Map
 Collection – a group of objects known as elements
◼ public interface Collection<E>
 Map – a group of objects where each object maps keys to values
◼ public interface Map<K, V></E>

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

How can objects be safely removed from collections

A

Need an Iterator object if you want to safely remove
elements while iterating (methods returning these are declared by
the interfaces implementing Collection)

public interface Iterator <E> {
boolean hasNext ();
E next ();
void remove (); // optional
}</E>

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

What are some Concrete set implementations provided in the Java API and one thing about them

A

◼ HashSet<E> — fastest, but no
order guarantees, actually has a
hash table (HashMap) behind it
◼ TreeSet<E> — uses a redblack tree structure, contents
ordered based on value, slower
than HashSet
◼ LinkedHashSet<E> —
ordered based on set insertion
(stored in a hash table with a linked
list running through it)</E></E></E>

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

Define a list collection in Java

A

A List is an ordered collection of elements, that may contain duplicate
elements. Two lists are treated equal if they contain the same elements in
the same order.

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

What are some Concrete list implementations provided in the Java API and one thing about them

A

◼ ArrayList<E> — typically fastest, but not always, uses
dynamically resizing array.
◼ LinkedList<E> — doubly linked list implementation,
better performing in certain cases.</E></E>

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

Can a list be iterated through using the for-each notation

A

Yes

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

Define a Queue collection in Java

A

A Queue is a collection of elements, stored for processing.
Most concrete implementations of Queue use a first-in-first-out
ordering

86
Q

What are the methods that can be performed on the queue collection?

A

◼ The inherited add method inserts an element unless it would
violate the queue’s capacity restrictions (throwing
IllegalStateException). The offer method, for use
on bounded queues, differs, indicating insertion failure by
returning false.
◼ remove and poll both remove and return the head of the
queue. (Which element this depends on the queue’s ordering
policy.) They vary only when the queue is empty — remove
throws NoSuchElementException, while poll returns
null.
◼ element and peek methods return, but do not remove, the
head of the queue. They operate as above if the queue is empty

87
Q

What is a Deque interface?

A

◼A Deque is a double-ended
queue
◼ Insertions and deletions can
occur at either end
◼ Implementation is similar to
that for queues

88
Q

How does a Map work in Java?

A

◼ A Map has two generic type arguments, <K, V>, and is used to
map keys to values, each key mapping to at most one value

89
Q

What are some concrete map implementations

A

 HashMap<K,V>
 TreeMap<K,V>
 LinkedHashMap<K,V>

90
Q

What is reflection in Java

A

Reflection is the ability for a class or an object to examine itself

91
Q

What can reflection in java be used for?

A

◼ Allows Java code to look at the class of an object and determine
its structure
◼ Within limits imposed by the security manager of a JVM, allows
you to find out what constructors, methods and fields a class has
◼ Can use it to change values of fields, dynamically invoke methods
and construct new objects
◼ Can do this on objects your code has never even seen before
◼ Classes to support this are in the
java.lang.reflect package

92
Q

What is the standard rule of Java reflection

A

Standard rule is – another object shouldn’t be able to use the
reflection API to do things it couldn’t do with ordinary compiled
Java code (not an automatic loophole)

To be able to break open objects and see
their insides is something guarded by the JVM security manager
However, these privileges can be granted (for instance, IDEs
have to rely on this to highlight errors when debugging)

93
Q

In java everything you deal with is one of either two types, what are they?

A

A reference or a primitive object

94
Q

How can we query the properties of an object at runtime

A

Every type of object has an immutable instance of
java.lang.Class instantiated for it by the JVM – this Class
provides methods to query the properties of the object at
runtime (along with the ability to create new classes and objects)

Class is therefore the entry point for the Reflection API

95
Q

how can i get the class of an object

A

object.getClass()

If you can access the type but have no instance can obtain, using
the .class keyword after the type name. This is legal even for
primitive types:
 Class c = float.class;
^idk what Magic-D is on about

96
Q

Name at least 4 Class instance methods

A

◼ getFields() returns an array of Field instances,
containing details of all public attributes associated with the
class, including inherited ones
◼ getFields(String name) returns a Field relating to
the specified public attribute, which may be inherited
◼ getDeclaredFields() returns an array of Field
instances, containing details of all variables regardless of their
access modifiers, not including inherited ones
◼ getDeclaredField(String name) returns a Field
containing details of the specified declared variable (not
inherited)
◼ getMethods() returns an array of Method instances,
containing details of all public methods associated with the class,
including inherited one
◼ You do not inherit constructors in Java – therefore the difference
between getConstructors() and
getDeclaredConstructors() is the first only returns
public constructors, and the second all constructors

97
Q

How can you deactivate normal security when using Java reflection?

A

◼ Field, Method and Constructor all extend
AccessibleObject, which has a method called
setAccessible() – this can allow you to deactivate normal
security when accessing that class member
◼ Whether the security manager allows you to do this depends on the
JVM security manager and policy – if you are not running a security
policy this will be enabled, if however the JVM was running in an applet
or another secure environment this functionality would not be accessible.

98
Q

How is access to the reflection API controlled?

A

◼ Access to the Refection API is controlled via a security manager
◼ A fully trusted application has access to all the functionality

99
Q

What are some issues that could be caused by Java reflection?

A

◼ Because reflection involves types that are dynamically resolved,
certain Java virtual machine optimisations cannot be performed.
◼ Consequently, reflective operations have slower performance
than their non-reflective counterparts, and should be avoided in
sections of code which are called frequently in performancesensitive applications.
◼ Reflection requires a runtime permission which may not be
present when running under a security manager. This is an
important consideration for code which has to run in a restricted
security context, such as in an Applet
◼ Since reflection allows code to perform operations that would be
illegal in non-reflective code, such as accessing private fields and
methods, the use of reflection can result in unexpected sideeffects.
◼ These side-effects may render code dysfunctional and may
destroy portability.
◼ Reflective code breaks abstractions and therefore may change
behaviour with upgrades of the platform.

100
Q

What are some common uses of reflection?

A

◼ Some common uses of reflection:
 Test programs by forcing specific states
 Insuring a high level of code coverage in a test suite
 By debuggers to inspect running programs

101
Q

The reflect package API provides two reflective methods for
creating instance of classes: Constructor.newInstance()
and Class.newInstance().
Which of these methods can only invoke the no-argument constructor and which is generally preffered for that reason

A

 Class.newInstance() can only invoke the no-argument
constructor, while Constructor.newInstance() may
invoke any constructor, irrespective of the number of parameters.
 Class.newInstance() requires that the constructor be
visible; Constructor.newInstance() may invoke private
constructors (under certain circumstances).

Because of this constructor.newInstance() is generally preferred

102
Q

What are the two protocols that machines can use to connect to the internet

A

Transmission Control Protocol(TCP)
The User Datagram Protocol(UDP)

103
Q

How does TCP work and what are some important points about it’s operation

A

◼ Analogous with a telephone conversation
◼ A link between two machines established
◼ Once point-to-point communication is established (which
machine, and which port), TCP guarantees the order of data
◼ This is essential to a number of applications (e.g. HTTP, FTP,
telnet)
 E.g. when the Hypertext Transfer Protocol reads from a Uniform
Resource Locator it needs to know the right order to generate a
valid file
◼ TCP operates in such a way that an error is sent if the order is
not adhered to

104
Q

How does UDP work and what are some important points about it’s operation

A

◼ If TCP is the telephone service, then UDP is the postal service
◼ Order is not guaranteed, and neither is delivery!
◼ This means UDP doesn’t have a lot of the error-checking and
ordering overheads that TCP does
◼ It does however mean an application using UDP may have to
recombine data in various orders, and also not mind the
potential of missing data
◼ For many applications this is unsatisfactory, but for some
applications this is actually ideal
◼ UDP is not connection-based: it sends independent packets of
data (datagrams) from one application to another

105
Q

What are the purpose of data ports?

A

Ports allow a computer to siphon data to the different applications
running on the machine

106
Q

What does data passed across the internet have associated with it to make sure that it reaches it’s destination?

A

An address and a port

The destination computer will have an Internet Protocol (IP) address (32-bit), and a 16-bit port number (both of which are used by TCP and UDP)— 0-1023 well-know ports < idk what Majeed means here

107
Q

How do sockets work with connection-based communication

A

In connection-based communication, a server application has a socket bound to a specific port — effectively registering that the application on the machine will have all data sent to that port passed on to it

108
Q

How does datagram based communication work?

A

In datagram-based communication, the datagram packet contains the port number, and is routed

109
Q

In a standard set up, what knowledge must the client have to make a connection request and what is the purpose of a socket

A

The client must know the server hostname and port
where the server will be listening
In the standard set-up, a server will run on a specific computer
(IP address), and has a socket bound to a particular port for a
client to be able to make a connection request.
in addition The client also needs its own port, to accept communication from the server

110
Q

What happens, in relation to sockets, what a server accepts a connection

A

◼ If the server accepts the connection, the server will get a new
socket bound to the same local port, and a remote endpoint set
to the address of the client (IP and port)
◼ The new socket is set up so that the server can continue listening
on the original socket for requests from other clients connecting
to the port

111
Q

What are the properties in the Java.net API that use TCP?

A

URL, URLConnection, Socket, ServerSocket

112
Q

What are the properties in the Java.net API that use UDP?

A

DatagramPacket, DatagramSocket,
MulticastSocket

113
Q

What does RMI stand for

A

Remote method invocation

114
Q

What does RMI allow and how does it work?

A

Allows an object in one virtual machine to invoke methods on another object in another virtual machine(or potentially another physical machine on the network).

RMI applications generally take the form of a server and a client

The server makes some remote objects, generates accessible
references to them, and then waits for one (or more) clients to
obtain a reference, and invoke a method on it

115
Q

How are remote objects located in RMI?

A
  1. Server application registers the remote objects with the RMI
    registry
  2. Pass remote object references via invocations of methods on
    other objects
116
Q

How are remote objects communicated with in RMI?

A

Handled by the RMI framework — from a programmer’s point
of view looks very much like simple method invocation

117
Q

What are three basic components in Java RMI

A

◼ Registry
 Relates remote objects with names
◼ Server
 Calls the registry to associate (or bind) a name with a remote object
 bind() and rebind() – Naming class and Registry
interface
◼ Client
 Looks up the remote object by its name in the server’s registry and
then invokes a method on it

118
Q

What must objects and methods do to be remote in RMI?

A

◼ In order to have the potential to act as a remote object, an object
must implement an interface which extends the
java.rmi.Remote interface
◼ Additionally each method in the interface must declare that it
throws java.rmi.RemoteException

119
Q

What are the steps required to create a distributed/remote service

A
  1. Make a remote interface (i.e. define the methods that the client
    can call remotely on a remote object)
  2. Make a remote implementation (the concrete class
    implementing the interface, which provides the actual services)
  3. Use the java compiler to generate the client and server helpers
    automatically (the skeleton and stubs). (N.B. in versions before
    Java 5.0 this was done by rmic)
  4. Start the RMI registry
  5. Start the remote service
120
Q

Define Dynamic Code Loading and explain what it does

A

Dynamic code loading in Java RMI (Remote Method Invocation) is a mechanism that allows Java classes to be loaded dynamically at runtime, on demand, across a network.

Lecture slides v
◼ One of the special properties of RMI is that a program can
download a class definition, along with the object reference.
◼ New types and new behaviours can be introduced into a virtual
machine where previously they were not defined in any of the
classes available to it
◼ The behaviour of a program can thus be dynamically extended at
runtime
◼ It is a requirement that classes can be downloaded on demand
during remote method invocation.

121
Q

What are the three class loaders used when starting a JVM

A
  1. The bootstrap class loader: loads the core Java libraries – part of
    the JVM itself and written natively for efficiency
  2. The extensions class loader: loads from the system-wide, platformspecific extension directory
  3. The system class loader: loads from the current directory and any
    specified in the CLASSPATH environment variable of a system

◼ It does this in the order of precedence

You can write your own additional class loaders

122
Q

What is the advantage of writing your own class loaders?

A

Allows you to add class definitions to a program whilst it is
running

123
Q

What is the architecture of RMI?

A

◼ Application layer: The client and server program.
◼ Stub & Skeleton layer: Intercepts method calls made by the
client/redirects these calls to a remote RMI service.
◼ Remote reference layer: Understands how to interpret and manage references made from clients to the remote service objects.
◼ Transport layer: Based on TCP/IP connections between machines in a network.

124
Q

What is the difference between the distributed and non distributed models?

A

◼ Clients of remote objects interact with remote interfaces, never with
the implementation classes of those interfaces.
◼ Non-remote arguments to, and results from, a remote method
invocation are passed by copy rather than by reference.
◼ A remote object is passed by reference, not by copying the actual
remote implementation.
◼ Since the failure modes of invoking remote objects are inherently more
complicated than the failure modes of invoking local objects, clients
must deal with additional exceptions that can occur during a remote
method invocation

125
Q

What are the similarities between the distributed and non distributed models?

A

◼ According to the Java RMI specification from Oracle, the Java
distributed object model is similar to the non-distributed model
in the following ways:
 A reference to a remote object can be passed as an argument or
returned as a result in any method invocation (local or remote).
 A remote object can be cast to any of the set of remote interfaces
supported by the implementation using the syntax for casting built
into the Java programming language.
 The built-in instance of operator can be used to test the
remote interfaces supported by a remote object.

126
Q

Define a mock object and when it should be used?

A

Mock objects are cheap placeholder objects that are predictable
and allow us to test the method we need to in the current class
They should be used when the real object:
 has non-deterministic behaviour
 is difficult to set up
 has behaviour that is hard to trigger (e.g., network error)
 is slow
 has (or is) a user interface
 does not yet exist

127
Q

How can mock objects be implemented?

A
  1. Use an interface to describe the object
  2. Implement the interface for production code
  3. Implement the interface in a mock object for unit testing
128
Q

What is a test suite and what does it allow us to do?

A

Test suites allow us to group multiple test classes to run as a single
batch
They also allow us to run a specific subset of unit tests from multiple
test classes

129
Q

What are some advantages of Test-Driven development?

A

-Can help you design your code better

-You see the code from the user’s perspective not the developer’s

130
Q

Define an Invariant and if they should be tested

A

Invariants are assertions about classes/objects that should not
change – should definitely test these when developing unit tests,

Need to ensure an object can never be viewed in an inconsistent
state

131
Q

If it’s very difficult to prove that a piece of code works, how can we test it?

A

We can only satisfy ourselves that we haven’t disproved that it works

132
Q

What are some points on the importance of uni tests?

A

 Reduces time spent on debugging
 Helps communicate code’s intended use – illustrates how you
expect the code to perform on various inputs and conditions
 The code shouldn’t drift away from the limits put on them by the
tests (unless you stop running them!)

133
Q

When should the test code be written, before or after implementation?

A

Write the test code itself – either before the implementation of
the tested code base or concurrently, never afterwards
Run the unit tests and ensure that they pass as you are
developing the tested code base

134
Q

What does the Right-BICEP acronym stand for in relation to testing

A

◼ Right – are the boundary results
correct? (or “right”)
◼ B – are all the boundary conditions
correct?
◼ I – can you check the inverse
relationships?
◼ C – can you cross-check the results
using some other means?
◼ E – can you force error conditions to
occur?
◼ P – are the performance
characteristics within bounds?

135
Q

What are some properties of good tests? Use the ATRIP acronym

A

◼ Automatic
◼ Thorough
◼ Repeatable (should produce the
same results each time)
◼ Independent (of each other test and
of the environment)
◼ Professional (written and
maintained to the same standard as
the shipped code)

136
Q

How can tests be tested?

A

◼ Improve the tests while fixing bugs
◼ Prove the tests by introducing bugs
 If you are not sure that the test code is written correctly, cause the
production code to exhibit the every bug you are trying to detect
 Verify that the test fails as expecte

137
Q

What must test code be written to do

A

◼ Test code must be written to do a number of things:
1. Set up all conditions needed for testing (create any required
objects, allocate any needed resources, …)
2. Call the method to be tested on the object
3. Verify that the object/class to be tested functions as expected
4. Clean up after itself

138
Q

What is the naming convention for a test?

A

If the production code class is called Account and a method is
called createAccount.
Test should be named testCreateAccout

139
Q

How should unit tests be set up?

A

Test code must be written to do a number of things:
1. Set up all conditions needed for testing (create any required
objects, allocate any needed resources, …)
2. Call the method to be tested on the object
3. Verify that the object/class to be tested functions as expected
4. Clean up after itself

140
Q

What is a potential issue with using assertEquals with floating point values?

A

Due to representation limitations (finite memory),
floating point values are not exact - checking exact equality of
floating point values is therefore unwise

141
Q

What happens when an assertation fails in a test containing multiple assertations?

A

If one of those assertions fails the test exits and the remaining
tests are not checked

142
Q

What is the difference between polling and events

A

Polling involves repeatedly checking the state or condition of a resource or system at regular intervals while events are occurrences or notifications that happen in response to changes or actions in a system.

143
Q

What are the properties of polling vs the properties of events

A

Polling
 Easy to implement
 Wasteful of resources

Events
 More complex to write
 Much better use of resources

144
Q

What are some situations where events and listeners are commonly used?

A

Buttons pressed, textentered into boxes, checkboxes selected. Any situation where a program is waiting for something to happen, but cannot make it happen

145
Q

What is the delegation model and what role does a source, listener and event play?

A

Events in Java (from Java 1.1 onwards) use what is known as the
delegation model
◼ Events are only distributed objects which register to listen for
them
◼ Source – an object that generates an event. Event generation
most typically occurs in response to some change in internal
state of the source. A source must register listeners in order for a
listener to be notified of a particular event
◼ Listener – an object that is notified of an event occurring
 Must (1) have registered and (2) have methods to deal with these
notifications
◼ Event – an object that contains information about a state change
in a source

146
Q

What does the Java event framework consist of?

A

Consists of two concrete classes, one abstract class and an
interface (along with naming conventions)
◼ Most important elements are
 java.util.EventObject abstract class
 java.util.EventListener interface

147
Q

How do listeners work?

A

An event listener has a different method for each type of event
notification that it is interested in
Event notification method declarations are grouped together into categories
 E.g., Button - ActionEvent, Key - KeyEvent
Each category is represented by an event listener interface, which
must extend java.util.EventListener
To be notified of events a class must implement at least one
listener interface

148
Q

Will an event listener class relate to a single event class and can it have multiple event notification methods?

A

Typically an event listener interface will relate to a single event class
 ActionListener – ActionEvent
 KeyListener – KeyEvent

An event listener may have multiple event notification methods that take the same event class as an argument
 KeyListener
◼ keyPressed (KeyEvent e), keyReleased (KeyEvent
e), keyTyped (KeyEvent e)

149
Q

What are the three core areas of requirements analysis

A

 Requirements gathering
 Requirements analysis: are the gathered requirements clear,
complete, consistent and unambiguous?
 Formal recording of requirements (documentation) – can be in the
form of use cases, stories, formal lists and specifications

150
Q

Describe High-level design

A

 Will describe the platforms, systems, products, services, that the
developed system will depend on (and additionally cover any
significant changes that need to be made to these external systems)
 Typically will include an architecture diagram – this will show the
interface, components and networks that need to be further
specified or developed

151
Q

Describe Detailed Design

A

 Specifies how the system will be constructed
 For instance what the functions/objects/methods should be
 Once the detailed design is generated it should be possible to
write the tests before the actual system is implemented

152
Q

What is Unit Testing

A

◼ Testing individual blocks of code in terms of correctness
◼ In procedural programming this is typically at the function level
◼ In OO programming this is usually at the object/class/method
level
◼ Probably the most widely used testing type that you have done
so far (albeit probably informally)

153
Q

What is Integration Testing

A

◼ To this point, we’ve only discussed the testing of individual
components
◼ These must be grouped together or integrated to form the final
system
◼ Unexpected behaviour may arise at this point, which is checked
for here

154
Q

What is System testing

A

◼ As the name suggests – testing the entire system as a whole
◼ Also checks that it doesn’t impair performance on the wider
environment
 Affecting broader resource availability on the OS
 Affecting other applications working on the same system

155
Q

What is User acceptance testing?

A

◼ User Acceptance Test plans are developed during the
requirements analysis phase and are composed by users
◼ UAT is performed in a user environment that resembles the
production environment and uses realistic data
◼ UAT ensures that the delivered system meets the user’s
requirements and system is ready for use in real time
◼ It is a validation activity rather than a verification activity

156
Q

What are the advantages of the V Testing Model

A

-Highly structured, phases completed one at a time
-Works well where all requirements are understood
-Simple to understand
-Easy to manage - each phase has a definite end with a review

157
Q

What are disadvantages of the V model

A

-Once a project is in the testing phase it is difficult to go back and change functionality
- Not suitable for projects where the requirements might change
-No working software created until late in the cycle

158
Q

What is static testing?

A

Static testing – assessing documents (review, walkthroughs, …)

159
Q

What is Dynamic testing?

A

Dynamic testing – testing that involves executing program
code

160
Q

Define white box testing

A

White box testing – testing where the internals of the program
are known, so can test explicit paths through the system (code
coverage)

161
Q

Define black box testing?

A

 Black box testing – treats code as a “black box”, and therefore is
only concerned with functionality

162
Q

Define grey box testing

A

Grey box testing – know both the required functionality and also
some of the implementation concepts (and/or access to data stores
not user accessible in the live system) which can be used in test
design, but not code base exposed

163
Q

What are the advantages and disadvantages of white box testing

A

Advantages
-Code can be seen so tests can be designed to test many paths through the program

Disadvantages
-Knowledge of the internals will influence the testing – can lead to bias in test design

164
Q

What are the advantages and disadvantages of black box testing

A

Advantages
-No knowledge of internals so no “programmer bias” – more likely to result in tests not expected by the programmer
Disadvantages
-High probability that tests will only test a small number of paths through the program

165
Q

Define code coverage and some properties about it

A

Code coverage attempts to measure how much of your code has
been tested (or the degree to which it has been tested)
-It look directly at the code
◼ Different measures of coverage are often referred to – some are
simply infeasible to completely cover
◼ So often a choice has to be made on how much code can be
covered

166
Q

Define the 4 code coverage types

A

◼ Function/method/(sub)routine coverage – has each method
written had a test written (and run) on it? This includes
constructors and invocations of methods not externally
accessible
◼ Statement coverage – has each line of code been processed by
at least one of your suite of tests?
◼ Decision coverage – has every decision edge been traversed in
your code (if/else)?
◼ Predicate coverage – has every condition been tested? (not
always the same decision coverage)

167
Q

Explain corner cases in code coverage

A

Related to edge cases – where a variable takes its maximum or
minimum possible value
Where many variables are at their extremes, said to be a corner
case
Most tests are focused on typical system uses, and therefore tend
to miss situations where multiple extremes occur

168
Q

What are some advantages to version control

A

◼ A fundamental tool in modern software development
◼ Gives a development team a project-wide ‘undo button’
◼ Allows multiple developers to work on the same code base in a
controlled manner – code no longer lost through overwrites
◼ Keeps a record of changes – can find out who has made
‘surprising code’ (and log commits explaining why)
◼ Can support multiple releases at the same time – no need to
freeze development leading up to a release
◼ Project-wide time machine can examine how the project looked
at particular dates/release versions, which is important when
supporting customers if they have problems

169
Q

What is a repository

A

A place to store all your project files/documents/directories
Repository acts as a server, usually based on a safe, secure and
reliable machine
Some system need constant network communication – some
allow local changes offline to resynchronise later
Some allow multiple repositories, some just one central master
repository

170
Q

What are some things that should be stored in a repository

A

◼ Source
◼ Build scripts
◼ Project documents
◼ Everything you need if your local machines died!!
◼ But not things like automatically generated API document

171
Q

What is a revision tag?

A

◼ Allow you to provide text for
particularly important revisions
◼ Easier to remember and more
informative than version
numbers
◼ For example, you might tag a
particular combination of files
for a release

172
Q

What is the Trunk?

A

Main code base that developers are working on

173
Q

What does it mean if the project has a fork?

A

A project fork historically means a schism in the development
team or perhaps a new development team working on a new
code direction derived from the old
 Means an independent branch of development

174
Q

What is locking and what’s the difference between strict and Optimistic locking

A

Locking is used to make sure two+ people don’t change the file at the same time
Strict locking:
 Only one person can change a file at any one time
Optimistic locking:
 All files can be changed, but if changed in the repository since last check out then local copy needs to be updated before you can commit the change.

175
Q

How does version control deal with binary files or file that have a lock?

A

Most version control systems will detect when a file is binary as
opposed to text based (like a Java file) and will mark it as nonmergable
◼ In this situation conflicts will have to be merged through
manually merging the two files

176
Q

Define Concurrency and it’s advantages

A

To be able to perform multiple processes at the same time –
including the potential interaction between them
 Multiple tasks at the same time sometimes called ‘parallelism’
adv:
 Allowing programs to interact with other systems/users
 Multi-core systems

177
Q

What can threads be treated as?

A

Threads can be treated as a lightweight process, they exist within a process. We use threads as they have shared memory space

178
Q

How can a single processor run threads?

A

Single process runs them virtually unlike a multi core processor which runs them actually

179
Q

Define liveness

A

Liveness is making sure that threads stay live, e.g that they can continue to execute despite concurrent execution challenges like deadlocks and livelocks

180
Q

How can threads be created in Java

A

In two ways:
❑ Using (and extending) the Thread class
❑ Using the Runnable interface

181
Q

How can threads be stopped?

A

By setting a flag:
-Loop will exit (and thread will stop) on the next iteration after done is set to true

By Interrupting:
-When isInterrupted() is called for this thread, it will stop
◼ Except that if the thread is sleeping /waiting will throw InterruptedException and immediately return from run()

182
Q

Define a race condition

A

When two threads try to access/change data at the same time it’s
known as a race condition

183
Q

How can Synchronization be achieved?

A

Simply add the synchronize keyword to the methods in the class
 When one thread is executing a synchronized method for an
object, all other threads that invoke synchronized methods for the
same object block suspend execution until the first thread is
done with the object

184
Q

How can only one block of code be synchronised?

A

Via statement synchronization e.g
synchronized (this){
// everything in here is synchronised

}

185
Q

Define atomic actions

A

In programming, atomic actions are self-contained, they cannot
be stopped in the middle
 They either happen or they don’t

186
Q

Why do threads have nondeterministic behaviors and what is in charge of scheduling them?

A

Threads in concurrent programming exhibit nondeterministic behavior due to the unpredictable nature of their execution.
Threads are scheduled by the operating system or a thread scheduler, and the order in which threads are executed is not strictly controlled by the program itself.

187
Q

What are the three things in java that can cause liveliness issues

A

Deadlock, starvation, and livelock

188
Q

Define a deadlock

A

A deadlock is a situation in concurrent programming where two or more threads are unable to proceed because each is waiting for the other to release a resource, creating a circular dependency and preventing any progress in the system.

189
Q

Define starvation

A

Where a thread can’t gain regular access to shared resources
because another thread is frequently calling the object’s methods

190
Q

Define a livelock

A

A little like deadlock except that it occurs when two threads are
too busy responding to one another to do work
A little like deadlock except that it occurs when two threads are
too busy responding to one another to do work

191
Q

what does void wait() do?

A

Waits for a condition to occur, must call from synchronised method/block.
In addition you can add a time inside the brackets of wait to signify how long wait should wait for
The wait() method releases the lock and regains it using
notify(). This is done natively

192
Q

What does void notify do?

A

notifies a waiting thread a condition has occurred, must call from
synchronised method/block (also void notifyAll();).
 allows thread communication

193
Q

What are the differences between the wait and sleep methods

A

wait
 Must occur in a block synchronised on the monitor object
 Releases the monitor (lock) when called and doesn’t sacrifice the
remainder of its timeslice
 Will wake up if notified via a notify call

sleep
 Does not need to occur in a synchronised block
 Retains the monitor (lock) when called and sacrifices the remainder
of its timeslice
 A sleeping thread can only be woken up by an interruption (not by
notify)

194
Q

What is the thread lifecycle

A

New: The thread is in the new state when it is instantiated but has not yet started. The Thread object is created, but the start() method has not been called.

Runnable: After calling the start() method, the thread enters the runnable state. It is ready to run, but the scheduler has not yet selected it to be the running thread.

Running: The thread enters the running state when the scheduler has chosen it to execute. It actively performs its task or runs its code.

Terminated (Dead): The thread enters the terminated state when its run() method completes or when it is explicitly stopped. Once terminated, a thread cannot be restarted.

195
Q

What do the Waiting, sleeping and blocking states mean for threads?

A

Blocked: A thread transitions to the blocked state when it is temporarily inactive. This can occur when it is waiting for a resource, such as I/O or a lock, to become available.

Waiting: A thread enters the waiting state when it waits for another thread to perform a specific action, often notified by the notify() or notifyAll() methods.

Sleeping (Timed Waiting): A thread enters the sleeping state when it voluntarily relinquishes its CPU time for a specified period using the Thread.sleep(long milliseconds) method. During this time, the thread is not actively running, but it is not blocked or waiting for a specific condition. After the sleep duration, the thread transitions back to the runnable state.

196
Q

What does yield() do?

A

◼ yield() causes the currently executing thread object to pause
and allow other threads to execute.
◼ If no other threads of the same priority need to execute,
execution of this thread continues
◼ Identifies the current thread as doing something not particularly
important

197
Q

what does join() do?

A

◼ Simple function allows one thread to wait for the completion of
another.
t.join()
◼ Like sleep, join responds to an interrupt by exiting with an
InterruptedException

198
Q

What design documents must be created before coding can begin?

A

 Software Architecture
 Data flow diagram
 State transition diagram
 Flowchart
 Commented code

199
Q

What are some advantages that OOP provides over other languages?

A

 Encapsulation/information
hiding
 Inheritance
 Polymorphism

200
Q

What is an occasion where OO programming could get in the way

A

Consider if you have two tightly coupled classes
 Rely heavily on the members in each class
 Lots of work involved in creating functions to access those
members
 Occurs more frequently in GUI programming

201
Q

What are nested classes?

A

It’s where classes that are closely linked can be located in one place, If 1 class is only used by one other then this link can be made explicit by making it a nested class. It can increase encapsulation and make the code more readable.
Is essentially a class defined within a class

202
Q

What is a static nested class and an Inner class?

A

A static nested class does not have access to instance members while an Inner class does

203
Q

What are the modifiers that a standard outer class can be declared with?

A

A standard outer class (or top-level
class) can only be declared with two
modifiers, public and the default
(implicit) package private

204
Q

What are the modifiers that a nested class can be declared with?

A

A standard outer class (or top-level
class) can only be declared with two
modifiers, public and the default
(implicit) package private

205
Q

What happens in compilation when there’s an inner class?

A

Will produce two class files
on compilation
 OuterClass.class
 OuterClass$InnerClass.class

206
Q

What instance can inner classes be accessed by?

A

Inner classes can be directly accessed by the enclosing instance

207
Q

From where can nested classes be accessed from?

A

All nested classes can be accessed externally (but must have
appropriate visibility modifier) through either the containing
class or object

208
Q

Where are local classes defined?

A

Local classes are defined and exist solely within a block (usually a
method)

209
Q

What modifiers can local classes contain?

A

Local class declaration cannot contain public, protected,
private, or static access modifiers.

210
Q

What are local classes able to access

A

◼ Cannot access method local variables (unless passed as
arguments) unless they are declared as final
◼ Can access all the members of the outer class instance like
standard inner class members

211
Q

What are Anonymous classes?

A

◼ Potentially one of the most convoluted aspects of Java
◼ Classes that are declared without any class name at all - therefore
they are named anonymous classes
◼ Not only may these be defined within a method, they may also
be defined within an argument to a method

212
Q

What are enumerated classes?

A

Enumerated classes, or enums for short, are a special type of data type in programming languages that define a set of named values. Each value represents a constant, and the entire set of values defines a distinct enumeration. Enumerations are used to represent a fixed number of well-defined constants, making the code more readable, maintainable, and less error-prone.