Software Development Flashcards
What are characteristics of Waterfall software development approaches?
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.
What are Characteristics of Agile software development?
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 are static nested classes and inner classes accessed
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.
What are local classes
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.
What are anonymous classes
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.
What are important aspects of multithreading in software development?
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.
What defines race conditions in Java programming, and how can they be addressed?
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.
What constitutes liveness problems in multithreading, and are they avoidable?
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 do wait() and sleep() methods function in Java programs?
What stages define the lifecycle of a thread in Java programs?
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.
What are the potential issues associated with stale data in software development?
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.
What Design Pattern does the Memento Pattern apply to?
Behavioral Patterns
What Design pattern does Iterator patterns belong to?
Behavioral Patterns
What Design pattern does Singleton pattern belong to
Creational Patterns
What Design pattern does decorator pattern belong to?
Structural Pattern
How do polling and event-driven programming differ in terms of event handling in Java?
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.
Define polymorphism
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.
What is a concrete class?
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.
What are the different levels of testing in software development?
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 do white box and black box testing differ, and what are their characteristics?
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.
What factors should be considered when conducting unit tests in software development?
When performing unit tests in software development, it’s crucial to consider factors such as boundary conditions, inverse relationships, boundary results, and performance characteristics.
What qualities define good tests in software development?
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.
What practices contribute to effective unit testing in software development?
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.
When should mock objects be utilized in software testing?
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.
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.
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.
What are the three types of design patterns?
Creational Patterns, Structural Patterns, Behavioral Patterns
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.
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.
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.
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.
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.
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.
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.
: What distinguishes HashSet<E> and TreeSet<E> in terms of order guarantees?</E></E>
HashSet<E> has no order guarantees, while TreeSet<E> maintains order guarantees based on natural ordering or a provided comparator.</E></E>
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.
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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
What state changes will happen in the thread lifecycle when calling yield() in Java?
From the running state to the runnable state.
What is a correct statement about the use of the Lock interface?
Two or more objects can share a lock.
Name the Creational Design Patterns
Factory Pattern, Abstract Factory Pattern, Singleton Pattern,
Prototype Pattern, Builder Pattern
Name the Structural Design Patterns
Adapter Pattern, Bridge Pattern, Composite Pattern, Decorator
Pattern, Facade Pattern, Flyweight Pattern, Proxy Pattern
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
What Pattern type does Composite pattern apply to
Structural pattern
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
What are some examples of things that follow the Singleton pattern Design methodology
Window Managers, File Systems, Print Spoolers
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).
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.
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.
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
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
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
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.
What Type of design pattern is Command Design
Behavioral
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
In the Decorator design pattern, can more than one decorator wrap an object?
Yes
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.
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.`
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
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
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.
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
What are the three types of Java Generics
Generic Types
Generic methods
Generic Constructors
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<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>
In Java generics is the score of argument class wide or limited to the method?
Limited to the method
What are Double and Integer subtypes of?
Number, however Container<Double> and Container<Integer> are not subtypes of Container<Number</Integer></Double>
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.
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.
What is a Java collection
Collection - an object that groups multiple elements into a single unit
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<E>
Map – a group of objects where each object maps keys to values
◼ public interface Map<K, V></E>
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 <E> {
boolean hasNext ();
E next ();
void remove (); // optional
}</E>
What are some Concrete set implementations provided in the Java API and one thing about them
◼ 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>
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.
What are some Concrete list implementations provided in the Java API and one thing about them
◼ ArrayList<E> — typically fastest, but not always, uses
dynamically resizing array.
◼ LinkedList<E> — doubly linked list implementation,
better performing in certain cases.</E></E>
Can a list be iterated through using the for-each notation
Yes