6 must know Java Web Services Interview Q&As

Q1. What are the different styles of Web Services used for application integration? and What are the differences between both approaches?
A1. SOAP WS and RESTful Web Service. Web services are very popular and widely used to integrate similar (i.e. Java applications) and disparate systems (i.e. legacy applications and applications written in .Net etc) as they are language neutral, which means a Web service client written in Java can consume a web service written in .Net and vice versa.

Java Web Service styles comparison

Java Web Service styles comparison

SOAP vs. REST comparison

SOAP Web serviceRESTful Web service
SOAP (i.e. Simple Object Access Protocol) is a standard communication protocol on top of transport protocols such as HTTP, SMTP, Messaging, TCP, UDP, etc.REST is an architectural style by which data can be transmitted over transport protocol such as HTTP(S).

Each unique URL is a some representation of a resource (i.e an object like Account, Customer, etc), and you can get the contents of the resources (i.e objects) via HTTP verbGET” and to modify the resources via “POST“, “PUT” or “DELETE“.

SOAP Layers

SOAP Layers

REST Layers

REST Layers

SOAP uses its own protocol and focuses on exposing pieces of application logic (not data) as services. SOAP exposes operations. SOAP is focused on accessing named operations, which implement some business logic through different interfaces.REST is about exposing a public API over the internet to handle CRUD (Create, Read, Update, and Delete) operations on data. REST is focused on accessing named resources through a single consistent interface.
SOAP only permits XML data formats.



REST permits many different data formats like XML, JSON data, text, HTML, atom, RSS, etc. JSON is less verbose than XML and is a better fit for data and parses much faster.

URL: http://localhost:8080/myapp/createEmptyCase

REST content

REST content XML, JSON, RSS, etc

SOAP based reads cannot be cached. The application that uses SOAP needs to provide cacheing.REST based reads can be cached. Performs and scales better.
Supports both SSL security and WS-security, which adds some enterprise security features. Supports identity through intermediaries, not just point to point SSL.

— WS-Security maintains its encryption right up to the point where the request is being processed.

— WS-Security allows you to secure parts (e.g. only credit card details) of the message that needs to be secured. Given that encryption/decryption is not a cheap operation, this can be a performance boost for larger messages.

— It is also possible with WS-Security to secure different parts of the message using different keys or encryption algorithms. This allows separate parts of the message to be read by different people without exposing other, unneeded information.

— SSL security can only be used with HTTP. WS-Security can be used with other protocols like UDP, SMTP, etc.

Supports only point-to-point SSL security.

— The basic mechanism behind SSL is that the client encrypts all of the requests based on a key retrieved from a third party. When the request is received at the destination, it is decrypted and presented to the service. This means the request is only encrypted while it is traveling between the client and the server. Once it hits the server (or a proxy which has a valid certificate), it is decrypted from that moment on.

— The SSL encrypts the whole message, whether all of it is sensitive or not.

Has comprehensive support for both ACID based transaction management for short-lived transactions and compensation based transaction management for long-running transactions. It also supports two-phase commit across distributed resources.REST supports transactions, but it is neither ACID compliant nor can provide two phase commit across distributed transactional resources as it is limited by its HTTP protocol.
SOAP has success or retry logic built in and provides end-to-end reliability even through SOAP intermediaries.REST does not have a standard messaging system, and expects clients invoking the service to deal with communication failures by retrying.
Time to market is slowTime to market is fast
JavaScript support difficultJavaScript support easy
Supports stateless & stateful operationsEmphasises on stateless operations

Which one to favor? In general, a REST based web service is preferred due to its simplicity, performance, scalability, and support for multiple data formats. SOAP is favoured where service requires comprehensive support for security and transactional reliability.

Who uses SOAP WS? Financial, Payment Gateways, Telecommunication, etc.

Q2. Differentiate between SOA (Service Oriented Architecture) versus WOA (Web Oriented Architecture)?
A2. Web Oriented Architecture (WOA) is an architectural style that is designed to be used for web based applications. Mobile APIs are more focused in using WOA technology. WOA builds on service-oriented architecture (SOA) by adding support for Web-based software application and services. The key difference between SOA and WOA is the use of REST APIs by WOA instead of SOAP by SOA.

Java Web Services

WOA – RESTFul Service Calls via AJAX to populate different sections of a UI

Q3. How would you decide what style of Web Service to use? SOAP WS or REST?
A3. In general, a REST based Web service is preferred due to its simplicity, performance, scalability, and support for multiple data formats. SOAP is favored where service requires comprehensive support for security and transactional reliability.

The answer really depends on the functional and non-functional requirements. Asking the questions listed below will help you choose.

1) Does the service expose data or business logic? (REST is a better choice for exposing data, SOAP WS might be a better choice for exposing business logic).

2) Do consumers and the service providers require a formal contract? (SOAP has a formal contract via WSDL)

3) Do we need to support multiple data formats?

4) Do we need to make AJAX calls? (REST can use the XMLHttpRequest)

5) Is the call synchronous or asynchronous? (SOAP supports Asynchronous messaging)

6) Is the call stateful or stateless? (REST is suited for statless CRUD operations)

7) What level of security is required? (SOAP WS has better support for security)

8) What level of transaction support is required? (SOAP WS has better support for transaction management)

9) Do we have limited band width? (SOAP is more verbose)

10) What’s best for the developers who will build clients for the service? (REST is easier to implement, test, and maintain)

Q4. What tools do you use to test your Web Services?
A4. SoapUI tool for SOAP WS & RESTFul web service testing and on the browser the Firefox “poster” plugin or Google Chrome “Postman” extension for RESTFul services.

Q5. Why not favor traditional style middle-ware such as RPC, CORBA, RMI and DCOM as opposed to Web services?
A5. The traditional middle-wares tightly couple connections to the applications. Tightly coupled applications are hard to maintain and less reusable. Generally do not support heterogeneity. Do not work across Internet and can be more expensive and hard to use.

Web Services support loosely coupled connections. The interface of the Web service provides a layer of abstraction between the client and the server. The loosely coupled applications reduce the cost of maintenance and increases re-usability. Web Services present a new form of middle-ware based on XML and Web. Web services are language and platform independent. You can develop a Web service using any language and deploy it on to any platform, from small device to the largest supercomputer. Web service uses language neutral protocols such as HTTP and communicates between disparate applications by passing XML or JSON messages to each other via a Web API. Do work across internet, less expensive and easier to use.

Q6. What is the difference between SOA and a Web service?
A6. SOA is a software design principle and an architectural pattern for implementing loosely coupled, reusable and coarse grained services. You can implement SOA using any protocols such as HTTP, HTTPS, JMS, SMTP, RMI, IIOP (i.e. EJB uses IIOP), RPC etc. Messages can be in XML or Data Transfer Objects (DTOs).

Web service is an implementation technology and one of the ways to implement SOA. You can build SOA based applications without using Web services – for example by using other traditional technologies like Java RMI, EJB, JMS based messaging, etc. But what Web services offer is the standards based and platform-independent service via HTTP, XML, SOAP, WSDL and UDDI, thus allowing interoperability between heterogeneous technologies such as J2EE and .NET.

300+ Enterprise Java Interview Q&As
Module 1Describe the recent Java application that you had worked on from a 100 feet?+
Unit 112 High-level JEE architecture overviews at 100 feet with diagrams
Unit 2Describe a typical Java EE architecture?
Unit 311 JEE application integration styles with diagrams
Module 2JEE Overview+
Unit 110 JEE overview interview Q&As
Unit 24 JEE bean validation, asynchronous processing & web fragments interview Q&As
Module 3Web Basics+
Unit 14 Http methods, content types, headers, MIME types, cookies, etc Q&As
Unit 212 Web development basics interview Q&AS
Unit 38 Web development design patterns interview Q&As
Module 4Java Servlets+
Unit 121 Java servlet interview Q&As
Unit 25 web.xml, ServletConfig, and ServletContext interview Q&As
Module 5View Technologies in Java Web applications+
Unit 1Client-side vs server side view technologies interview Q&As
Unit 213 AngularJs interview Q&As
Unit 37 JSP interview Q&As
Unit 49 JSF interview Q&As
Module 6Java Web Services-
Unit 16 must know Java Web Services Interview Q&As  - Preview
Unit 26 Micro & web services interview Q&As
Unit 36 RESTful web services interview Q&As
Unit 4JAX-RS how to create a RESTFul Web Service in Java?
Unit 55 JAXB interview Questions & Answers
Unit 6RESTful interview question on 12 rules to remember
Unit 7REST constraints (i.e. design rules) interview Q&As
Unit 8HATEOAS question on RESTful web service
Unit 9HATEOAS RESTFul Service with Spring tutorial
Unit 1011 SOAP web services interview Q&As
Unit 11SOAP Web Service Styles Interview Q&As
Module 7Java and Spring Microservices+
Unit 110+ Domain Driven Design (i.e. DDD) Interview Q&As
Unit 210+ Key Microservices Interview Questions Answered
Unit 37 Apache Kafka interview Q&As
Unit 4DevOps, Kubernetes, Docker & Microservices Q&As
Module 8Spring Core+
Unit 19 Spring framework overview interview Q&As
Unit 2DIP, DI, Spring IoC and loose coupling in detail Q&As
Unit 34 Spring bean lifecycle interview Q&As
Unit 417 Spring bean scopes interview Q&As
Module 9Spring MVC and Spring Boot+
Unit 111 Spring MVC interview Q&As
Unit 215 Spring boot Interview Q&As
Unit 3Spring Cloud Microservices interview Q&As
Module 10JPA and Hibernate+
Unit 18 JPA interview Q&As
Unit 28 Hibernate basics interview Q&As
Unit 38 Hibernate object states, lazy loading & optimistic locking Q&As
Module 11JDBC, Transaction Management & JTA+
Unit 15 JDBC overview interview Q&As
Unit 212 JDBC basics interview Q&As
Unit 39 Java Transaction Management interview Q&As
Unit 48 JTA interview Q&As
Module 12JMS, JNDI, and JMX+
Unit 116 JMS interview Q&As
Unit 29 JNDI & LDAP interview Q&As
Unit 35 JMX and MBean interview Q&As
Module 13Database & SQL+
Unit 115 Database interview Q&As
Unit 215 SQL interview Q&As
Unit 33 SQL subqueries interview Q&As
Module 14Unix & Regex+
Unit 114 Unix interview Q&As
Unit 2Power of regex for string manipulation
Unit 39 Regular expressions (aka regex) in Java interview Q&As
Module 15JSON, XML & XSD+
Unit 117 XML interview Q&As
Unit 211 XSD interview Q&As
Unit 37 Processing XML in Java interview Q&As
Unit 45 JAXB interview Q&As
Unit 56 JSON interview Q&As
Unit 6Processing JSON in Java
Module 16UML & ERD+
Unit 112 UML interview Q&As
Unit 210 ERD (i.e. Entity-Relationship Diagrams) interview Q&As
Module 17Maven & Git+
Unit 112 Maven build tool interview Q&As
Unit 27 Maven, Nexus, and other build tools Q&As
Unit 38 Git Source control system interview Q&As
Unit 46 Git Q&As on pull requests, rebasing, merging, etc
Module 18JavaScript+
Unit 13 Java Vs. JavaScript interview Q&As
Unit 210 JavaScript Interview Q&As on variable scopes & context
Unit 310 JavaScript interview Q&As on functions, prototypes, “this” variable, binding, etc
Unit 410 JavaScript interview Q&As on functions
Unit 57 JavaScript interview Q&As on closures
Module 19SDLC+
Unit 15 SDLC interview Q&As for Java developers
Unit 218 Agile development methodology interview Q&As
Unit 330+ SDLC activities performed by developers
Module 20Enterprise Code Quality+
Unit 13 Ensuring code quality in Java applications Q&As
Unit 26 Unit testing Spring boot applications Q&As
Unit 34 Q&As on unit testing the DAO layer
Unit 4Unit testing Spring controller
Unit 5BDD development in Java
Module 21Judging Experience+
Unit 13 How would you go about ..." Q&As to judge experience
Unit 211 In your Java experience, what are ... Q&As
Unit 37 Interview Q&As on debugging skills
Unit 418 Java scenarios based interview Q&As
Unit 59 SQL scenarios Q&As judge experience
Unit 6How would you go about designing Java apps with UML diagrams?