Top Interview Questions & Answers | Learn Now

Java Web Services Interview Questions and Answers | Basic and Advanced

Written by Venkatesan M | May 25, 2017 10:51:33 AM

Q1. What are web services ?

Ans: Web services  are client and server applications that communicate over the World Wide Web’s (WWW) HyperText Transfer Protocol (HTTP). Web services provide a standard means of inter operating between software applications running on a variety of platforms and frameworks.

Main characteristics of the Web Services  are :
1. Interoperability
2. Extensibility
3. Machine processable descriptions.

for example in simple words , when we call somebody so the person dialing and calling is the client  application , while person receiving the call is server applicationand "hello" word is the protocol as similar to HTTP request .

Q2. What is the difference between SOA and a web service?

Ans: SOA (Service-Oriented Architecture) is an architectural pattern that makes possible for

services to interact with one another independently.

Web Services is a realization of SOA concept, that leverages XML, JSON, etc. and common Internet protocols such as HTTP(S), SMTP, etc.

SOA is a system-level architectural style that tries to expose business. WOA is an interface-level architectural style that focuses on the means by which these service capabilities are exposed to consumers.

Q3. What is SOAP?

Ans:

SOAP (Simple Object Access Protocol) is a transport protocol for sending and receiving requests and responses on XML format, which can be used on top of transport protocols such as HTTP, SMTP, UDP, etc.

Q4. What is REST?

Ans:

REST (REpresentational State Transfer) is an architectural style by which data can be transmitted over transport protocol such as HTTP(S).

Q5. What is the difference between a REST web service and a SOAP web service?

Ans:

Below are the main differences between REST and SOAP web service

  • REST supports different formats like text, JSON and XML; SOAP only supports XML;
  • REST works only over HTTP(S) on a transport layer; SOAP can be used different protocols on a transport layer;
  • REST works with resources, each unique URL is some representation of a resource; SOAP works with operations, which implement some business logic through different interfaces;
  • SOAP based reads can’t be cached, for SOAP need to provide caching; REST based reads can be cached;
  • SOAP supports SSL security and WS-security(Web Service-security); REST onlysupports SSL security;
  • SOAP supports ACID(Atomicity, Consistency, Isolation, Durability); REST supports transactions, but it is neither ACID compliant nor can provide two phase commit.

Q6. How  to decide which one of web service to use REST or SOAP? 

Ans:

“REST vs SOAP” we can rephrased to "Simplicity vs Standard". Of course, "Simplicity" with REST at most cases wins, it wins in performance, scalability and support for multiple data formats, but SOAP is favored where service requires comprehensive support for security (WS-security) and transactional safety (ACID).

 Q7. What is WSDL?

Ans:

WSDL (Web Services Description Language) is an XML format for describing web services and how to access them.

Q8. What is JAX-WS?

Ans:

JAX-WS (Java API for XML Web Services) is a set of APIs for creating web services in XML format.

Q9. What is JAXB?

Ans:

JAXB (Java Architecture for XML Binding) is a Java standard that defines how Java objects are converted from and to XML. It makes reading and writing of XML via Java relatively easy.

Q10. Can we send soap messages with attachments?

Ans:

Yes, we can send different formats such as PDF document, image or other binary file with soap messages as an attachment. Messages send using the binary data. SOAP messages is attached with MIME extensions that come in multipart/related.

An example:

MIME-Version: 1.0

Content-Type: Multipart/Related; boundary=MIME_boundary; type=text/xml;

start="<claim061400a.xml@ javahungry.com>"

Content-Description: This is the optional message description.

<?xml version='1.0' ?>

<SOAP-ENV:Envelope

xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

<SOAP-ENV:Body>

<theSignedForm href="cid:claim061400a.tiff@javahungry.com"/>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

--MIME_boundary

Content-Type: image/tiff

Content-Transfer-Encoding: binary

Content-ID: <claim061400a.tiff@javahungry.com>

...binary TIFF image...

--MIME_boundary—

Q11. What is MTOM?


Ans:

MTOM (Message Transmission Optimization Mechanism) is a mechanism for transmitting large binary attachments with SOAP messages as raw bytes, allowing for smaller messages.

Q12. What is XOP?

Ans:

XOP (XML-binary Optimized Packaging) is a mechanism defined for the serialization of XML Information Sets that contain binary data, as well as deserialization back into the XML Information Set.

Q13. What is a SOAP envelope element?

Ans:

SOAP envelop element is the root element of a SOAP message which defines the XML document as a SOAP message.

An example:

<?xml version="1.0"?>

<soap:Envelope

xmlns:soap="http://www.w3.org/2001/12/soap-envelope"

soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

Message information

</soap:Envelope>

Q14. What does a SOAP namespace defines?

Ans:

SOAP namespace defines the Envelope as a SOAP Envelope.

An example:

xmlns:soap=http://www.w3.org/2001/12/soap-envelope

Q15. What is the SOAP encoding?

Ans:

SOAP encoding is a method for structuring the request which is suggested within the SOAP specification, known as the SOAP serialization.

Q16. What does SOAP encodingStyle attribute defines?

Ans:

SOAP encodingStyle defines the serialization rules used in a SOAP message. This attribute may appear on any element, and is scoped to that element's contents and all child elements not themselves containing such an attribute. There is no default encoding defined for a SOAP message.

An example: 

SOAP-ENV:encodingStyle="http://www.w3.org/2001/12/soap-encoding"

Q17. What are 2 styles web service’s endpoint by using JAX-WS?

Ans:

  1. RPC (remote procedure call) style web service in JAX-WS;
  2. document style web service in JAX-WS.

Q18. What is encoding rules for header entries?

Ans:

  • a header entry is identified by its fully qualified element name, which consists of the namespace URI and the local name. All immediate child elements of the SOAP Header element must be namespace-qualified.
  • the SOAP encodingStyle attribute may be used to indicate the encoding style used for the header entries.
  • the SOAP mustUnderstand attribute and SOAP actor attribute may be used to indicate how to process the entry and by whom.

Q19. What is the wsimport tool?

Ans:

The wsimport tool is used to parse an existing Web Services Description Language (WSDL) file and generate required files (JAX-WS portable artifacts) for web service client to access the published web services: https://docs.oracle.com/javase/6/docs/technotes/tools/share/wsimport.html

Q20. What is the wsgen tool?

Ans:

The wsgen tool is used to parse an existing web service implementation class and generates required files (JAX-WS portable artifacts) for web service deployment: http://docs.oracle.com/javase/6/docs/technotes/tools/share/wsgen.html

Q21. What the tool are required to test SOAP services?

Ans:

SOAPUI tool for SOAP WS: http://www.soapui.org/

Q22. What is the difference between SOAP and other remote access techniques?

Ans:

  • SOAP is simple to use and it is non - symmetrical unlike DCOM or CORBA is highly popular and usually have complexity in them.
  • SOAP provides greater platform independent with the language independence unlike DCOM or CORBA doesn't provide any of these.
  • SOAP uses HTTP as its transport protocol and the data are being saved in XML format that can be ready by human, whereas DCOM or CORBA have their own binary formats that are used to transport the data in complicated manner.
    SOAP identify the object other than URL endpoint. SOAP objects are stateless and it is hard to maintain that. Whereas, it is not hard to maintain in case of other remote access techniques.

Q23. What is a resource in a REST?

Ans:

A resource is a unique URL with representation of an object which we can get contents via GET and modify via PUT, POST, DELETE.

Q24. What are HTTP methods supported by REST?

Ans:

  • GET;
  • POST;
  • PUT;
  • DELETE;
  • OPTIONS;

Q25. Whether can use GET request instead of POST to create a resource?

Ans:

It is not possibly, because GET can’t change a resource.

Q26. What is the difference between PUT and POST?

Ans:

Need to use PUT when can update a resource completely through a specific resource. For example, if know that an article resides at http://javahungry.blogspot.com/article/123, can PUT a new resource representation of this article through a PUT on this URL. If do not know the actual resource location for instance, when add a new article, can use POST.

PUT is idempotent, while POST is not. It means if use PUT an object twice, it has no effect.

Q25. What is WADL?

Ans:

WADL (Web Application Description Language) is a XML description of a deployed RESTful web application.

Q26. What are frameworks available to implement REST web services? 

Ans:

Jersey, Restlet, EasyRest, etc.

Q27. What is the Restlet framework?

Ans:

Restlet is a lightweight, comprehensive, open source RESTful web API framework for the Java platform.

It has advantages such as

  • websocket and server-sent events support;
  • HTTP/2 support;
  • transparent HTTP PATCH support;
  • client cache service;
  • fluent APIs.

Q28. What is the Jersey framework?

Ans:

Jersey is open source framework for developing RESTful Web Services in Java that provides support for JAX-RS APIs and serves as a JAX-RS (JSR 311 & JSR 339) Reference Implementation. It has advantages such as

  • contains support for Web Application Description Language (WADL);
  • contains Jersey Test Framework which lets run and test Jersey REST services inside JUnit;
  • supports for the REST MVC pattern, which would allow to return a View from Jersey services rather than just data.

Q29. What is the RESTeasy framework?

Ans:

RESTeasy is a JBoss project, which implements of the JAX-RS specification. It has benefits such as

  • fully certified JAX-RS implementation; supports HTTP 1.1 caching semantics including cache revalidation;
  • JAXB marshalling into XML, JSON, Jackson, Fastinfoset, and Atom as well as wrappers for maps, arrays, lists, and sets of JAXB Objects;
  • OAuth2 and Distributed SSO with JBoss AS7;
  • rich set of providers for: XML, JSON, YAML, Fastinfoset, Multipart, XOP, Atom, etc.

Q30. What is the difference between AJAX and REST?

Ans:

  • in Ajax, the request are sent to the server by using XMLHttpRequest objects; REST have a URL structure and a request/response pattern the revolve around the use of resources;
  • Ajax eliminates the interaction between the customer and server asynchronously; REST requires the interaction between the customer and server;
  • Ajax is a set of technology; REST is a type of software architecture and a method for users to request data or information from servers.

Q31. What tool are required to test REST services?

Ans:

Firefox “poster” plugin for RESTFUL services. https://addons.mozilla.org/en-us/firefox/addon/poster/

Q32. What does a @Path annotation do? 

Ans:

@Path annotation binds URI pattern to a Java method.

import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.core.Response;

@Path("/persons")

public class PersonRestService {

@GET

public Response getPerson() {

return Response.status(200).entity("getPerson is called").build();

}

@GET

@Path("/vip")

public Response getPersonVIP() {

return Response.status(200).entity("getPersonVIP is called").build();

}

}

On calling URI: “/persons” result:  getPerson is called

On calling URI: “/persons/vip” result:  getPersonVIP is called

Q33. What does a @PathParam do?

Ans:

@PathParam annotation injects the value of URI parameter that defined in @Path expression.

import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.PathParam;

import javax.ws.rs.core.Response;

@Path("/persons")

public class PersonRestService {

@GET

@Path("{id}")

public Response getPersonById(@PathParam("id") String id) {

return Response.status(200).entity("getPersonById is called, id : " + id).build();

}

}

On calling URI: “/persons/1” result:  getPersonById is called, id : 1

Q34. What does a @QueryParam do?

Ans:

@QueryParam annotation injects URI query parameter into Java method.

import java.util.List;

import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.QueryParam;

import javax.ws.rs.core.Response;

@Path("/persons")

public class PersonService {

@GET

@Path("/query")

public Response getPersons(

@QueryParam("from") int from,

@QueryParam("to") int to,

@QueryParam("orderBy") List&lt;String&gt; orderBy) {

return Response

.status(200)

.entity("getPersons is called, from : " + from + ", to : " + to

+ ", orderBy" + orderBy.toString()).build();

}

}

Q35. What does a @MatrixParam do?

Ans:

@MatrixParam are a set of “name=value” in URI path.

import javax.ws.rs.GET;

import javax.ws.rs.MatrixParam;

import javax.ws.rs.Path;

import javax.ws.rs.PathParam;

import javax.ws.rs.core.Response;

@Path("/books")

public class BookService {

@GET

@Path("{year}")

public Response getBooks(@PathParam("year") String year,

@MatrixParam("author") String author,

@MatrixParam("country") String country) {

return Response

.status(200)

.entity("getBooks is called, year : " + year

+ ", author : " + author + ", country : " + country)

.build();

}

}

Q36. What does a @FormParam do?

Ans:

@FormParam bind HTML form parameters value to a Java method.

import javax.ws.rs.FormParam;

import javax.ws.rs.POST;

import javax.ws.rs.Path;

import javax.ws.rs.core.Response;

@Path("/persons")

public class PersonService {

@POST

@Path("/add")

public Response addPerson(

@FormParam("name") String name,

@FormParam("age") int age) {

return Response.status(200)

.entity("addPerson is called, name : " + name + ", age : " + age)

.build();

}

}

 Q37.How to get HTTP request header in JAX-RS (2 ways)?

Ans:

inject directly with @HeaderParam;

import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.HeaderParam;

import javax.ws.rs.core.Response;

@Path("/persons")

public class PersonService {

@GET

@Path("/get")

public Response getPerson(

@HeaderParam("person-agent") String personAgent) {

return Response.status(200)

.entity("getPerson is called, personAgent : " + personAgent)

.build();

}

}

  • pragmatically via @Context.

import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.core.Context;

import javax.ws.rs.core.HttpHeaders;

import javax.ws.rs.core.Response;

@Path("/persons")

public class PersonService {

@GET

@Path("/get")

public Response getPerson(@Context HttpHeaders headers) {

String personAgent = headers.getRequestHeader("person-agent").get(0);

return Response.status(200)

.entity("getPerson is called, personAgent : " + personAgent)

.build();

}

}

38.How to download file in JAX-RS?

  • put @Produces(“?”) on service method, with a Response return type. Instead “?” write a type text/plain, image/png, etc.
  • set “Content-Disposition” in Response header to tell browser pop up a download box for user to download.

import java.io.File;

import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.Produces;

import javax.ws.rs.core.Response;

import javax.ws.rs.core.Response.ResponseBuilder;

@Path("/image")

public class ImageService {

private static final String FILE_PATH = "c:\\my.png";

@GET

@Path("/get")

@Produces("image/png")

public Response getFile() {

File file = new File(FILE_PATH);

ResponseBuilder response = Response.ok((Object) file);

response.header("Content-Disposition",

"attachment; filename=image_from_server.png");

return response.build();

}

}

Q39. What is new in this field for past few years?

Ans:

The initiation of XML in this field is the advancement that provides web service a single language to communicate in between the RPCs, web services and their directories.

Q40. Give me an example of real web service?

Ans:

One example of web services is IBM Web Services browser. You can get it from IBM Alphaworks site. This browser shows various demos related to web services. Basically web services can be used with the help of SOAP, WSDL, and UDDI . All these, provide a plug-and-play interface for using web services such as stock-quote service, a traffic-report service,  weather service etc.

Q41. How you define web service protocol stack?

Ans:

It is basically set of various protocols that can be used to explore and execute web services. The entire stack has four layers i.e. Service Transport, XML Messaging, Service Description and Service Discovery.

Q42. Can you define each of these layers of protocol stack?

Ans:

The Service Transport layer transfer messages between different applications, such as HTTP, SMTP, FTP, and Blocks Extensible Exchange Protocol (BEEP). The XML Messaging layer encodes messages in XML format so that messages can be understood at each end, such as XML-RPC and SOAP. The Service Description layer describes the user interface to a web service, such as WSDL. The Service Discovery layer centralizes services to a common registry and offer simple publish functionality, such as UDDI.

Q43. Define XML – RPC?

Ans:

It is a protocol that makes use of XML messages to do Remote Procedure Calls.

Q44. Define WSDL?

Ans:

It means Web Services Description Language. It is basically the service description layer in the web service protocol stock. The Service Description layer describes the user interface to a web service.

Q45. What kind of security is needed for web services?

Ans:

The security level for web services should be more than that of what we say Secure Socket Layer (SSL). This level of security can be only achieved from Entrust Secure Transaction Platform. Web services need this level of security to ensure reliable transactions and secure confidential information .

Q46. Do you have any idea about foundation security services?

Ans:

As implies from its name, these services are the foundation or basics of integration, authentication, authorization, digital signatures and encryption processes.

Q47. Define Entrust Identification Service?

Ans:

Entrust Identification Service comes from the Entrust Security Transaction Platform. This platform allows companies to control the identities that are trusted to perform transactions for Web services transactions.

Q48. What UDDI means?

Ans:

UDDI stands for Universal, Description, Discovery, and Integration. It is the discovery layer in the web services protocol stack.

Q49. Define Entrust Entitlements Service?

Ans:

This service verifies entities that attempt to access a web service. For Example, the authentication service, the Entitlements Service ensures security in business operations.

Q50. Define Entrust Privacy Service?

Ans:

As its name implies, it deals with security and confidentiality. This service encrypts data to ensure that only concerned parties can access the data.

Q51. What do you mean by PKI?

Ans:

It means Public-Key Infrastructure.

Q52. What tools are used to test a web service?

Ans:

I have used SoapUI for SOAP WS and Firefox poster plugin for RESTFul Services.

Q53. Differentiate between a SOA and a Web service?

Ans:

SOA is a design and architecture to implement other services. SOA can be easily implemented using various protocols such as HTTP, HTTPS, JMS, SMTP, RMI, IIOP, RPC etc. While Web service, itself is an implemented technology. In fact one can implement SOA using the web service.

Q54. Discuss various approaches to develop SOAP based web service?

Ans:

We can develop SOAP based web service with two different types of approaches such as contract-first and contract-last. In the first approach, the contract is defined first and then the classes are derived from the contract while in the later one, the classes are defined first and then the contract is derived from these classes.

Q55. If you have to choose one approach, then what will be your choice?

Ans:

In my point of view, the first approach that is the contract-first approach is more feasible as compared to the second one but still it depends on other factors too.

Q56. Is there any special application required to access web service?

Ans:

No, you don’t need to install any special application to access web service. You can access web service from any application that supports XML based object request and response.

Q57. Can you name few free and commercial implementations for web services?

Ans:

The implementations I know are Apache SOAP, JAX-WS Reference Implementation, JAX-RS Reference Implementation, Metro, Apache CXF, MS.NET and Java 6.

Q58. Name browser that allows access to web service?

Ans:

JavaScript XmlHttpRequest object is required to access web service via browsers. The browsers that support this object are Internet Explorer, Safari and Mozilla-based browsers like FireFox.

Q59. What is REST?

Ans:

REST stands for Representational State Transfer. REST itself is not a standard, while it uses various standards such as HTTP, URL, XML/HTML/GIF/JPEG (Resource Representations) and text/xml, text/html, image/gif, image/jpeg, etc (MIME Types).

Q60. How one can provide API to users?

Ans:

To provide an API to the users, one can easily do this with an “open table”. All you need to do is to write open table which is basically an XML schema that point to a web service.

Q61. Name the various communication channels in web service?

Ans:

Web service is integrated with three protocols such as HTTP/POST, HTTP/GET, and SOAP. It provides three different communication channels to clients. Client can choose any communication method as per requirements.

Q62. How can you document web service?

Ans:

Web services are contemplated as self-documenting because they provide entire information regarding the available methods and parameters used for XML based standard, known as WSDL. One can also provide more information to explain web services via their own WebService and WebMethod attributes.

Q63. What are the situations, when we need ASP.NET web services?

Ans:

ASP.NET web services are used when one need to implement three tier architecture in a web service. It allows handy ways to use middle tier components through internet. The main advantage of .NET Web services is that they are capable enough to communicate across firewalls because they use SOAP as transport protocol.

Q64. What are distributed technologies?

Ans:

The increasing ratio of distributed applications has raised demand for distributed technologies. It allows segmenting of application units and transferring them to different computers on different networks.

Q65. Differentiate between web services, CORBA and DCOM?

Ans:

Web services transfer/receive messages to/from application respectively, via HTTP protocol. It uses XML to encode data.

CORBA and DCOM transfer/receive messages to/from application respectively, via non-standard protocols such as IIOP and RPC.

Q66. Can you tell few benefits of web services?

Ans:

The biggest advantage of web service is that is supported by wide variety of platforms. Moreover, in near future, web services may spread its boundary and enhance new methods that will provide ease to clients. The enhancement will not affect the clients, even if they offer old methods and parameters.

Q67. Can you name some standards used in web services?

Ans:

The standards used in web services are WSDL (used to create interface definition), SOAP (used to structure data), HTTP (communication channels), DISCO (used to create discovery documents) and UDDI (used to create business registries).

Q68. Explain in brief, what DISCO is?

Ans:

DISCO means discovery. It groups the list of interrelated web services. The organization that provides web services, issues a DISCO file on its server and that file contains the links of all the provided web services. This standard is good when client knows the company already. Also it can be used within a local network as well.

Q69. Explain in brief, what UDDI is?

Ans:

UDDI (Universal Description, Discovery, and Integration) provides consolidated directory for web services on the internet. Clients use UDDI to find web services as per their business needs. It basically hosts the web services from various companies. In order to share web services, you need to publish it in UDDI.

Q70. Explain the .NET web services supported data types? 

Ans:

.Net web services uses XML-based standards to transfer/receive information. Thus, .NET web services can only works with data types known by XML schema standard. Like FileSteam, Eventlog etc. are not recognized by the XML schema standards and hence, not supported in web services.

Q71. How a .NET web service is tested?

Ans:

ASP.NET uses a test page routinely, when one calls for the URL of .asmx file in any browser. This page shows complete information regarding web services.

Q72. How a .NET web service is consumed?

Ans:

Since we know that web services are constructed on XML standards. Therefore, clients need to have complete understanding of XML-based messages to interchange messages. Clients can communicate with web services through .NET framework that offers proxy mechanisms. These proxy mechanisms have detailed information regarding data sharing within web services that can be easily used by the clients.

Q73. Can you name the two Microsoft solutions for distributed applications?

Ans:

The two Microsoft solutions for distributed applications are .NET Web Services and .NET Remoting.

Q74. Differentiate between .NET Web Services and .NET Remoting?

Ans:

As far as protocol is concerned, .NET Web Service uses HTTP, while, .NET Remoting uses any protocol i.e. TCP/HTTP/SMTP. When it comes to performance, .NET Remoting is comparatively, faster than.NET Web Service. Also, as .NET Web Services are hosted via IIS, therefore, it is far more reliable than the .NET Remoting.

Q75. Name the components to be published while deploying a Web Service?

Ans:

The components that need to be published during a web service deployment are Web Application Directory, Webservice.asmx File, Webservice.Disco File, Web.Config File and Bin Directory.

Q76.What are the steps performed by the client to access a web service?

Ans:

First of all a web reference to the web service is created by the client in his application. Then a proxy class is generated. After that an object of the proxy class is created and at last, the web service is accessed via that proxy object.

Q77. How web services are implemented in .NET?

Ans:

To implement web services in .NET, HTTP handlers are used that interrupt requests to .asmx files.

Q78. Explain few disadvantages of Response Caching?

Ans:

Response Caching is useless or incompetent when method accepts extensive amount of values because caching means to store lot of information.  Also, if the method depends on external source of information, and that are not provided within the parameters then such methods are bypassed.

Q79. What is the alternate solution to Response Caching?

Ans:

One can use Data Caching (System.Web.Caching.Cach) instead of Response Caching.

Q80. Brief few drawbacks of using GET and POST methods to communicate with the web service?

Ans:

These methods are less secure and inhibit users to pass structures and objects as arguments. Also, it doesn’t allow users to pass ByRef arguments.

Q81. How can one access a class as a web service?

Ans:

To access a class as a web service, one should inherit the class from the System.Web.Services.WebService class and qualify the class with the WebService attribute.

Q82. How can one access the web service class method via internet?

Ans:

To access web service class method via internet, one should qualify a method with the WebMethod attribute.

Q83. How a SOAP message is structured?

Ans:

A SOAP message is consists of SOAP Envelope, SOAP Headers, and SOAP Body.

Q84. Can you name different kinds of web services?

Ans:

There are two types of web services in total i.e. SOAP based web service and RESTful web service.

This question is already mentioned earlier.

Q85. What’s different in RESTful web services?

Ans:

The RESTful web services contains no contract or WSDL file.

Q86. Give me few reasons to use RESTful web service?

Ans:

The RESTFul web services are simple to implement and test. It supports various data formats such as XML, JSON etc.

Q87. Explain what is JAVA web services? What are the methods to create web services?

Ans:

Java webservices is developed to build and deploy basic web service on JAVA platform.

To create a web services, there are two approaches that are adopted

  1. Top-down approach
  2. Top-up approach

Q88. Explain what is JAXP?

Ans:

JAXP is a JAVA API for XML processing that enables application to write, read, manipulate and transform XML data.  Similarly, to perform other various function there are other Java API’s as well like JAX-RPC, JAXM, JAXR, JAXB, etc.

Q89. Mention the JAXB binding framework?

Ans:

JAXB binding framework is available in three Java Packages

  • bind:This package defines abstract classes and interfaces that are used directly with content classes
  • bind.util:This package contains utility classes that may be availed by client applications to manage marshalling, unmarshalling and validation events
  • bind.helper:This helper package gives partial implementations for some of the javax.xml.bind interfaces. These APIs are not to be directly used by applications using JAXB architecture

Q90. Give a simple example of how XML document can be Marshal and Unmarshal in JAVA framework?

Ans:

Marshalling is the process of converting XML document into Java readable form while UnMarshalling is the reverse process of Marshalling.  Let see how Java unmarshals an XML document and then marshals it back

JAXBContext jc= JAXBContext.newInstance (“com.acme.foo”);

// unmarshal from foo.xml

Unmarshaller u = jc.createUnmarshaller () ;

FooObject fooObj=

(FooObject)u.unmarshal (new File (“foo.xml”) );

// marshal to sytem.out

Marshaller m = jc.createMarshaller ();

m.marshal (fooObj, System.out);

Q91. Explain what does Marshaller do if jaxb.encoding property is not declared?

Ans:

By default, the Marshaller will use “UTF-8” if jaxb.encoding property is not declared.

Q92. Mention what are the types of validation can a JAXB client can perform?

Ans:

There are two types of JAXB client validation that a JAXB can perform

  1. Unmarshal Time Validation
  2. On-Demand Validation

Q93. Mention what are the three ways to handle the event encountered during the marshal, unmarshal and validate operations?

Ans:

  • Using the default event handler
  • Register and Implement a custom event handler
  • Use the ValidationEventCollector utility

Q94. Explain where does JAXB compiler is located?

Ans:

JAXB schema binding compiler is placed in the <JWSDP_Home>/jaxb/bin directory.  In this directory, there are two scripts, xjc.sh (Solaris/Linux) and xjc.bat (Windows).

Q95. In what cases do you need to customize the default binding?

Ans:

In some cases, you are required to customize the default binding like

  • Creating API documentation for the schema derived JAXB packages, classes, methods and constants
  • Giving semantically meaningful customized names for cases that the default XML name-to-Java identifier mapping cannot handle automatically
  • Overriding default binding- like specifying that a model group should be attached to a class rather than a list

Q96. Explain what is Inline Customization?

Ans:

Customization to JAXB bindings made by means of inline binding declarations  in an XML schema file that take the form of <xsd:appinfo> elements embedded in schema <xsd:annotation>elements.

Q97. Explain what is XML signature?

Ans:

XML can be used to sign any arbitrary data whether it is a binary or XML.  The data is recognized via URIs in one or more reference elements.  It is described in one or more forms, like detached, enveloping or enveloped.

Q98. Explain what is Stax?

Ans:

Stax stands for Streaming API for XML; it is an API to read and write XML documents, originating from the JAVA programming language.

Q99. Mention what are the usual XML APIs?

Ans:

The usual XML APIs includes

  • DOM based or Tree based APIs:The whole document is read into memory as a tree structure for random availability by calling application
  • Event based APIs:The application registers to get events as entities are encountered within the source document

Q100. Explain what is Push parsing and Pull parsing?

Ans:

  • Pull Parsing:Streaming pull parsing is referred to a programming model in which a client application calls methods on an XML parsing library, when it needed to communicate with an XML infoset- which means the client will only gets XML data when it is asked for
  • Push Parsing:In Push Parsing, the parser pushes parsing events or XML data to the application.  In push model, the parser got the hold over the parsing  process and the parser calls the implemented handler methods.

Q101. Explain on which technology does XWS security is based on? List out the options that XWS security provides for securing JAX-RPC applications?

Ans:

XWS security is based on securing web services build on JAX-RPC and on stand-alone application based on SAAJ.  For securing JAX-RPC application, options that XWS security provides are

  • XML digital signature
  • XML encryption
  • Username token verification
  • XWS security framework APIs

Q102. List out the six packages available in XML Digital signature API?

Ans:

Digital signature API is

  • crypto
  • crypto.dsig
  • crypto.dsig.keyinfo
  • crypto.dsig.spec
  • crypto.dom
  • crypto.dsig.dom

Q103. Explain what is JAXR?

Ans:

JAXR is the JAVA programming APIs for Java platform application to access and programmatically interact with various kinds of meta-data registries.

Q104. Explain what does the JAXR architecture consist of?

Ans:

JAXR architecture is consists of a JAXR client and JAXR provider.

  • JAXR client:It is a client program which uses the JAXR API to use a registry through a JAXR provider
  • JAXR provider:It is an implementation of the JAXR API that provide access to a particular registry provider or to a class of registry providers that are built on a common speicifications.

Q105. Explain what is JAXM messaging models?

Ans:

There are two types of messaging models for JAXM synchronous and asynchronous

  1. Synchronous messaging model:In such type of model, client directly communicates with the source. In this, the client will send the request and waits.
  2. Asynchronous messaging model:In this model, client directs the message to the messaging provider and returns back.  Messaging provider then executes the routing of the message to the end source.

Q106. Explain what is UDDI, DISCO and WSDL?

Ans:

  1. UDDI:It means Universal Description, Discovery and I It is the directory that is used to publish and discover public web services
  2. DISCO:It is commonly known as discovery. It clubs common services together and exposes schemas document of the web services
  3. WSDL:It stands for web service description language (WSDL). It is used to describe web services.  The description includes URL of web services, properties and methods supported by web services, data type it supports and protocol detail it supports

Related Interview Questions...

Core Java Interview Questions And Answers

Core Java Programming Interview Questions and Answers

Multithreading in Java Interview Questions and Answers

Javascript Interview Questions

Java/J2EE Apps Integration Questions and Answers.

Java Collections Interview Question and Answers

Interview Questions For Selenium with Java

Java Interview Questions and Answers

Tricky Java Interview Questions and Answers