Java Web Services Interview Questions

  1. What is a web service?
  2. What are the important parts of a web service?
  3. What are the advantages of Web Services?
  4. What are the different types of web services?
  5. What are SOAP Web Services?
  6. What is a WSDL?
  7. What is marshalling and unmarshalling? How do JAXB and XMLBeans help with this?
  8. What are the java frameworks that you can use to build web services?
  9. How do you handle security for Web Services?
  10. What are the popular Java Specifications for Web services?
  11. What is Service Oriented Architecture (SOA)?

What is a web service?

“Web

Simplest definition is a service offered over the web (internet) i.e. HTTP. Whenever we browse the internet, we are making use of innumerable web services. Even the simplest attempt to load a google.com website involves web services.

When we type in google.com in the browser, following steps happen in the background:

  • Step I : Browser invokes a get request on google.com.
  • Step II : google.com returns a HTTP response with the HTML content to show.
  • Step III : Browser understands the HTML content and renders it for the user.

Browser is invoking a get request and google.com server is responding with HTTP Response. This is a great example of a web service.

What are the important parts of a web service?

Let’s use the above example to understand the three important parts of a web service.

  • Service Provider : Google.com is the service provider. Handles the request and sends a response back.
  • Service Consumer : Browser is the service consumer. Creates Request. Invokes Service. Processes the Response.
  • Data Exchange Format : In this example, Data Exchange is done over HTTP protocol. Request is HTTP request and Response is HTTP Response. Data exchange format can be something else as well. SOAP (in case of SOAP web services) and JSON (most RESTful services).

What are the advantages of Web Services?

  • Re-use : Web services avoid the need to implement business logic repeatedly. If we expose a web service, other applications can re-use the functionality
  • Modularity : For example, tax calculation can be implemented as a service and all the applications that need this feature can invoke the tax calculation web service. Leads to very modular application architecture.
  • Language Neutral : Web services enable communication between systems using different programming languages and different architectures. For example, following systems can talk with each other : Java, .Net, Mainframes etc.
  • Web Services are the fundamental blocks of implementing Service Oriented Architecture in an organization.

What are the different types of web services?

Web services are usually classified based on the data exchange format. There are two popular styles of web services.

  • SOAP Web Services : All web services using SOAP format (we will discuss this in detail later) are called SOAP web services.
  • RESTful Web Services : All web services satisfying the Rest Architectural Constraints (we will discuss this in detail too) are called RESTful Web Services.

What are SOAP Web Services?

“SOAP

In SOAP web services, data exchange (request and responses) happens using SOAP format. SOAP is based on XML.

SOAP format defines a SOAP-Envelope which envelopes the entire document. SOAP-Header (optional) contains any information needed to identify the request. Also, part of the Header is authentication, authorization information (signatures, encrypted information etc). SOAP-Body contains the real xml content of request or response.

All the SOAP web services use this format for exchanging requests and responses. In case of error response, server responds back with SOAP-Fault.

What is a WSDL?

WSDL defines the format for a SOAP Message exchange between the Server (Service Provider) and the Client (Service Consumer).

A WSDL defines the following

  • What are the different services (operations) exposed by the server?
  • How can a service (operation) be called? What url to use? (also called End Point).
  • What should the structure of request xml?
  • What should be the structure of response xml?

What is marshalling and unmarshalling? How do JAXB and XMLBeans help with this?

Web sevices interview questions - marshalling and unmarshalling

SOAP web services use SOAP based XML format for communication. Java applications work with beans i.e. java objects. For an application to expose or consume SOAP web services, we need two things

  • Convert Java object to SOAP xml. This is called Marshalling.
  • Convert SOAP xml to Java object. This is called Unmarshalling.

JAXB and XMLBeans are frameworks which enable use to do marshalling and unmarshalling easily.

What are the java frameworks that you can use to build web services?

One frequently used framework is Spring Web Services (also called Spring WS).

With Java EE 6 and Java EE 7, there is little need for using an external framework, as lot of web service needs are built into them. So, it is a difficult choice to make.

How do you handle security for Web Services?

Security for web services has to be handled at two levels : Transport level and Application level.

  • At transport level, SSL is used to exchange certificates (HTTPS). This ensures that the server (service producer) and client (service consumer) are mutually authenticated. It is possible to use one way SSL authentication as well.
  • At the application level, security is implemented by transferring encrypted information (digital signatures, for example) in the message header (SOAP Header). This helps the server to authenticate the client and be confident that the message has not been tampered with.

What are the popular Java Specifications for Web services?

Popular java specifications for SOAP web services is JAX-WS. Rest Web service Specifications are JAX-RS.

What is Service Oriented Architecture (SOA)?

“Service

Service Oriented is an architectural style where applications are built on top of language neutral, loosely coupled, independent, reusable components.

Major components of SOA are

  • User Interface Layer : User Interface for web/desktop applications.
  • Business Process Layer : This represents the layer where the use cases are choreographed on top of the Services.
  • Services – Services and components used to build the services, such as various frameworks

All important questions regarding Restful web services are covered in this Restful Web Services article.

If you loved these Questions, you will love our PDF Interview Guide with 400+ Questions.
Download it now!.

400+ Interview Questions in 4 Categories:
  1. Java : Core Java, Advanced Java, Generics, Exception Handling, Serialization, Threads, Synchronization, Java New Features
  2. Frameworks : Spring, Spring MVC, Struts, Hibernate
  3. Design : Design, Design Patterns, Code Review
  4. Architecture : Architecture, Performance & Load Testing, Web Services, REST Web Services,Security, Continuous Integration