Units 5-8 Flashcards

1
Q

Briefly describe the conditions under which optimistic concurrency control might be more suitable, and one possible advantage of using it.

A

The optimistic approach is suitable when:

  • the likelihood of clients accessing the same data is very low
  • fast response is important, such as in interactive applications.

It aims to avoid the overheads and problems associated with locking mechanisms, such as lock management and deadlock detection/prevention.

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

A Java client can make use of distributed objects using Remote Method Invocation (RMI). It is also possible for Java clients to access Enterprise Java Beans (EJBs) and invoke methods on those. Describe three significant ways in which these two ways of using remote objects resemble one another.

A
  • Both are action-oriented rather than data-oriented.
  • Both take advantage of loose coupling.
  • Both are examples of remote object invocation.
  • Both run inside JVMs.
  • Both are homogenous.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are session beans and what purpose do they serve?

A
  • They are a type of EJB that handles an interactive session between a client and the application server.
  • Neither persistent nor shared.
  • Encapsulate the business logic.
  • Session beans access and modify entities, shielding data from clients
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Name the two types of session beans and explain the main difference between the two types.

A
  • Stateful bean: the state (value of the bean’s instance variables) is kept across multiple calls to the bean’s methods, e.g. an online shopping cart.
  • Stateless bean: the state is discarded after each method call - a session with a stateless bean lasts only for the duration of a single method call, e.g. a database query. A single stateless bean can provide multiple methods, each one implementing an independent query.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Both servlets and JavaServer Pages (JSP) are mechanisms used to generate web pages. Explain when one would use JSP and when one would use servlets.

A
  • JSP would be used when the output of the webpage is mainly static HTML/XML, with some dynamically generated content.
  • Servlets would be used for more complex processing, where the static content of the response is very limited or is delegated to another component.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain the following statement: “Java’s RMI is a form of communication that follows the distributed object paradigm”.

A

The distributed object paradigm extends the object-oriented paradigm to a distributed setting, so that local and remote objects are treated in the same way and have the same capabilities.

RMI is effectively extending the way that objects invoke methods on other objects to a distributed setting, and hence belongs to the distributed objects paradigm. RMI works by adding an additional layer that deals with the lower level details of the communication, such as data marshalling and sockets. To use RMI requires the existence of a registry so that objects can look up where other objects are located, in order to invoke methods on them.

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

Explain what is meant by ‘conflicting operations’.

A

Operations are conflicting if the order in which they are carried out affects the result.

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

What are the three main categories of components in the MVC approach and what are their roles? Illustrate your answer with an example for each category.

A
  • Model: the abstraction of all the domain data in the system, e.g. the shopping cart in an e-commerce system.
  • **View: **the visualisation of the model, e.g. HTML/JSP pages.
  • Controller: the set of components that manage the communications between model and view, e.g. a servlet.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Using a diagram or otherwise, name the standard tiers of a Java EE application and indicate the type of components associated with each tier.

A
  • Client Tier: Browser, applet, application client
  • Web Tier: Servlet, JSP, JavaBean
  • Business Tier: EJB, Entity class
  • Database / EIS Tier: DBMS
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Explain how HTTP servlets deal with handling concurrent requests from multiple clients.

A

For the standard situation of a multi-threaded servlet, the Web container will create and run a separate thread for the service method that is invoked in response to each request. The helper methods such as doGet or doPost which will be invoked by the service method must be written to take account of this.

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

Explain how HTTP servlets deal with avoiding problems with concurrent access to shared data.

A

Data stored in variables declared locally to servlet methods is threadsafe, because each thread has its own copy of local variable data.

By contrast, instance variables or static variables are not thread-safe as they are shared between any threads being run concurrently by the servlet. Code that updates instance data or static data, must use synchronization, so that at most one thread at a time can be carrying out an update. It is best to synchronize as little of the servlet code as possible, to maximise performance.

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

What is meant by a heterogeneous system?

A

A heterogeneous system is one implemented using more than one kind of computer, operating system, software or communication protocol.

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

Why are heterogeneous systems of particular interest in distributed computing?

A
  • Distributed computing in a wide context inevitably involves heterogeneity, due to the variety of systems in existence.
  • Legacy systems may exist or systems may have been developed by different parties at different locations and times, leading to heterogeneity.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Give a definition of middleware.

A
  • Any software that provides an intervening layer between two communicating systems, providing the ability to make communication between the systems transparent
  • *OR**
  • Software that masks the heterogeneity of an underlying system
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Explain what is meant by homogeneous and heterogeneous middleware, and give an example of each.

A
  • Homogeneous: middleware in which all parties are assumed to be implemented in the same language and running on the same platform, e.g. Java RMI
  • Heterogeneous: middleware in which no assumptions are made about a shared language/common platform, e.g. CORBA.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Heterogeneous middleware is more flexible than homogeneous middleware, but has higher overheads. Give two examples of such overheads.

A
  • Additional communication overheads due to their flexibility and the requirement to translate between heterogeneous representations.
  • Requires the use of an IDL (interface definition language)** **representing features of multiple languages.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Give two reasons for using JSP Expression Language or Tag Libraries in JSP pages in preference to Java scriptlets and expressions.

A
  • Separates processing (Java code in servlets) from presentation (JSP pages using tags and EL). Helps with maintenance in complex applications.
  • Allows web designers familiar with HTML and XML, but not with Java, to produce and maintain JSP pages without any Java programming.
  • (unit 8, p 42)*
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How does the RPC mechanism take care of robustness?

A

The use of timers (at points A and D in diagram). If time-out occurs, this indicates that something has gone wrong.

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

Remote Method Invocation (RMI) has three steps: binding, lookup and method call. Explain briefly what happens during each step.

A
  1. The server application binds the server object to a symbolic name in a registry, a naming service that associates objects to unique names. The location of the registry and the symbolic name are known to client and server.
  2. The client object looks up the symbolic name in the registry and obtains a reference to the server object.

3 The client object uses that reference to make a remote method call.

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

Briefly explain the role of JavaBeans in Java EE applications with regards to JavaServer Pages (JSP).

A

JavaBeans are used for the transfer of complex data between web tier components such as JSP pages and servlets. They are also useful for temporary storage of data.

21
Q

What features are required of a Java class so that it can be used as a JavaBean?

A

It has a zero-argument constructor.

It has properties which are read/write, read-only, or write-only.

Every readable property of the bean has a getter method.

Every writeable property of the bean has a setter method.

It must be serialisable.

22
Q

Give a sample code fragment showing how a JavaServer Page would access a JavaBean using JSP tags. The syntax does not have to be exact.

A

Unit 8, page 33.

23
Q

What is load balancing?

A

Load balancing is avoiding situations where one component has to do all the work, while other components remain idle.

24
Q

Explain briefly how load balancing can be achieved in three styles of software architecture for distributed systems.

A

Classic client–server: load balancing can take place if some of the processing is carried out by the clients;

Multiple servers: load can be shared among the servers;

Proxy server model: proxy takes over some of the work from the servers, and relays information to the clients that would otherwise have had to be provided by the server;

Peer-to-peer: the work is shared among all the peers

25
Q

Describe the two phases of 2PL.

A

In the acquire phase, the transaction acquires objects, but does not release any.

In the release phase, the transaction unlocks objects, but does not acquire any.

26
Q

Is 2PL an optimistic or a pessimistic form of concurrency control? Briefly explain.

A

It is pessimistic. Pessimistic algorithms assume that there are likely to be conflicts and take measures to avoid them. 2PL uses locks to avoid conflicts.

27
Q

What are entity classes in Java EE and what purpose do they serve?

A

A class that just holds data and may provide business logic, although the latter is usually delegated to session beans. Entity classes must be annotated with @Entity. An entity class corresponds to a table.

28
Q

How do entity classes and entities map to a relational database?

A

An entity class corresponds to a table, each instance of it to a record in the table and each column to an instance variable. To define an entity class for table T1, declare one private instance variable per column and access it through a pair of setter and getter methods. If a column is a foreign key to table T2, the corresponding variable is typed by the class corresponding to T2. If T1 has a one-to-many relationship to T2, then the class may have an additional instance variable holding a collection of instances of the class corresponding to T2.

29
Q

What are the advantages and disadvantages of servlets compared to applets in providing dynamic content for web pages?

A

Applets run on the client machine, and so can be very responsive since there are no network delays.

The applet code must be downloaded from a server before running - less attractive to write large applets.

Servlets are more scalable – additional servers can be used to run more servlets under heavy demand.

Untrusted applets have severe security restrictions that limit what they are permitted to do on the client machine – although most of these can be avoided using trusted applets.

Servlets can use the full power of the Java language and its libraries; they can access other servers and invoke other programs.

30
Q

Interprocess communication can be either synchronous or asynchronous. Explain how these two approaches differ.

A

Asynchronous: sending and receiving processes do not have to be at their synchronisation points at the same time. Requires a buffer to temporarily store messages. Non-blocking form of communication.

Synchronous: both processes are required to be at the point of sending and receiving at the same time, and the message goes straight from the sending process to the receiving process. Blocking form of communication - the process that sends is blocked while it is in the send instruction.

31
Q

Explain the main idea of remote procedure calls (RPC), including a brief outline of the steps involved.

A

In the RPC model the idea of procedure calling is extended so that it is possible to call a procedure even if the process that will execute that procedure is remote. Action-oriented.

  • RPC service layer sits between the calling/called program and the underlying network related stack.
  • RPC service layer gives the request an ID, marshalls procedure arguments into a suitable message, sets timer, transmits message to server machine.
  • Server RPC layer unmarshalls arguments, makes a note of the ID and calls the relevant method.
  • The return from method call is marshalled, timer is set and message transmitted to the calling host.
  • Upon receiving response, timer for the RPC call is disabled, acknowledgement message is sent to the server, returned results passed to calling program.
  • Upon receiving the acknowledgment; the serve disables the related timer.
  • If any of the timers timeout; the RPC service layer has to take steps to rectify the situation.
32
Q

What do RPC and Java remote method invocation (RMI) have in common and how do they differ?

A
  • Both are synchronous and blocking.
  • Both go through various layers that abstract away data marshalling and the low-level network protocols.
  • Both are action-oriented, but RMI is also object-oriented and an example of a distributed object paradigm.
  • RMI is homogeneous, RPC is hetereogeneous
  • In RPC a procedure is called directly, while in RMI a method is called through a particular object that was created at runtime. RMI therefore requires a registry and a unique name to look up the object reference.
33
Q

Briefly describe the role of Java security managers used in RMI.

A

If a JVM receives a serialised object of an unknown class (i.e. a class that is not on the JVM’s class path), it must use a security manager to check whether the user-defined security policy allows downloading and executing of the code from the location given in the java.rmi.server.codebase property set by the JVM that sent the object.

34
Q

In a client-server system that uses multiple servers, explain the difference between data replication and data partitioning.

For data replication give one example of where it might be used and why. For data partitioning give two different examples of where and why it might be used.

A

Data partitioning: the data resources for the system as a whole are distributed among the servers, such that each server is responsible for its own section or partition. The servers interact with each other to provide the replies to requests. Examples: A large international commercial organisation, e.g. eBay (account and item details could be held on the server local to the country). Open University student database (student records and tutor details could be held on a server for each region).

Data replication: each server holds an identical copy of the data. Better performance and availability, improved fault tolerance. Example: online banking system where the database has been replicated to run on a number of separate servers.

35
Q

Explain how RMI (Remote Method Invocation) uses names to access remote objects and why it uses this approach. Briefly outline the relation of RMI to JNDI (Java Naming and Directory Interface).

A

After a remote object has been created and exported, the binding process puts a name–stub pair in the registry. When the client looks up a name in the registry, it gets back the associated stub object, on which it can now make local method calls.

Names are more convenient and more flexible to use rather than specifying the full details of a resource or its location.

The RMI registry is a simple example of a naming service. More sophisticated directory services that locate services by hierarchical names or by attributes can be accessed via the JNDI API

36
Q

Briefly discuss when you would use each of the following approaches in a web application: pure HTML web pages, JavaServer Pages (JSP) and servlets.

A

Pure HTML pages: when the required content is static.

JSP pages: particularly suited to constructing dynamic web pages in situations where the output is predominantly static HTML or XML but there is some dynamic Java content required.

Servlets: useful for more complex processing, where the static content of the response is very limited or is delegated to another component.

37
Q

List the tiers of a Java EE system and explain the role of each tier.

A

EIS/database tier: holds the data for the application and stores it permanently in some kind of database.

Business tier: contains the software relating to the business logic.

Web tier: makes the business logic accessible for web applications.

Client tier: deals with the presentation, or user interface, of the application as a whole.

38
Q

Explain the concept of a transaction and why transactions are crucial in enterprise systems.

A

A transaction is a sequence of atomic actions, where we want the whole sequence to be performed in its entirety, or not performed at all. Tranactions are required to have the properties of atomicity, consistency, isolation and durability.

Transactions are a crucial part of enterprise application development in order to keep the system in a consistent state.

39
Q

Using a state diagram or otherwise, show the possible states a transaction can be in and the possible transitions between these states.

A

Active – the initial state a transaction is in when it is first started. While the transaction is executing it remains in this active state.

Partially Committed – the state after the final operation has been executed.

Committed – the state after successfully completing the transaction. All the changes to the database made by the transaction will persist.

Failed – the state when the discovery is made that normal execution cannot proceed.

Aborted – the state when the transaction has been rolled back and the database is restored to the state it was in prior to the start of the transaction.

40
Q

Explain what session beans are in Java EE and distinguish the two main types in terms of what each one is useful for.

A

Session bean: A type of EJB that handles an interactive session between a client and the application server. Session beans are neither persistent nor shared.

Stateful session bean: Implements a single business service that spans multiple method calls, hence requiring state to be kept between calls. For example, this would be used for a shopping cart.

Stateless session bean: The state is discarded after each method call. Ideal for one-off services that are always performed in the same way, e.g. database query.

41
Q

Assuming we are using container-managed entity managers, how are transactions typically handled in session beans and how can this be modified by means of annotations? You are not required to remember the exact syntax of Java annotations.

A

By default, a container-managed entity manager automatically creates and commits transactions on method calls and returns. This can be modified using the @TransactionAttribute annotation.

42
Q

Briefly define what is meant by a thin client in a distributed system.

A

Thin clients (typically used in n-tier architectures) do not carry out much processing and leave this to the server. An example of a thin client is a browser.

43
Q

Message-oriented middleware makes use of an intermediary for the communication between senders and receivers. Explain the role of this intermediary and how it affects this type of communication.

A

A sender deposits a message with the messaging system, which acts as the intermediary, and the intermediary then looks after the message from that point onwards. The intermediary delivers the message by forwarding it to the queue associated with the appropriate receiver. If the receiver process is not running, or if it has no space in its buffer, the messaging system will hold on to the message until the receiver is ready. This is a reliable form of communication.

This form of communication is asynchronous – the sender is not blocked upon sending a message, but can continue with other processing.

The processes are said to be loosely coupled.

44
Q

1 // transaction.begin(); //1
2 // if (bankAcc1.getBalance() >= 10000) {
3 // bankAcc1.debit(10000);
4 // bankAcc2.credit(10000);
5 // transaction.commit(); }
6 // else {
7 // System.out.println(“Insufficient funds”);
8 // transaction.rollback(); }

For each numbered line of code, indicate which transaction state the system will be in after the execution of that line.

A
  1. Active
  2. Active
  3. Active
  4. Partially committed
  5. Committed
  6. Failed
  7. Failed
  8. Aborted
45
Q

Using a state diagram or otherwise, show the possible states a transaction can be in and the possible transitions between these states.

A

Active > Partially Committed > Committed

Active > Partially Commited > Failed > Aborted

Active > Failed > Aborted

46
Q

What are the two possible kinds of entity manager used when dealing with persistence in Java EE? Explain how each of these entity managers is created and closed?

A

Application-managed entity managers are explicitly created and closed by the application.

Container-managed entity managers are implicitly created and closed by the EJB container.

47
Q

Explain briefly how the handling of transactions differs depending on the kind of entity manager being used. No coding is required for this question, though you may use brief code extracts for illustration if you wish.

A

Application-managed entity managers explicitly start and end transactions.

Transactions in **container-managed entity managers **are by default implicitly created and committed at method call and return.

48
Q

What is the role of dependency injection and annotation with regards to entity managers?

A

Dependency injection: an object (e.g. a bean) indicates that it depends on the existence of another object (an entity manager in this case) and the container ‘injects’ such an object into the application at runtime. Dependency injection is usually achieved by annotating the declaration of the required object.

A required entity manager can created by dependency injection through the @PersistenceContext annotation.