Web Services & Xml Interview Questions in Java

We have compiled most frequently asked Java J2EE Interview Questions which will help you with different expertise levels.

Java J2EE Interview Questions on Web Services & Xml

Question 1.
Elucidate UDDI.
Answer:
The Universal Description, Discovery, and Integration is a database of web services providers that is accessible from within a program and supplies information about the web services available from the provider including information about interfaces to web services. The web services community centers around a group of web-based registries that contain information about each member, their web services, and the application programming interfaces used to access those services. This group of registries is referred to as the Universal Description, Discovery, and Integration (UDDI). A UDDI entry is called a tModel and contains:-

  1. The name of the business
  2. Contact information
  3. Industry codes
  4. Product classification
  5. A description of the web service
  6. Requirements for rights to access the web service
  7. Technical reference to the interface and properties

Question 2.
Elucidate JAXR.
Answer:
The keystone of web services is the XML registry that is the repository for information about the availability of web services and information necessary to access web services. The XML registry is the mechanism for organizations to make available web services to other organizations and to avail themselves of another organization’s web services. Two important XML registry standards are UDDI (refer to the previous problem) and the Java API for XML registries (JAXR) that is used to access an XML registry. The JAXR architecture is organized into two groups – the JAXR client and the JAXR provider. The JAXR client is a Java program that accesses the information contained in an XML registry by interacting with a JAXR provider.

A JAXR provider implements the RegistryService interface giving JAXR client registry access. There are two packages that are j necessary to implement JAXR: the javax.xml.registry package contains the interface to access the registry while the javax.xml.registry.info model package contains interfaces that define registry objects and how those objects are interrelated.

Question 3.
Elucidate SOA. Are SOA and EJB mutually exclusive?
Answer:
At the core of Service-oriented architecture (SOA) lies the concept of service. A simplistic definition of service is a group of related components that carry out a given business process function, e.g. transferring funds between banks or booking an itinerary. An SOA, thus, is a paradigm focusing on the development of services rather than piecemeal components such that these services provide a higher level of abstraction from a functional standpoint.

It is, of course, essential for EJB developers and architects to understand that SOA and EJB are not mutually exclusive but rather are symbiotic. You can write robust SOA architectures using EJB. You might even be called upon to implement SOA projects using EJB.

Question 4.
Are SOA and Web Services the same? Elaborate.
Answer:
The terms Web Services and SOA are often used interchangeably and wrongly so. SOA is a paradigm as elaborated above. There are many possible ways of building software so that it implements salient features of SOA (mainly coarse granularity and loose coupling). One such way is Web Services. Web Services are a group of XML technologies that can be used for implementing SOA. Core Web Service technologies – mainly SOAP and WSDL – form the basis of most of these Web Service implementations today.

Question 5.
Elucidate SOAP.
Answer:
Simple Object Access Protocol (SOAP) is an XML-based application-level protocol intended for exchanging information in a distributed network. SOAP supports both the models of distributed computing: RPC as well as document-style messaging. RPC style SOAP allows remote invocation of operations. The RPC in-out parameters and return values of these operations are serialized into XML, whereas in document-style SOAP, because an operation’s input and output are XML fragments, serialization of parameters and return values to XML is not needed.

Although most of the Web Service applications use SOAP over HTTP today, the standard does not preclude using SOAP over other Internet protocols, such as Simple Mail Transfer Protocol (SMTP). The latest version of SOAP, viz. SOAP 1.2, is a World Wide Web Consortium (W3C) Recommendation.

Question 6.
Elucidate WSDL.
Answer:
Web Service. Description Language (WSDL) is an XML-based metadata standard that is used to describe the service interface as well as service binding information. For RPC style services, a WSDL service interface consists of the supported operations, the input-output parameters that these operations accept, and their return values. For document-style services, the service interface description contains the XML schema fragments for the input-output messages of the service operations, whereas the service binding description specifies communication protocols, ports, the service URL, and other such binding information. Now, the latest version of WSDL, viz. WSDL 2.0, is well on its way to becoming a W3C standard.

The backbone of web services is communication used to transmit between web service providers to an XML registry and from an XML registry to a web services consumer. The Web Service Description Language (WSDL) is a standard used to describe network services used to facilitate the interaction between web services providers and consumers. Organizations that either
publish web services or consume web services must be able to communicate with each other using an agreed-upon protocol. Protocols supported by an organization are described using WSDL.

WSDL standardizes XML elements that describe a collection of communication endpoints. WSDL defines a network service using seven XML elements, viz. type, message, operation, port type, binding, port, and service. WSDL has binding extensions for popular protocols and message formats that are positioned on top of the network service definition. These include SOAP 1.1, HTTP GET/POST, and MIME.

Question 7.
Explain service-oriented architecture with Web services.
Answer:
Web services are a way of building a Service-Oriented Architecture (SOA). SOA is an architectural approach to structuring large-scale, distributed systems that integrate heterogeneous applications behind ‘service’ interfaces. Figure 12 shows the basic model of a service lookup in a Service-Oriented Architecture as supported by Web services technologies:-

WEB SERVICES & XML Interview Questions in Java chapter 9 img 1

1. A service provider creates an abstract service definition that can ‘publish’ in a service registry. With Web services, the description is a Web Services Description Language (WSDL) file, and the registry follows the Universal Description, Discovery, and Integration (UDDI) standard.

2. A service requestor can find the service description, possibly using a set of selection criteria to query the registry.

3. If a suitable description is found, the requestor can bind to and use the service.

Question 8.
Can you explain the concept of Web services in the form of an equation?
Answer:
The set of de facto standards that make up Web services today can be summarized in the form of the following simple equation:-

WEB SERVICES & XML Interview Questions in Java chapter 9 img 2

Question 9.
Elucidate JMS.
Answer:
The Java Message Service (JMS) is a messaging standard, designed to eliminate many of the disadvantages MOM (Message-Oriented Middleware) products have faced over the past few years. JMS has two parts: an API, for which you write code to send/receive messages, and a Service Provider Interface (SPI) where you plug in JMS providers. A JMS provider knows how to talk to a specific MOM implementation.

Question 10.
What is an Object-Relational (OR) mapping? Elaborate.
Answer:
The simplest way to persist objects in Java is to use Java’s native serialization API that lets you write objects to files. Another popular way to store Java objects is to use a traditional relational database management system (RDBMS) such as Oracle, DB2, Microsoft SQL Server, etc. Rather than serialize an object as a complete bit blob, we would decompose each object inti’) its constituent parts and store each part separately. For instance, for a bank account object, the bank account number could be stored in one relational database field and the bank account balance in another field.

When you save your Java objects, you would use JDBC to ‘map’ the object data into a relational database. When you want to load your objects from the database, you would instantiate an object from that class, read the data in from the database, and then populate that object instance’s field with the relational data read in. This is shown in Figure 13.

WEB SERVICES & XML Interview Questions in Java chapter 9 img 3

This mapping of objects to relational databases is a technology called ofc/ECF-relational mapping. It is the act of converting and upconverting in-memory objects to relational data. An object-relational (OR) mapper may map your objects to any kind of relational database schema.

For instance, a simple object-relational mapping engine might map a Java class to a SQL table definition. An instance of that class would map to a row in that table, while fields in that instance would map to individual cells in that row. This is shown in Figure 14.

WEB SERVICES & XML Interview Questions in Java chapter 9 img 4

Question 11.
Elucidate publish/subscribe messaging domain.
Answer:
When you perform messaging, you first need to choose the messaging domain: publish/subscribe (pub/sub) or point-to-point (PTP). PTP is a special case of pub/sub. So, we shall describe only the latter over here. Publish/subscribe messaging is analogous to watching television: many TV stations broadcast their signals, and many people listen to their broadcasts. Thus, with pub/sub, you can have ‘many’ message producers talking to ‘many’ message consumers. In this sense, the pub/subdomain is an implementation of a distributed event-driven processing model.

Subscribers (listeners) register their interest in a particular event ‘topic’. Publishers (event sources) create messages (events) that are distributed to all of the subscribers (listeners). Producers aren’t hard-coded to know the specific consumers in receiving its messages; rather, the MOM system maintains the subscriber list. You will get an idea of pub/sub vs. P-T-P messaging domains from Figure 15.

WEB SERVICES & XML Interview Questions in Java chapter 9 img 5

Question 12.
What criteria would you employ while choosing between servlets and stateless session beans as Web service endpoints?
Answer:
Here are some guidelines that should help you in choosing between servlets and stateless session beans as Web service endpoints.

Use a servlet as a Web service endpoint if:

  1. The business logic of the service is within a Web tier since in this case both the endpoint and Web service’s business implementation will reside in the same tier.
  2. You need a lightweight Web service container, viz. servlet container.
  3. You need to execute some logic that resides on the Web tier before invoking Web services.
  4. You do not mind writing logic for synchronizing multithreaded access to your service. This is required since, the servlet container does not synchronize concurrent requests to the servlet instance and hence, in this case, to your Web service endpoint.

Use a stateless session bean as a Web service endpoint if:

  1. The business logic of the service is within an EJB tier since in this case both the endpoint and Web service’s business implementation will reside in the same tier.
  2. You need the Web service implementation to avail themselves of the transaction- and component-level security services from the container.
  3. You need to execute some logic that resides on the EJB tier before invoking Web services.
  4. You want the container to take care of synchronizing concurrent access to your service.

Question 13.
Elucidate Aspect-Oriented Programming (AQP).
Answer:
‘Aspect’ forms the core of Aspect-Oriented Programming (AOP). Aspects are reusable services that are quintessentially cross-cutting of your application. In the context of a business application, services that provide user authentication, user authorization, logging of access to the system, and persistence of application data are examples of cross-cutting services or ‘concerns’ for a business application developer – ‘concerns’ because a developer cannot write robust applications without taking care of them. Hence, AOP can be defined as a programming platform that facilitates the development of ‘aspects’ to mitigate ‘concerns’ so that ‘aspects’ can be ‘reused’ by all living objects within a given environment.

Question 14.
Does the EJB world use AOP techniques?
Answer:
Yes! It does!! All the services that our beans get are ‘aspects’, e.g. persistence, life-cycle management, transaction management, security, and dozens of other things that we, the business application developers, care about. EJB containers implement these cross-cutting ‘concerns’ and provide reusable ‘aspects’ so that all the beans deployed within the container can offload these ‘concerns’ on the container ‘aspects’. However, there is a caveat, viz. the EJB programming model does not allow you to develop new ‘aspects’ to take care of ‘concerns’ that are not supported by the EJB container.

Question 15.
Is AOP different than OOP?
Answer:
Yes! It is!! One of the common traits of both AOP and OOP is reusability. However, OOP instills reusability via inheritance. This works well in a vertical parent-child relationship chain. But, OOP does not work when behavior needs to be used horizontally, owing to the behavior’s cross-cutting nature. Now, why should you want to reuse behavior horizontally? Since you don’t want your business object, e.g. a ShoppingCart, to inherit the behavior pertaining to transactions, because these behaviors are unrelated; you don’t want an apple to inherit grape-like qualities; rather, you want to mix apples and grapes to prepare a margarita. This is exactly where AOP comes into the picture. AOP and OOP are not competing but complementary technologies. Consider, for example, an EJB server where cross-cutting ‘aspects’ are provided to your object-oriented beans. To conclude, OPP and AOP coexist.

Question 16.
Elucidate XML.
Answer:
XML (Extensible Markup Language) is a framework for defining markup languages. In contrast to HTML (HyperText Markup Language), there is no fixed collection of markup tags in XML. Instead, XML lets you define your own tags, tailored and customized to the kind of information you wish to represent. Each XML language is targeted at a particular application domain, but all of them will share many common features such as they all use the same markup syntax and they all benefit from a common set of generic tools for processing documents.

Question 17.
Is XML merely an extension of HTML? Elaborate.
Answer:
XML is not an extension of HTML, nor is it a replacement for HTML, which ideally should be just another XML language. However, because of a number of minor syntactical differences, HTML does not directly fit into the XML framework. As a remedy, the W3C has designed XHTML as an XML variant of HTML.

Question 18.
What are the inherent advantages of using XML?
Answer:
XML has been designed with some simple but powerful principles in mind. First of all, it allows tailor-made markup for any imaginable application domain. As an additional benefit, XML is inherently internationalized and platform-independent. All XML documents are written in the Unicode alphabet which leads to easy internationalization.

Finally, XML is designed and intended to be the future of all structured information. This even includes information stored in relational databases, which has motivated and led to the development of the powerful query language – XQuery. In fact, XML was designed to bring the power of SGML (Standard Generalized Markup Language), which was standardized in 1986, to the Web. A major benefit of using XML is the availability of “generic tools and technologies” that surround the core XML notation. t

Question 19.
When would you use XML with EJB?
Answer:
Using XML with EJB is useful in the following scenarios:-

  1. Pbr data-driven integration
  2. As a document persistence mechanism
  3. As a Web service interface

Question 20.
In the XPath data model, what is an XML tree?
Answer:
In the XPath data model, an XML tree is a special kind of ordered tree whose nodes can be any of the following kinds:-

  • Text nodes
  • Element nodes
  • Attribute nodes
  • Comment nodes
  • Processing instruction nodes
  • Root nodes

Question 21.
Is an XML document just a tree structure, just a textual representation, or both?
Answer:
An XML document can be considered both in its textual representation and as a tree structure.

Question 22.
Elucidate XPath.
Answer:

  • XPath is a language used to navigate XML trees.
  • The development of several different XML technologies has identified a common need for a flexible notation for pointing into and navigating around XML documents. This has resulted in the XPath language, which is used for:
  • uniqueness and scope descriptions in XML Schema;
  • for pattern matching and selection in XSLT;
  • for selection and iteration in XQuery; and,
  • as a key component of XLink and XPointer.

Besides, a part of XPath is able to express computations on data values, which is well exploited in XSLT and XQuery.

Question 23.
Elucidate XPointer and XLink.
Answer:
XPointer and XLink provide hyperlinks in general XML documents. The XPointer language generalizes the ability to point at specific places ins XML documents.

Question 24.
Elucidate XSLT.
Answer:
The XSLT language is used to transform XML documents using XSL (Extensible Stylesheet Language) technology.

1. The XSL technology has two constituents: XSLT (XSL Transformations), which is a declarative programming language for specifying transformations between XML languages, and XSL-LO (XSL Formatting Objects, which is a particular target language suitable for specifying the physical layout.

2. XSLT was originally developed and designed as a generalized stylesheet, intended to fit in the same niche as CSS (Cascading Stylesheets). However, it has developed into a complete programming language with many more applications. The behavior of a stylesheet may be obtained by specifying a transformation into the XHTML language, which enables rendering in a browser. But,

3. XSLT transformations may also be used to translate between other XML languages, extract views of XML data, and perform query-like computations. XSLT transformations may be executed in standalone tools, but they are also supported by all modern browsers. Specifically, an XML document may contain a processing instruction that links to an external XSLT document. A browser will, then load the XSLT file, execute the corresponding transformation and present the result, which will presumably be an XHTML document.

Question 25.
Elucidate XQuery.
Answer:
XML documents naturally generalize database relations. XQuery is the corresponding generalization of SQL. There are many reasons why a merger of XML and databases is attractive. But, the main strategic advantage is that if XML is the future of WWW and XML becomes the future of databases, then in the future, the WWW’ will simply become one gigantic database. That’s why XQuery is designed to generalize SQL, as XML generalizes database tables.

Question 26.
Evaluate XQuery vis-a-vis XSLT.
Answer:
XQuery and XSLT may emulate each other but are designed for different tasks:-

1. While XSLT is exceedingly good at defining complicated recursive traversals and transformations to arbitrary depths of XML documents, while XQuery must use explicit recursion for user-defined functions.

2. Conversely, XQuery has more the flavor of a database programming language and allows simple solutions for simple problems, while XSLT may be more verbose.

Question 27.
Can you elucidate the relation between Web services and XML?
Answer:
Web services support service-oriented architectures (SOA) using in particular, XML and HTTP.

  • The basic Web service standards, as already elaborated, are SOAP, WSDL, and UDDI. While SOAP is a protocol for exchanging XML documents, typically but not necessarily using HTTP, WSDL is an interface description language for Web services. Again, U DDI is a system for making clients and servers find each other. And, not surprisingly, all three of them use an XML notation.

Question 28.
Give one feature each of SOAP, WSDL, and UDDI.
Answer:
The main strengths of SOAP are support for intermediaries, fault management, and RPC (Remote Procedure Calls) interactions. A WSDL description of a Web service describes its functionality, data encodings, communication protocols, and location. UDDI allows Web services to be registered and discovered.