Software Development

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is the syntax of a lambda expression

(arguments) -> {body} can have zero or more arguments argument can be declared or inferred. With only a single inferred argument no brackets are necessary. The same with the body if it only has 1 expression

What do you need to create when creating a custom events and Listeners

- A custom event class - A custom event listener interface - Listeners to respond to the event - An event source class

Briefly explain TCP network communication

- A link between 2 machines is established - Once point-to-point communication is established (which machine and port), TCP guarentees the order of data - This is essential to a number of applications - TCP operates in such a way that an error is sent if the data does arrive in the order it is sent.

Explain what must happen for a client to communicate with a server

- A server will run on a specific computer (IP) and has a socket bound to a particular port - The client must know the hostname and port where the server is listening - The client needs its own socket bound to a port to accept communication - If the server accepts the communication a new socket is bound to the same port, so that the server can continuing listening on the original socket.

Gives some uses of RMI

- Allowing different servicess to be provided across different machines - Allows dynamic runtime behaviour of a JVM, beyond the set of class definition available to a JVM at its commencement.

Why do we use Java Generics

- Allows more bugs to be detected at compile time - Facilitates the generic programming style were algorithms can 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 can be detected at compile time. - Allows compile time checking of java types, removes the requirement to cast objects

How does a VCS provide better team cooperation

- Allows multiple developers to simultaneously work on the same project in a controlled manner

Why do we use enums over just integers

- Because we would have to map between integers and for example days or whatever we are using our enum for - We would have to check if the integers were within a range. Enums remove this factor as they only take fixed values

What are the advantages of pair programming

- Better productivity than 2 independent developers - Promotes dissemination of project knowledge among the team - Good for transferring skills to junior developers

Why do we need a VCS

- Better team cooperation - Track changes - Track ownership - Multiple releases

Compare and contrast the Factory Method Pattern vs. the Abstract Factory Pattern

- Both encapsulate object creation, leading to more decoupled, flexible designs - Both strive for abstraction promoting loose coupling by reducing dependency on concrete classes - The Factory pattern uses inheritance and gives you a complete object in one shot - Abstract factory pattern uses composition (It defines an abstract type for creating a family of products and lets subclasse decide how those products are produced) and returns a family of related classes

What is the most common use of events in Java and why

- Designing GUIs - This is so that buttons can be pressed, text can be entered - Checkboxes can be selected - Your program needs to be able to react to these events

What is Distributed Version Control

- Each user gets their own repository and working copy - After your commit, others have no access to your changes until you push changes to the central repository You commit You push They pull They update

What are the benefits 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.

Give 4 examples of VCSs

- Git - Mercurial - Concurrent Versions System (CVS) - Subversion (SVN)

What is integration testing

- Grouping together indivudal components and integrating them to form the final system - Unexpected behaviour may arise which is what we test for

How does RAD differ from standard software development

- Heavy focus on tools to reduce development time (e.g. IDE's GUI builders) - The planning and software implementation are interleaved - The business needs are of paramount importance - The deadline is prioritised over requirements so you may scrap features to meet the deadline

Explain how the software development industry uses prototyping

- Involves including end users during the development process - Lower functionality prototypes are constructed to try out ideas and get feedback - Tightly couples analysis, design and implementation phases. This leads to prototypes that feedback can be given about. - Generally prototypes will be discarded

What are the advantages and disadvantages of the waterfall approach

- Leads to well documented projects - However it means that errors can propagate through if not spotted, which can be expensive to fix - Very good for small projects where a clear set of requirements can be set out

What are the stages in creating a system that uses RMI

- Make a remote interface (define the methods that the client can call remotely on the object) - Make a remote implementation (the class implementing the interface, which provides the actual services) - Develop the server program, which creates an object and binds it to the RMI registry - Develop the client program - which accesses the remote object stored in the registry - Start the RMI registry - Compile and run the server - Compile and run the client

What is good practise when committing to a VCS

- Make each commit a logical unit, and use a descriptive commit message - Test before you commit - Don't commit generated files e.g. .class files

What factors should play into deciding a software development model

- Project type - Your preference - Employer preference - Customer preferences - Yours/the team's abilities

What is dynamic code loading

- RMI is downloading a class definition as well as an object reference - Therefore new types and behaviours can be introduced to classes in their source JVM whilst another JVM is running - This allows programs to be dynamically extended at runtime

What is the importance of Unit testing

- Reduces time spent on debug - 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 tests (unless you stop running them).

Outside of running the test itself what must your test code accomplish

- Setup all conditions needed for testing - Call the method to be tested on the object - Verify that the object/class to be tested function as expcted - Cleans up after itself

How is a scrum implemented

- Sprint planning meeting which decides which items will be worked on, identifies the sprint tasks and divides the sprint into timeboxes - Daily scrum meeting which summarises the previous day's work and the coming day's. Intended to foster collaboration - Sprint review meeting which includes a demonstration of the completed software. The project owner determines which items of work are complete

How do we implement the Singleton pattern

- Static member: Create a private static variable of the Singleton class. This is the only instance of the class - Private constructor: Create a private constructor for making sure the outer classes cannot instantiate an object of the Singleton class - Static public method: Create a global point of access to get the Singleton Instance

What are the practical 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

What is unit testing

- Testing individual blocks of code for correctness - In procedural programming this is typically at a function level - In OO programming this is usually at an object/class level - Probably the most widely used testing type

What is System testing

- Testing the entire system as a whole - Checks that it doesn't impair performance on the wider environment - Impacting broader resource availability on the OS - Affecting other applications working on the same system

What are the 3 class loaders used in order of precedence

- The boostrap class loader loads the core java libraries - The extensions class loader loads from the system-wide, platform specific extensions directory - The systems class loader loads from the current directory and and specified in the CLASSPATH environment variable of a system

What should you do if an assertion fails in one of your tests

- The failing code should be fixed immediately - Do not continue to add features to the code while tests are failing

How do we implement a customer event source

- The source class must have methods for registering and de-registering listeners - It must contain a method to "fire" the event. This method must create the event object and then call the listeners notification method on the event.

What are local classes. What are the rules for creating time

- They are defined and exist solely within a block (usually a method) - They cannot contain public, protected, private or static modifiers - They cannot access method local variables unless passed as arguments or declared as final - Can access all members of the outer class instance like standard inner class members - Variables can be effectively final if they are never changed and only ever take 1 value. In this case a variable can be accessed by a local class

How do you prepare a unit tests

- Typically a unit test will tests a single method, and a subset of the functionality that the method may provide. First decide how to test this aspect of the code - Remember that the method may interact with the objects other methods. - You may need to setup the instance of the object in some fashion before being able to test the functionality you want - Write the code itself - Run the unit tests and ensure they pass as you are developing the tests code base

What is User acceptance testing

- UAT plans are developed during the requirements analysis phase and are composed by users - UAT is developed 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 VERIFICATION activity

What are the advantages of agile development

- User engagement - Rapid development of a usable product - Early testing catches bugs and results in a high quality product - Small incremental changes mitigate the potential risk of introducing a large change to a system

How do we implement mock objects

- Using an interface to describe the object - Implement the interface for production code - Implement the interface in a mock object for unit testing

What are the types of dynamic testing

- White box: testing where the internals of the program are known, so you can test explicit paths through the system - Black box testing: the tester has no knowledge of the internals, testing is only concerned with functionality - Grey Box: Know both the required functionality and some of the implementation concepts, which can be used in test design, but the whole code base is not exposed

What are the propterties of good tests (ATRIP)

A - Automatic T - Thorough R - Repeatable (should produce the same results each time) I - Independent (of each other test and the environment) P - Professional (written and maintained to the same standard as the shipped code)

What is a VCS

A Version Control System It records changes to files over time so that you can recall specific versions later

What is a lambda expression

A block of code that you pass around between objects

What is the Queue Interface

A collection of elments stored for processings, use a first-in-first-out ordering. The add method inserts a method unless it would violate the queues capacity restrictions Remove() and poll() both remove and return the head of the queue. Remove throws a NoSuchElementException if the queue is empty, whereas poll returns null. Element() and peek() methods return, but do not remove the head of the queue. IF they queue is empty they behave as above in the same order.

What does the builder pattern create

A complex object (with parts) step by step

What is "stale data" and what issues does this present for threads

A data item that isn't up to date. This can lead to issues as different threads might have different values for the same data item

What is a repository

A database of all the edits to, and/or historical versions of your project Acts as a server based on a safe, secure and reliable machine

What must an event object contain

A getSource method Any other methods that you require. For example a getter for a variable that represents the state of something at the time of the event

What is the map interface

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

What is a monitor

A mechanism that ensures that only one thread can be executing a section of code at a time For example a synchronized block of code acts as a monitor

What is the waterfall approach

A methodology for software development that breaks the SDLC into distinct phases. Each of these phases needs sign-off before moving to the next

What is the set interface

A set contains no duplicate elements. Two sets are treated equal if they contain the same elements.

What is the join() method

A simple function that allows a program to wait for the completion of a thread before continuing. Overloads of join allow you to specify a waiting period. You use start a thread then join a thread. This thread will execute completely before the CPU can execute any other threads.

How do we use event listeners when implementing a GUI program

All Listener interfaces extend EventListener For GUI programs there are listeners interfaces already implemented for each event type e.g. KeyListener - KeyEvent. You should create a listener that implements the correct interface for the event you are handling.

What are ports. How do UDP and TCP use ports

All data passed around the internet has an address and a port. The destination computer will have an IP address and a 16-bit port number In TCP, a server application has a socket it binds to a specific port - effectiely registering that application on the machine will have all data sent to that port In UDP the packet contains the port number and is routed

Explain the Product classes of the Factory Method Pattern

All products implement the same interface so that classes which use the products can refer to the interface not the concrete class. Each ConcreteProduct is created by a ConcreteCreator

What are the benefits of concurrency

Allowing programs to interact with other systems/users multi-core systems

What is created for every object by the JVM

An immutable instancce of java.lang.Class is instantiated for it. Providing methods to query the properties of the object at runtime (along with the ability to create new classes and objects)

What is a scrum

An implementation of Agile development - Based on 2-4 week long fixed-length sprints - Aiming to produce deployable software in each sprint

What is a functional interface

An interface with exactly one abstract (that is, non-default and non-static) method You can feed lambda functions into the constructors that will override the abstract method. e.g. WorkerInterface is a functional interface with a method doSomeWork()) we write a functio execute(WorkInterface worker) than calls the doSomeWork function on worker. We then call execute on a lambda function and this function will override doSomeWork and be executed.

What are Java Collections

An object that groups multiple elements into a single unit

What is a listener

An object that is notified of an event occurring

What is EMMA

An open source code coverage tool. It can be run from the command line and is embedded in versions of popular IDEs

What are the concrete implementations of the List interface

ArrayList<E>: typically the fastest, but not always, uses dynamically resizing array LinkedList<E>: double linked list implmentation, better performing in certain cases

What is type erasure

As generics were a late addition to Java. To ensure backwards compatibility generic type instantiation is carried out by via tyoe erasure where the compiler removes all type information from parameters and arguements within generic classes/methods. This is to ensure bytecodes from different versions are compatible

What are the side-effects of using reflection

As reflecting can allow you to access private fields that would otherwise be inaccessible this can create side-effects: - These may render code dysfunctional and destroy portability - Reflective code breaks abstractions and therefore may change behaviour making originally hidden fields visible.

What is Centralized Version control

As soon as you commit to a centralised repository, others can see your changes You commit They update

What are Invariants

Assertions about classes/objects that should not change. For example checking that an array index is greater than 0 and less than the array length.

What is the decorator pattern

Attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality

With the precedence of class loaders in mind, what should you be careful of when naming classes

Be aware of naming conflicts. If for example you name a class something that is present in an installed extension. The class loader may load this rather than the class you've defined.

What OO Principles do Factory patterns help us meet

Both help us: - Encapsulate what varies - Strive for loosely coupled designs between objects that interact - "Dependency inversion principle" (Depend upon abstractions. Do not depend upon concrete classes) The Abstract factory meets: Favor object composition over class inheritance

How do you test your tests?

By introducing bugs into the production code and ensuring that your tests fail as a result

How does a VCS help with multiple releases

Can support multiple releases at the same time, no need to freeze development leading up to a release

What are anonymous classes and how do you use them

Classes defined without a class name. - Declared using the new keyword followed by an interface or class that they are going to extend or implement. - You never define the class as you don't use the class keyword. Therefore you cannot reference this class again.

Why use nested classes

Classes that are closely linked can be located in one place. If 1 class is only used one by one other, then this link can be made explicit by making it a nested class In some cases it can increase encapsulation by hiding the nested classes It can make the code more readable

What is the difference between concurrency and parallelism

Concurrency: A condition that exists when at least two threads are making progress. So this can be true if one thread is waiting for a CPU's timeslice but not being actively executed Parallelism: A condition that arises when at least two threads are executing simultaneously

What are the methods for creating instances of classes in Java

Constructor.newInstance() Class.newInstance we generally use the first as using the second will default to using the public no-argument constructor. Whereas the first we can obviously specify which constructor to use

How do you use categories in JUnit 4.x

Create interfaces with no body that will represent your categories Use the @Categories(CategoryInterface.class) Annotation above a test to add it to that category When defining a test suite you can add the @IncludeCategory(CategoryInterface.class) annotation which will add that category constraint onto your test suite

What is the Command in the command pattern

Declares the interface for all commands. Usually has just 1 method execute() which defines what will happen when each command is executed. Can also define an undo() method to allow executions to be undone.

What is the objective of the Command pattern

Decouple an object making requests from objects that know how to perform requests

What is a ConcreteCommand in the command pattern

Defines the binding between an action and a receiver. Once bound, the Invoker can make a request of its command object (execute()) resulting in the concrete command calling one or more actions on the receiver

How do you register listeners to GUI objects

Each event source implemented as part of the aformentioned GUI packages have methods like addXXXXListener() for registering a type of listener

What is the stub

Each remote object has an associated stub class which implements the same remote interfaces. An instance of the stub class is needed on each client. Client-side remote invocations are actually local invocations on the stub class.

What is the definition of the command 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 is the definition of the Singleton Pattern

Ensures that a class has only 1 instance. Provide a global point of access to it

What are the two ways to create threads in Java

Extend the Thread class Implement the Runnable interface

What is the OO principle that the decorator pattern forfills

Favor object composition over class inheritance

How can you bypass JVM security for reflection

Field, Method and Constructor objects all extend the Accessible Object, which has a method setAccessible(boolean). Which allows you to deactivate normal security when accessing that class member

What are the types of code coverage

Function/method coverage: Has each method written had a test written and run on it. This includes constructors and methods that are not externally accessible Statement coverage: Has each line of code been processed by at least one of your tests Decision coverage: Has every decision edge (if/else) been traversed in your code Predicate coverage: Has every boolean expression evaluated to both true and false

How does a VCS help track changes

Gives access to historical versions of your project. Gives development team a project-wdie undo button

What is the evolution stage of the SDLC

Has the system accomplished its goal? Are there any modifications to be made? If so, return to the start of the cycle.

What are the concrete map implementations

HashMap, TreeMap, LinkedHashMap These function the same as the set implementations with the same name

What are the concrete implementations of the Set interface

HashSet<E>: fastest, but no order guarantees TreeSet<E>: Uses a red-black tree structure, contents ordered on value LinkedHashSet<E>: Ordered based on set insertion. Stored in a hash table with a linked list running through it.

What is the Invoker in the command pattern

Holds a command and at some point asks the command to carry out a request by calling its execute method

What is a lock

If a thread has a lock on the object it means that only it is allowed to execute any of synchronized or locked methods on that object. Once the execution is complete the lock is released. We can use methods to release the lock in other ways

What is Thread confinement

If data is only used by a single thread then it is said to be confined. Data should be thread confined wherever possible

What is the issue with the default implementation of the Singleton pattern

If multiple threads access the class then multiple instances can be created

When should you use mock objects

If the real object: - Has non-deterministic behaviour - Is difficult to set up - Has behaviour that is hard to trigger - Is slow - Has or is a user interface - Does not yet exist

How do you stop a thread by interrupting it

If the thread is set to waiting or sleeping it will see this as interrupted and it will return from run()

What is synchronization in threads

If you add the synchronized keyword to methods in the class or blocks of code, when one thread is executing this code, all other threads must suspend executing until the first thread is done with the object.

What are the differences in implementation between using Runnable interface or the Thread class

If you are using Runnable you need to use a new Thread() constructor on your object when creating an instance of your object to enable it to be started. However when extending the Thread class this isn't necessary See example in the picture

In what scenarios would you use the lock interface

If you needed two or more objects to share a lock. Or one object to have multiple locks

What are bounded types

If you want to write a class/method to operator not just with generic types, but for types that extend, or are superclasses of given classes. writing using <S extends ClassName> or <S super ClassName> extends specifies an upper bound, super specifies a lower bound

What is the benefit of extending the Thread class

If you wanted to overwrite specific methods in the class and changes it's functionality, extending the class is the best way to go. However in most of our use cases this is unnecessary.

What is the difference between test suites in Junit 3.8.x vs. Junit 4.x

In 4.x we can just use annotations. In 3.8.x we must specify a public static Test suite() method that is run if you run the given test class.

What is good practice when collaborating using a VCS

Incorporate others' changes frequently Share your changes frequently Coordinate with your co-workers Use branches

What are the disadvantages of the command pattern

Increase in the number of classes for each individual command

What is code coverage in testing. When using it what do we have to take into account

It attempts to measure how much of the code has been tested. If you use code coverage your testing isn't black box as it looks at the code directly. Often a choice has to be made on how much code is covered. Some bits of code are infeasible to test. There is no set % to aim for as it's situational and varies depending on the program

What is the yield() method

It causes the currently executing thread to pause and allow other threads to execute If no other threads of the same priority need to execute, execution of the thread continues Identifies the curren thread as doing something not particularly important. Very useful if you have 2 threads then need to swap execution at specific times, by yielding their time on the CPU to the other thread

What is the Factory Method Pattern

It defines an interface for creating an object, but lets subclasses decide which class will be instantiated.

What is the dequeue interface

It is a double ended queue Insertions can occur at either end

What is an inner class and what access modifiers would you use when defining it?

It is a nested class that does have access to instance members. It can be defined using any modifiers

What is a static nested class, what keywords would you use to define it and and why

It is a nested class that does not have access to instance members. It must be static and It can only be declared as public or package private. This allows the nested class to access the outer class.

What is the Iterator interface

It is an interface that we can implement to allow us to safely remove objects while iterating

What is an event

It is an object that contains information about a state change in a source

What does ? represent in Java Generics

It is an unknown type known as a wildcard

What is the property of non determinism

It is impossible to determine which task will be completed first in a multi-threaded world.

What is Reflection

It is the ability for an object to examine itself and look at the class of an object to find out what constructors, methods and fields a class has.

What is heap pollution

It is the situation when a variable of a declared parameterised type refers to an instance that is not of that type. For example in this picture

What is forking

It means independent branch of development. If you want to work on a specific feature on a respository, you branch out separately, work on that branch and then commit/merge. Often used if you are going to try a new code direction. or try to add a new feature

How do we implement customer listener interface

It must extend EventListener Provide declaration of any notification methods that will be required of listeners of this type

What is the Abstract Factory Pattern

It provides an interface for creating families of related or dependent objects without specifying their concrete class

How do you resolve conflict in a VCS

It requires manual intervention

What is the Builder in the Builder pattern

It specifies the interface for creating parts of the complex Product object

What does the keyword volatile mean

It tells the compiler not to optimise accesses and forces the next read to see the last write

In a GUI program what is the event source. What packages would we use for this

It would be a button or checkbox. java.awt.* and jav.swing.* are two packages that gives us classes for creating GUI components.

How do you run a test suite from the command line

Java "runner" "testClass" sometimes you need to use -cp followed by the file locations of the testing classes or Junit source files to allow the compiler to see the necessary source files to run the classes

What is the property of conversion in lambda functions

Lambda functions can infer conversion. For example if you create a new Thread and give it a lambda function in its constructor. The lambda function will be automatically converted to the Runnable interface to create an instance of Thread

What is the Trunk

Main code base the developers are working on. (known as the master branch in git)

What is the concept of Non-blocking I/O

Modern programs have to interact with other systems such as databases, the internet and other users. I/O must not block the functionality of a program or restrict it's usability We use concurrency to overcome this issue

What is the notify method and how do we use it

Notifies a waiting thread the a conditions has occurred, must be called from a synchronised method You can use notifyAll to notify all active threads. You use notify on any instance of the Object class. When you call the method it will notify all threads that were set to wait by the same instance of the Object class. e.g. x.notify will wake up all threads that were set to wait using x.wait

What is livelock

Occurs when two threads are too busy responding to one another to do work. Provided 1 thread keeps sending messages the other will keep responding, looping continuously

How do you get a class of an object in Java

On an object use the getClass() method If you can access the type but have no instance of the class. use the .class keyword after the typename e.g. Class c = float.class; If you know the name of the class you can use the static forName method e.g. Class c = Class.forName("java.lang.String");

How does Sychonizing the getInstance() method in the singleton pattern ensure thread safety. What are the pros and cons

Only 1 thread can access the method at a time, so 2 instances cannot be created. Pros: Easy to implement and maintains lazy instantiation Cons: Slow performance due to the locking overhead

If instead of decorating objects we added funcitonality into the base code of classes. What OO principle does this breach

Open-Closed principle. Classes should be open for extension, but closed for modification. This is because to solve the issue we are modifying the code

Briefly explain UDP network communication

Order is not guarenteed nor is delivery, as UDP doesn't check for any errors. It is a best attempt delivery system. It is not based on a connection, packets are sent independently

How do you make packages available to 2 JVMs

Package them into a jar file and give both JVM's the classpath

Compare and contrast Polling vs. event driven programming

Polling - While the event hasn't happened, keep checking - Easy to implement - Wasteful of resources Event-Driven programming - Events have control within the operating systems - The OS will release resources provided they are notified when the event happens - More complex to write - Much better user of resources

What is RAD

Rapid Application Development

What are the uses of atomic actions and how do we use them

Read and writes are atomic for reference variables and most primitive variables If you declare a variable atomic then any read and writes will be atomic regardless of it's type.

What are the performance implications of reflection

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 performance-sensitive applications.

When using reflection in your code what do you need to ensure about the environment you are running it in

Reflection requires a runtime permission. Which may not be present when running under a security manager. It is important to know whether or not the code will be run in a restricted security context

What are the components in Java RMI

Registry: Relates remote objects with names Server: Calls the registry to associate a name in the registry with an object Client: Looks up the remote object by its name in the registry then invokes a method on it

What are the 3 parts of distributed Object Applications. How does RMI furfill these

Remote Object location - Server application registers the remote objects with the RMI registry - Pass remote object references via invocations of methods on other objects Remote Object Communication - Handled by the RMI framework From a programmers point of view it is like simple method invocation Accessing Class definitions - RMI provides the ability for passing class definitions

What is RMI

Remove Method Invocation Allows an object in one virtual machine, to invoke methods on another object in another virtual machine

What is the client in the command pattern

Responsible for instantiating the ConcreteCommand and setting its Receiver

What is the acronymn Right-BICEP

Right - are the boundary results right, these are the extremes of the input domain B - Are the boundary conditions correct i.e. is the input domain correct I - Can you check the inverse relationships C - Can you cross check the results E - can you force error conditions to occur P - Are the performance characteristics within bounds

How do you create a test Suite in Junit 4.x

RunWith specifies the runner class that runs the tests. Different runners can have different functionality

What is the builder pattern

Separates the construction of a complex object from its representation so that the construction processes can create different representations.

What are the stages in the SDLC (and what does it stand for)

Software Development lifecycle: - Requirements analysis - Design - Implementation - Testing - Evolution

What is agile development?

Sofware development based on short iterative sprints

What are the OO principles met by the command pattern

Strive for loosely coupled designs between objects that interact Classes should be open for extension but closed for modification

What Java classes use UDP and which use TCP

TCP - Url, UrlConnection, Socket, ServerSocket UDP - DatagramPacket, DatagramSocket, MulticastSocket

How does a VCS help track ownership

Tags every change with the person who made it

What is the director in the Builder pattern

Takes responsibility for the construction of the complex Product object. However it delegates action creation and assembly to the Builder interface

Explain the creator classes in the Factory method pattern

The Creator superclass defines an abstract factoryMethod. As well as any concrete methods that can work generically on any product produced by any implementation of the factoryMethod The concreteCreators implement the factoryMethod to instantiate objects

What are the guards against reflection use

The JVM security manager guards against reflection. - Another object is not able to use reflection to do something that couldn't be done with ordinarily compiled java code. e.g. accessing private field - However these priviledges can be granted

What is a socket

The binding of a port to a specific application, where the application will be listening for or sending network traffic.

What is the concrete Builder in the Builder pattern

The concrete builder creates and assembles the parts the make up the Product through the Builder interface

What is the property of liveness

The idea that we now need to be concerned that our code performs correctly in time (not just correctly).

How does eager instantiation in the singleton pattern ensure thread safety. What are the pros and cons

The instance is created during the class definition. Not during the getInstance() method. So it can't be accessed by threads. Pros: Easy to implement, thread safe without synchonization Cons: the instance is created even though the client application might not be using it

How do you stop a thread using a flag

The loop will exit when done is set to true.

How do you make a remote object

The object must extend the java.rmi.Reemote interface Each method must throw java.rmi.RemoteException

How do you use a decorator class

The original object is wrapped in one or more decorators Decorators have the same supertype as the objects they decorate. This means we can pass around any decorated object in place of the original object. The decorator adds its own behaviour before or after it delegates to the object to do the rest of its work Objects can be decorated at any time, so we can perform dynamic runtime decoration

What is the Product in the Builder pattern

The product represents the complex object that is created by the ConcreteBuilder object(s). It consists of multiple parts

How does Double checked locking in the singleton pattern ensure thread safety. What are the pros and cons

The synchronized block is used inside the if condition to ensure that only 1 singleton class is created. Pros: locking overhead is minimal as it is only applicable for the first threads that access the method when the variable is null. Once this is not true, then the synchronized block is never reached

What is a nested class and what are the two types

These are classes defined within classes. The two types are: Static nested class Inner class

What is an adapter class

These are classes that can be defined for an interface. They implement all methods of an interface with an empty method body. So if you extend these classes you only have to override the methods that you require. You can completely ignore any others. They will be invokable but they will have no effect and won't be shown in your code, making it easier to read.

What are atomic actions

Theu are self-contained, and cannot be stopped in the middle. Either they do or don't happen

What are mock objects

They are cheap placeholder items that are predictable and allow us to test a method we need to in the current class.

What are threads

They are list of instructions that the computer will carry out at the same time by putting them on separate processors (or if there is only 1 processor available, by rapidly swithching between the threads)

What are enums and what are the rules for them

They are used for creating variables with specific ranges/values that they can take Not instantiated. You reference a specific value that the enum can take Effectively static and final You can declare an enum as a separate class, or as a class member, but not internally within a method.

What are test suites

They 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

What are design patterns

They provide a reusable solution to one type of problem during software development

Why might you write your own class loader

This allows you to add class definitions to a program whilst it's running. As the program will be loading in classes rather than just using the one's that you've declared e.g. creating a ClassLoader instance that will search a directory for jar files that can be added during runtime

What is the benefit of using the Runnable interface

This allows you to extend and implement other interfaces and superclasses which makes this way of creating a thread more versatile. You can also use your class to create multiple threads of the same class. By constructing multiple Thread objects using the same object.

How do you create an instance of an inner class from within outer class?

This is just created as if the inner class were any other public class

What is the skeleton

This is responsible for listening for invocation requests on suitable IP ports, and dispatching them to the proper, locally resident remote objects .

Example what happens when you create a new instance of the outer and inner classes at the same time in order to create just an instance of the inner class? e.g. new Car().new Engine()

This just creates the inner class, as it creates the instance of the outer class that has no name. Making this instance of the outer class an anonymous class

How do you create an instance of an inner class from outside the outer class

This requires an instance of the outer class to exist to facillitate the creation of the inner class. The example shows the two ways

What is the difference between Thread.start() and Thread.run()

Thread.start() creates a new thread and executes it Thread.run() just executes the run method of said thread as if it were any other method

Why do we use threads rather than separate programs

Threads can share memory between them which makes them more efficient

What is concurrency

To be able to perform multiple processes at the same time - including the potential interaction between them.

What is pair programming

Two people working on a simple programming task. They take the roles: driver (typing) Navigator (responsible for the overall direction of the code) These roles are reversed between the two periodically

How would you achieve explicit locking. Give code examples

Using the Lock interface to create and release locks. This is what the synchonized keyword does automatically. But we can take full control of the process. creating a lock: Lock myLock = new ReentrantLock() myLock.lock() myLock.unlock()

What are atomic variables

Variables that support atomic operations. Built into java using the atomic library.

What is merging

Version control systems all you to merge changes made in branches back into the main trunk

What are the difference between wait and sleep methods

Wait: - Must occur in a synchronized block - Releases the lock when called and doesn't sacrifice the remainder of its timeslice as the CPU no longer needs to work on this thread - Will wake up if notified via a notify call Sleep - Does not need to occur in a synchronized block - Retains the lock when called and sacrifices the remainder of its timeslice as the CPU must stay in this thread for the specified sleep period - Only woken up by an interruption

How do you use the wait() method

Waits for a condition to occur (Another thread will notify the thread if the condition has occured), must call from synchronised method/block. There is an overloaded method of wait that takes a long, representing the time to wait You have to catch the InterruptedException as otherwise the thread will just terminate when you tell it to wait

What are the limits of testing

We cannot test every aspect of even a moderately simple system testing cannot assert that the software functions correctly under all conditions, but that it functions incorrectly under specific conditions

How do we create concrete listeners

We implement a listener interface and give implementation for all of the notification methods declared in the interface

What is the design stage of the SDLC

What are the hardware, software and network requirements? What parts of these will be in-house? And what will be externally developed or bought off the shelf

What is the Requirements analysis stage of the SDLC

What business/scientific problem is the system addressing? Is it feasible? What will the system do? Who are the users?

What is marshalling and unmarshalling

When a client invokes a method that accepts parameters on a remote object. These parmeters, if primitives are jsut attached to the header of the TCP packet when sent to the server. If they are objects then these objects are serialised (marshalling) and deserialised (unmarshalling) at the other end

What is escaping

When an object is published when it shouldn't have been

What is a race condition

When two threads try to access/change data at the same time it's known as a race condition. This can often lead to inconsistent results

What is a conflict in a VCS

When two uses make simultaneous, different changes to the same line of code

What is publishing

When you make an object available outside its current scope e.g. storing a reference to it whether other code can find it such as a non-private attribute

What is branching

Where 2 versions of the trunk are created and go in different directions. The different changes made in these branches are then merged back into the trunk.

What is Starvation

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

What are Corner Case

Where a variable takes its maximum or minimum possible value. Important to test these as they can cause bugs that will happen very rarely as most standard use of the system is unlikely to use values this high/low

What is Deadlock

Where all currently active threads need access to a resourece that is locked by another thread. So none of them can progress

Compare and contrast white box testing vs. black box testing

White Box: - Advantages: code can be seen so tests can be designed to test many paths through the program - Disadvantages: Knowlege of the internals will influence the testing - can lead to bias in test design Black Box: - Advantages: No knowledge of the internals, so no programmer bias. More likely to results in tests not expected by the programmer - Disadvantages: High probability that tests will only test a small number of paths through the program

Give examples where singleton patterns might be used

Window managers Thread pools File systems

How do you invoke generic methods

You can either specify the type of the generic variable, or you can leave it to be inferred

How do you run tests from multiple classes in Junit 3.8.x

You create a composite test class that has methods from multiple test classes in its suite method

How do you setup and teardown using Junit 3.8.x

You overwrite the methods setUp() and tearDown() that are already defined when you create a test class (by extending the TestCase class)

What does the property of type erasure mean we need to be aware of

You should not mix legacy type notations with generic types in newly produced code, as this can lead to warnings of unchecked or unsafe operations where the type declarations have been removed.

If your using test driven development how should you write code

You should write code that's compartmentalised so that it is easier to test. If you create a class that has many different functions it is far harder to test

What should you keep in mind when writing construtors for thread classes

You shouldn't start a thread in a constructor. Objects are only in a stable and consistent state after they have been constructed so they shouldn't be referenced by threads before this

What is an event source

an object that generates an event.

What is the List interface

an ordered collection of elements, that may contain duplicate elements. Two lists are treated as equal if they contain the same elements in the same order. You can iterate over a list using for-each notation It declares methods to return list iterator objects (which are extensions of iterators)

How do you create a class that is both the event source and the listener

create a class that extends an event source and also implements a listener class.

What are the uses of atomic variables

if 2 threads are constantly changing the value of a variable. You can use atomic methods to alter the value. Rather than having to synchonize every method that alters the variable. Which is more expensive

How do you write a decorator class

implement the Decorator interface (or extend if declared as an abstract class) create an instance variable to hold the object you are wrapping create a constructor, which has as an argument the object to be wrapped. And set the instance variable equal to the object passed into the constructor. Add your "decorations" e.g. define the a cost() method that adds 20 to what the original objects cost() method returns

What is the downside of using synchronized

it is very expensive

How would you create a new object for a static nested class

new OuterClass.NestedClass();

What is the Receiver in the command pattern

performs the work required to carry out a request

How do you define a Java generic class

public class generic<T> {} Where T would be replaced by the type you want the class to take when you instantiate it. when defining the class use T in place of any type declaration where necessary.

What are the two overall types of testing

static (assessing documents, reviewing and walking through the code) dynamic (testing that involves executing the program code)

How do you synchonize blocks of code

synchronized(this){}

What are the naming conventions for tests

testMethodName if you have mulitple tests for 1 method they should be called start with the above and then add on words the specify what the test is testing

How do you implement the static public method for a singleton class

the method will return the 1 stored instance of class. If the class isn't instantiated. It will instantiate and store a new instance. Then return it.

How does the this keyword function with an inner class

using this alone refers to the inner class. Use Outerclass.this to refer to the outer class instance


Conjuntos de estudio relacionados

Electronics - Resistors & Ohm's Law_Copy

View Set

Oxygen Therapy and Respiratory Issues (NCLEX Practice Questions)

View Set

COM 263: L7 Verbal Communication

View Set

GENERAL ANATOMY - WRITTEN EXAMINATION

View Set