Software Development Flashcards

(212 cards)

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
What are the benefits and characteristics of test-driven development?
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.
26
What principles guide design patterns in software development?
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.
27
What are the three types of design patterns?
Creational Patterns, Structural Patterns, Behavioral Patterns
28
How do factory patterns and abstract factory patterns differ in terms of their design principles?
 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.
29
What functionalities do builder patterns provide in the context of constructing complex objects?
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.
30
How do factory patterns and builder patterns differ in the way they construct objects?
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.
31
What are key characteristics of decorators in the decorator design pattern?
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.
32
How do generics contribute to program development in Java?
Generics in Java make many bugs in a program detectable at compile time, ensuring type safety and enhancing code robustness.
33
What are generic types in Java programming, and how are they represented?
Generic types in Java programming include generic classes parameterized over types, and a single uppercase letter is commonly used to represent the type.
34
What functionalities do bulk operations in the Set interface provide?
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.
35
: What distinguishes HashSet and TreeSet in terms of order guarantees?
HashSet has no order guarantees, while TreeSet maintains order guarantees based on natural ordering or a provided comparator.
36
How is reflection utilized in Java programming, and what functionalities does it provide?
Reflection in Java allows dynamic invocation of methods, construction of new objects, and changing values of fields during runtime.
37
What distinctions exist between the getFields() and getDeclaredFields() methods in Java programming?
getFields() returns an array of Field instances, including inherited ones. getDeclaredFields() returns an array of Field instances, not including inherited ones.
38
What considerations and characteristics are associated with reflective operations in Java programs?
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.
39
What are the fundamental characteristics and functionalities of Transmission Control Protocol (TCP)?
TCP establishes a reliable link between two communication machines and guarantees the order of data transmission, ensuring data integrity during communication.
40
What is the purpose of the Factory Design Pattern?
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.
41
In the context of the Factory Pattern, what is the role of the abstract creator, using an example?
An abstract class or interface defines a factory method (e.g., createPizza). This class is made abstract to allow subclasses to provide specific implementations.
42
Explain Concrete creators in the Factory pattern
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.
43
Explain Product creation in the Factory Design Patterns
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.
44
Give an overview of the builder pattern
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
45
How does the builder pattern work?
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.
46
What are advantages of the builder pattern
 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.
47
Difference between Factory, Abstract factory and builder patterns
 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
48
What state changes will happen in the thread lifecycle when calling yield() in Java?
From the running state to the runnable state.
49
What is a correct statement about the use of the Lock interface?
Two or more objects can share a lock.
50
Name the Creational Design Patterns
Factory Pattern, Abstract Factory Pattern, Singleton Pattern, Prototype Pattern, Builder Pattern
51
Name the Structural Design Patterns
Adapter Pattern, Bridge Pattern, Composite Pattern, Decorator Pattern, Facade Pattern, Flyweight Pattern, Proxy Pattern
52
Name the Behavioural Design Patterns
Chain Of Responsibility Pattern, Command Pattern, Interpreter Pattern, Iterator Pattern, Mediator Pattern, Memento Pattern, Observer Pattern, State Pattern, Strategy Pattern, Template Pattern, Visitor Pattern
53
What Pattern type does Composite pattern apply to
Structural pattern
54
Give a simple overview of the Singleton Design pattern
Ensures that a class has only one instance, and provides a global point of access to it
55
What are some examples of things that follow the Singleton pattern Design methodology
Window Managers, File Systems, Print Spoolers
56
In the Singleton design pattern a class employs a technique called lazy instantiation, what is this?
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).
57
How can a thread safe singleton class be created?
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.
58
What is the double checked locking principle in relation to thread safe singleton classes
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.
59
Give a short overview of the Decorator pattern
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
60
What are some principles of the Decorator design pattern
-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
61
What are some facts about Decorators in the Decorator design pattern
◼ 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
62
Summerise the Command Design Pattern
Encapsulates a request as an object, thereby letting you parameterise other objects with different requests, queue or log requests, and support undoable operations.
63
What Type of design pattern is Command Design
Behavioral
64
What are all the design patterns we need to know and a small summary about each of them
 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
65
In the Decorator design pattern, can more than one decorator wrap an object?
Yes
66
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.
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.
67
At what times can objects be decorated in the decorator design pattern?
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.`
68
What are some of the more important design principles in Object Oriented programming?
 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
69
In the command pattern give a short explanation of what each of these things do? Invoker, Command, ConcreteCommand, Receiver, Client
◼ 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
70
What are Java generics
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.
71
Why should we use Java generics
◼ 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
72
What are the three types of Java Generics
Generic Types Generic methods Generic Constructors
73
How can Java generics be implemented in code?
Via the use of a type variable - conventionally a Single Uppercase Letter ( usually T) public class Container { private T contents; public void add(T contents) { this.contents = contents; } public T get() { return contents; } } ◼ 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 containedDouble; //instantiation also needs the chevrons: containedDouble = new Container();
74
In Java generics is the score of argument class wide or limited to the method?
Limited to the method
75
What are Double and Integer subtypes of?
Number, however Container and Container are not subtypes of Container
76
What is type erasure?
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.
77
What is heap pollution?`
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.
78
What is a Java collection
Collection - an object that groups multiple elements into a single unit
79
What is the difference between a collection and a map in Java
Collection vs Map  Collection – a group of objects known as elements ◼ public interface Collection  Map – a group of objects where each object maps keys to values ◼ public interface Map
80
How can objects be safely removed from collections
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 { boolean hasNext (); E next (); void remove (); // optional }
81
What are some Concrete set implementations provided in the Java API and one thing about them
◼ HashSet — fastest, but no order guarantees, actually has a hash table (HashMap) behind it ◼ TreeSet — uses a redblack tree structure, contents ordered based on value, slower than HashSet ◼ LinkedHashSet — ordered based on set insertion (stored in a hash table with a linked list running through it)
82
Define a list collection in Java
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.
83
What are some Concrete list implementations provided in the Java API and one thing about them
◼ ArrayList — typically fastest, but not always, uses dynamically resizing array. ◼ LinkedList — doubly linked list implementation, better performing in certain cases.
84
Can a list be iterated through using the for-each notation
Yes
85
Define a Queue collection in Java
A Queue is a collection of elements, stored for processing. Most concrete implementations of Queue use a first-in-first-out ordering
86
What are the methods that can be performed on the queue collection?
◼ 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
What is a Deque interface?
◼A Deque is a double-ended queue ◼ Insertions and deletions can occur at either end ◼ Implementation is similar to that for queues
88
How does a Map work in Java?
◼ A Map has two generic type arguments, , and is used to map keys to values, each key mapping to at most one value
89
What are some concrete map implementations
 HashMap  TreeMap  LinkedHashMap
90
What is reflection in Java
Reflection is the ability for a class or an object to examine itself
91
What can reflection in java be used for?
◼ 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
What is the standard rule of Java reflection
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
In java everything you deal with is one of either two types, what are they?
A reference or a primitive object
94
How can we query the properties of an object at runtime
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
how can i get the class of an object
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
Name at least 4 Class instance methods
◼ 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
How can you deactivate normal security when using Java reflection?
◼ 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
How is access to the reflection API controlled?
◼ Access to the Refection API is controlled via a security manager ◼ A fully trusted application has access to all the functionality
99
What are some issues that could be caused by Java reflection?
◼ 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
What are some common uses of reflection?
◼ 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
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
 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
What are the two protocols that machines can use to connect to the internet
Transmission Control Protocol(TCP) The User Datagram Protocol(UDP)
103
How does TCP work and what are some important points about it's operation
◼ 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
How does UDP work and what are some important points about it's operation
◼ 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
What are the purpose of data ports?
Ports allow a computer to siphon data to the different applications running on the machine
106
What does data passed across the internet have associated with it to make sure that it reaches it's destination?
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
How do sockets work with connection-based communication
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
How does datagram based communication work?
In datagram-based communication, the datagram packet contains the port number, and is routed
109
In a standard set up, what knowledge must the client have to make a connection request and what is the purpose of a socket
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
What happens, in relation to sockets, what a server accepts a connection
◼ 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
What are the properties in the Java.net API that use TCP?
URL, URLConnection, Socket, ServerSocket
112
What are the properties in the Java.net API that use UDP?
DatagramPacket, DatagramSocket, MulticastSocket
113
What does RMI stand for
Remote method invocation
114
What does RMI allow and how does it work?
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
How are remote objects located in RMI?
1. Server application registers the remote objects with the RMI registry 2. Pass remote object references via invocations of methods on other objects
116
How are remote objects communicated with in RMI?
Handled by the RMI framework — from a programmer’s point of view looks very much like simple method invocation
117
What are three basic components in Java RMI
◼ 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
What must objects and methods do to be remote in RMI?
◼ 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
What are the steps required to create a distributed/remote service
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
Define Dynamic Code Loading and explain what it does
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
What are the three class loaders used when starting a JVM
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
What is the advantage of writing your own class loaders?
Allows you to add class definitions to a program whilst it is running
123
What is the architecture of RMI?
◼ 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
What is the difference between the distributed and non distributed models?
◼ 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
What are the similarities between the distributed and non distributed models?
◼ 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
Define a mock object and when it should be used?
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
How can mock objects be implemented?
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
What is a test suite and what does it allow us to do?
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
What are some advantages of Test-Driven development?
-Can help you design your code better -You see the code from the user’s perspective not the developer’s
130
Define an Invariant and if they should be tested
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
If it's very difficult to prove that a piece of code works, how can we test it?
We can only satisfy ourselves that we haven’t disproved that it works
132
What are some points on the importance of uni tests?
 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
When should the test code be written, before or after implementation?
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
What does the Right-BICEP acronym stand for in relation to testing
◼ 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
What are some properties of good tests? Use the ATRIP acronym
◼ 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
How can tests be tested?
◼ 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
What must test code be written to do
◼ 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
What is the naming convention for a test?
If the production code class is called Account and a method is called createAccount. Test should be named testCreateAccout
139
How should unit tests be set up?
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
What is a potential issue with using assertEquals with floating point values?
Due to representation limitations (finite memory), floating point values are not exact - checking exact equality of floating point values is therefore unwise
141
What happens when an assertation fails in a test containing multiple assertations?
If one of those assertions fails the test exits and the remaining tests are not checked
142
What is the difference between polling and events
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
What are the properties of polling vs the properties of events
Polling  Easy to implement  Wasteful of resources Events  More complex to write  Much better use of resources
144
What are some situations where events and listeners are commonly used?
Buttons pressed, textentered into boxes, checkboxes selected. Any situation where a program is waiting for something to happen, but cannot make it happen
145
What is the delegation model and what role does a source, listener and event play?
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
What does the Java event framework consist of?
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
How do listeners work?
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
Will an event listener class relate to a single event class and can it have multiple event notification methods?
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
What are the three core areas of requirements analysis
 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
Describe High-level design
 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
Describe Detailed Design
 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
What is Unit Testing
◼ 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
What is Integration Testing
◼ 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
What is System testing
◼ 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
What is User acceptance testing?
◼ 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
What are the advantages of the V Testing Model
-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
What are disadvantages of the V model
-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
What is static testing?
Static testing – assessing documents (review, walkthroughs, …)
159
What is Dynamic testing?
Dynamic testing – testing that involves executing program code
160
Define white box testing
White box testing – testing where the internals of the program are known, so can test explicit paths through the system (code coverage)
161
Define black box testing?
 Black box testing – treats code as a “black box”, and therefore is only concerned with functionality
162
Define grey box testing
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
What are the advantages and disadvantages of white box testing
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
What are the advantages and disadvantages of black box testing
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
Define code coverage and some properties about it
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
Define the 4 code coverage types
◼ 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
Explain corner cases in code coverage
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
What are some advantages to version control
◼ 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
What is a repository
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
What are some things that should be stored in a repository
◼ Source ◼ Build scripts ◼ Project documents ◼ Everything you need if your local machines died!! ◼ But not things like automatically generated API document
171
What is a revision tag?
◼ 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
What is the Trunk?
Main code base that developers are working on
173
What does it mean if the project has a fork?
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
What is locking and what's the difference between strict and Optimistic locking
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
How does version control deal with binary files or file that have a lock?
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
Define Concurrency and it's advantages
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
What can threads be treated as?
Threads can be treated as a lightweight process, they exist within a process. We use threads as they have shared memory space
178
How can a single processor run threads?
Single process runs them virtually unlike a multi core processor which runs them actually
179
Define liveness
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
How can threads be created in Java
In two ways: ❑ Using (and extending) the Thread class ❑ Using the Runnable interface
181
How can threads be stopped?
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
Define a race condition
When two threads try to access/change data at the same time it’s known as a race condition
183
How can Synchronization be achieved?
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
How can only one block of code be synchronised?
Via statement synchronization e.g synchronized (this){ // everything in here is synchronised ... }
185
Define atomic actions
In programming, atomic actions are self-contained, they cannot be stopped in the middle  They either happen or they don’t
186
Why do threads have nondeterministic behaviors and what is in charge of scheduling them?
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
What are the three things in java that can cause liveliness issues
Deadlock, starvation, and livelock
188
Define a deadlock
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
Define starvation
Where a thread can’t gain regular access to shared resources because another thread is frequently calling the object’s methods
190
Define a livelock
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
what does void wait() do?
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
What does void notify do?
notifies a waiting thread a condition has occurred, must call from synchronised method/block (also void notifyAll();).  allows thread communication
193
What are the differences between the wait and sleep methods
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
What is the thread lifecycle
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
What do the Waiting, sleeping and blocking states mean for threads?
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
What does yield() do?
◼ 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
what does join() do?
◼ 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
What design documents must be created before coding can begin?
 Software Architecture  Data flow diagram  State transition diagram  Flowchart  Commented code
199
What are some advantages that OOP provides over other languages?
 Encapsulation/information hiding  Inheritance  Polymorphism
200
What is an occasion where OO programming could get in the way
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
What are nested classes?
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
What is a static nested class and an Inner class?
A static nested class does not have access to instance members while an Inner class does
203
What are the modifiers that a standard outer class can be declared with?
A standard outer class (or top-level class) can only be declared with two modifiers, public and the default (implicit) package private
204
What are the modifiers that a nested class can be declared with?
A standard outer class (or top-level class) can only be declared with two modifiers, public and the default (implicit) package private
205
What happens in compilation when there's an inner class?
Will produce two class files on compilation  OuterClass.class  OuterClass$InnerClass.class
206
What instance can inner classes be accessed by?
Inner classes can be directly accessed by the enclosing instance
207
From where can nested classes be accessed from?
All nested classes can be accessed externally (but must have appropriate visibility modifier) through either the containing class or object
208
Where are local classes defined?
Local classes are defined and exist solely within a block (usually a method)
209
What modifiers can local classes contain?
Local class declaration cannot contain public, protected, private, or static access modifiers.
210
What are local classes able to access
◼ 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
What are Anonymous classes?
◼ 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
What are enumerated classes?
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.