As an enterprise Java developer, you will be spending more time integrating systems via Java web services & messaging. Java Web Services interview questions are must know for the Java developers.
Q1. What are the different styles of Web Services used for application integration? and What are the differences between both approaches?
A1. Web services are very popular and widely used to integrate similar (i.e. written in Java) 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.
SOAP vs. RESTful web services comparison
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.
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 relevant questions listed below will help you choose.
1) Does the service expose data or business logic? RESTful Web Service is a better choice for exposing data, SOAP Web Service might be a better choice for exposing business logic.
2) Do consumers and the service providers require a formal contract? SOAP Web Service has a formal contract via WSDL. REST is an architectural style, and not a messaging API like SOAP. RESTful service must provide extensive text description and example code. REST can use tools like OpenAPI (i.e used to be Swagger) to generate the docs for our RESTful API. OpenAPI also allows you to execute each operation on the interface.
3) Do you need to support multiple data formats? E.G. JSON, XML, Text, atom, RSS, etc. REST permits many different data formats.
5) Is the call synchronous or asynchronous? Synchronous means that you call a web service and all other code execution and user interaction is stopped until the call returns. Asynchronous means that you do not halt all other operations while waiting for the web service call to return
SOAP services based on specified interaction patterns can be generated synchronously, asynchronously, or both synchronously and asynchronously to meet your business needs. REST services can be generated with synchronous operation only as it is nothing but an HTTP call. REST services has not nothing to do with being Synchronous or asynchronous, but clients calling can support asynchronous to achieve it like AJAX in browser. In a server side you can have a multi-threaded environment & non-blocking I/O to achieve asynchronous REST service.
6) Is the call stateful or stateless? REST is suited for stateless CRUD operations. It is also a best practice to favor stateless over stateful. “12 Rules” for REST API design & development.
7) What level of security is required? SOAP WS has better support for security. RESTful supports only point-to-point SSL security. SOAP supports both SSL security and WS-security, which adds enterprise security features like identity through intermediaries, and not just point to point SSL.
8) What level of transaction support is required? SOAP WS has better support for transaction management. 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.
9) Do you 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 style 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.
Q7. What is the difference between SOA and Micro Services?