Google

Feb 10, 2012

Java Web Services Interview Questions and Answers: Overview

Q. What are the different application integration styles?
A. There are a number of different integration styles like

1. Shared database
2. batch file transfer
3. Invoking remote procedures (RPC)
4. Exchanging asynchronous messages over a message oriented middle-ware (MOM).


Q. How does a Java EE application integrates with other systems?
A. Using various protocols like HTTP(S), SOAP, RMI, FTP, proprietary, etc.

 

Q. What are the different styles of Web Services used for application integration?
A. SOAP WS and RESTful Web Service

Q. What are the differences between both SOAP WS and RESTful WS? 
A. 
  • The SOAP WS supports both remote procedure call (i.e. RPC) and message oriented middle-ware (MOM) integration styles. The Restful Web Service supports only RPC integration style.
  • The SOAP WS is transport protocol neutral. Supports multiple protocols like HTTP(S),  Messaging, TCP, UDP SMTP, etc. The REST is transport protocol specific. Supports only HTTP or HTTPS protocols.
  • The SOAP WS permits only XML data format.You define operations, which tunnels through the POST. The focus is on accessing the named operations and exposing the application logic as a service. The REST permits multiple data formats like XML, JSON data, text, HTML, etc. Any browser can be used because the REST approach uses the standard GET, PUT, POST, and DELETE Web operations. The focus is on accessing the named resources and exposing the data as a service. REST has AJAX support. It can use the XMLHttpRequest object. Good for stateless CRUD (Create, Read, Update, and Delete) operations.

             GET - read()
             POST - create()
             PUT - update()
             DELETE - delete()
  • SOAP based reads cannot be cached. REST based reads can be cached. Performs and scales better.
  • SOAP WS supports both SSL security and WS-security, which adds some enterprise security features like maintaining security right up to the point where it is needed, maintaining identities through intermediaries and not just point to point SSL only, securing different parts of the message with different security algorithms, etc. The REST supports only point-to-point SSL security. The SSL encrypts the whole message, whether all of it is sensitive or not.
  • The SOAP 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. The 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.
  • The 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.


  • Q. How would you decide what style of Web Service to use? SOAP WS or REST?
    A. 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.

    • Does the service expose data or business logic? (REST is a better choice for exposing data, SOAP WS might be a better choice for logic).
    • Do the consumers and the service providers require a formal contract? (SOAP has a formal contract via WSDL)
    • Do we need to support multiple data formats?
    • Do we need to make AJAX calls? (REST can use the XMLHttpRequest)
    • Is the call synchronous or  asynchronous?
    • Is the call stateful or stateless? (REST is suited for statless CRUD operations)
    • What level of security is required? (SOAP WS has better support for security)
    • What level of transaction support is required? (SOAP WS has better support for transaction management)
    • Do we have limited band width? (SOAP is more verbose)
    • What’s best for the developers who will build clients for the service? (REST is easier to implement, test, and maintain)


    Q. What tools do you use to test your Web Services?
    A. SoapUI tool for SOAP WS and the Firefox "poster" plugin for RESTFul services.


    Q. What is the difference between SOA and a Web service?
    A.

    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.



    Q. Why not favor traditional style middle-ware such as RPC, CORBA, RMI and DCOM as opposed to Web services?
    A.

    The traditional middle-wares tightly couple connections to the applications and it can break if you make any modification to your application. Tightly coupled applications are hard to maintain and less reusable. Generally do not support heterogeneity. Do not work across Internet. 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 messages to each other via a Web API. Do work across internet, less expensive and easier to use.

    Q. What are the different approaches to developing a SOAP based Web service?
    A. 2 approaches.

    • The contract-first approach, where you define the contract first with XSD and WSDL and the generate the Java classes from the contract.
    • The contract-last approach where you  define the Java classes first and then generate the contract, which is the  WSDL file from the Java classes.

    Note: The WSDL describes all operations that the service provides, locations of the endpoints (i.e.e where the services can be invoked), and simple and complex elements that can be passed in requests and responses.

    Q. What are the pros and cons of each approach, and which approach would you prefer?

    A.

    Contract-first Web service


    PROS:

    • Clients are decoupled from the server, hence the implementation logic can be revised on the server without affecting the clients.
    • Developers can work simultaneously on client and server side based on the contract both agreed on.
    • You have full control over how the request and response messages are constructed -- for example, should "status" go as an element or as an attribute? The contract clearly defines it. You can change OXM (i.e. Object to XML Mapping) libraries without having to worry if the "status" would be generated as "attribute" instead of an element. Potentially, even Web service frameworks and tool kits can be changed as well from say Apache Axis to Apache CXF, etc
     
    CONS:

    • More upfront work is involved in setting up the XSDs and WSDLs. There are tools like XML Spy, Oxygen XML, etc to make things easier. The object models need to be written as well.
       
    • Developers need to learn XSDs and WSDLs in addition to just knowing Java.

     
    Contract-last Web service
     
    PROS:
    • Developers don't have to learn anything related to XSDs, WSDLs, and SOAP. The services are created quickly by exposing the existing service logic with frameworks/tool sets. For example, via IDE based wizards, etc.
        
    • The learning curve and development time can be smaller compared to the Contract-first Web service.
     
    CONS:
    •  The development time can be shorter to initially develop it, but what about the on going maintenance and extension time if the contract changes or new elements need to be added? In this approach, since the clients and servers are more tightly coupled, the future changes may break the client contract and affect all clients or require the services to be properly versioned and managed.
    •  In this approach, The XML payloads cannot be controlled. This means changing your OXM libraries could cause something that used to be an element to become an attribute with the change of the OXM.


    So, which approach will you choose?

    The best practice is to use "contract-first", and here is the link that explains this much better with examples -->  contract-first versus contract-last web services In a nutshell, the contract-last is more fragile than the "contract-first".  You will have to decide what is most appropriate based on your requirements, tool sets you use, etc.
     



    Note: More Java Web Services interview questions and answers including WSDL, SOAP, UDDI, JAXR, SAAJ, etc are covered in Java/J2EE Job Interview Companion with diagrams.


    More Web services Interview Questions and Answers

    Java Web Services Interview Questions and Answers: RESTful Web services
    Java Web Services Interview Questions and Answers: SOAP clients
    SOAP versus RESTful Web service -- comparison
    RESTFul Web Service URI conventions with Spring MVC examples

Labels:

45 Comments:

Blogger Renish Shah said...

"SOAP WS wupports both SSL security and WS-security" ,Nice article..but replace W with S in this statement.

6:07 AM, March 16, 2012  
Blogger Unknown said...

Fixed. Thanks for spotting the mistake.

9:35 AM, March 16, 2012  
Blogger phani said...

Hi,

Very nice one i ever found. BTW, I bought the eBook with 400 Q/A, but do not have latest after 2007. How can i get the update version of it?Thanks.
Phani.

5:03 PM, May 05, 2012  
Blogger Unknown said...

Hi Phani,

I didn't have a chance to update it yet. I have updated some topics via this blog. Also, the core java career essentials has up to date info on core Java.

1:10 PM, May 06, 2012  
Anonymous Anonymous said...

Arulkumaran Kumaraswamipillai
I read your book
Thank you very much!
You've covered almost everything

4:46 PM, June 02, 2012  
Anonymous Mohan said...

Contract last is top down or bottom up approach?

8:54 PM, June 09, 2012  
Blogger Unknown said...

The contract last is a bottom-up approach. The contract first or WSDL first is a top down approach

2:11 PM, June 10, 2012  
Blogger Unknown said...

nice collection..wwwinterviewdotcom

3:08 PM, July 08, 2012  
Anonymous kk said...

gr8

1:54 AM, July 23, 2012  
Blogger Thiru Vaka said...

Hi,

I read your book, its too good and covered much about web services.

6:06 PM, July 25, 2012  
Blogger Dhung said...

really awsum post....... well "http://www.dhung.com/job-interview-questions-answers/java-developer" is also provide question for java..................

5:34 PM, July 26, 2012  
Blogger kumar said...

we had developed a 10 services in server side production development services and we have to provide 5 services to the client while what should we do in how to prevent the remaing 5 services in server side

12:46 PM, August 15, 2012  
Blogger Unknown said...

You need to elaborate a bit more on your question. Not clear as to what you are trying to do.

1:34 PM, August 15, 2012  
Blogger Unknown said...

Good information webservices

8:47 PM, August 23, 2012  
Blogger durga said...



Thanks for sharing, I will bookmark and be back again








Anesthesia Billing Services

9:16 PM, August 29, 2012  
Anonymous Navneet Arora said...

Very Nicely explained the core parts, differences and uses. Thanks a lot for sharing these details.

1:49 PM, September 04, 2012  
Anonymous Anonymous said...

Looks like already corrected. By the way seems REST is getting more and more popular, at least I can say in interview. Its good to prepare few REST Web Service interview questions as well.

2:27 PM, September 20, 2012  
Anonymous Anonymous said...

hi

2:56 PM, September 22, 2012  
Anonymous Anonymous said...

Very Nicely explained webservice

2:17 PM, October 03, 2012  
Blogger indigitalmind said...

its very good explanation of web services concepts mainly RESTful vs SOAP bases webservice

3:59 AM, October 14, 2012  
Blogger Unknown said...

Web Designing

i Really bookmark reader great post wow ...

5:16 PM, October 25, 2012  
Anonymous Anonymous said...

hi Arulkumaran,
i need your help.
am sending request thru SOAP to another application.
they are getting my request. but when they are sending response its throwing following errors on their side.
on my side only we have changed something..but their side they didnt do any changes frm long tym.
Can you tell me what could be the problem?
[WebContainer : 8] ERROR com.sbc.embus.adapter.soap.http.SoapAdapterServlet - SoapAdapterServlet encountered java.lang.ClassCastException while dispatching response
java.lang.ClassCastException: progress.message.jimpl.Message incompatible with javax.jms.TextMessage
at com.sbc.embus.adapter.soap.http.SoapAdapterServlet.doPost
[WebContainer : 8] DEBUG com.sbc.embus.jxservice.dispatcher.util.Log4JLoggingHandler - PROPERTY embusErrorCode=500
Thanks in advance

6:07 AM, October 28, 2012  
Anonymous Anonymous said...

The first question itself is very good.

6:12 AM, November 13, 2012  
Anonymous Anonymous said...

nice artical

5:37 AM, January 28, 2013  
Anonymous Anonymous said...

I read your Books. Your way of explaining things is pretty good.

12:17 AM, February 08, 2013  
Anonymous Anonymous said...

Very nice artical

9:43 PM, February 19, 2013  
Blogger Unknown said...

Hi I have bought your ebook. Wondering if you have updated book after 2007. I was looking for updated Spring,Web Service and java concurrency 1.5 and JSF questions. If I buy your 2009 version would i be able to get updated resources including stuff covered in this article? Thanks in advance.

12:01 AM, March 16, 2013  
Blogger Unknown said...

No, I am currently working on it. Stay tuned.

10:34 PM, March 16, 2013  
Blogger Unknown said...

This all updates are really useful for java web developers and also helpful for who are prepare to interview for Java based.
Web Developer in Bangalore

5:55 PM, June 18, 2013  
Blogger Akash said...

All questions are helpful for when you go for the Interview.
java interview questions

1:24 AM, June 28, 2013  
Anonymous web designing companies said...

There are so many different styles to understand the concepts of Java web developing services.This is such a Great resource that you are providing. It gives in depth information. Thanks for this valuable information.

10:08 PM, July 11, 2013  
Anonymous Anonymous said...

It depends where are you going for interview...

6:17 PM, July 16, 2013  
Blogger javatreasury said...

Already we have Apache HTTPS. Then why we are going for web services?

9:54 PM, July 20, 2013  
Blogger Vaasu said...

First of thanks for this nice blog. But I did't get in what context you have written "REST has AJAX support" . Do you means calling REST web service through AJAX. If so then, as per my knowledge It is possible to call SOAP web service through AJAX. Could you please clarify this.

4:27 AM, August 23, 2013  
Anonymous Anonymous said...

its, bottom up approach. First java classes and then WSDL.

6:10 PM, September 25, 2013  
Anonymous Anonymous said...

Best explanations I have ever come across. Thanks for the post.

1:26 AM, October 15, 2013  
Anonymous Anonymous said...

By far one of the best answer for the soap vs rest. I always stutter in an interview for thsi question, this gave me better insight of what it is. Thanks.

7:04 AM, January 29, 2014  
Blogger Unknown said...

Thanks for posting this questions.... Web Designing India

4:32 PM, March 01, 2014  
Anonymous Anonymous said...

Hi ,
About this sentence:

"The SOAP WS supports both remote procedure call (i.e. RPC) and message oriented middle-ware (MOM) integration styles. The Restful Web Service supports only RPC integration style. "

when we use web service with MOM (as transport layer) , the message will always contain a procedure to call , so it use RPC. So MOM and RPC are used together ?

2:16 AM, April 04, 2014  
Blogger Sreenath Reddy said...

Check for more java interview questions @http://skillgun.com/

10:42 PM, April 22, 2014  
Anonymous Anonymous said...

It is great post.This blog provides the important java questions which is useful in the interview.The interested freshers can use this blog...
Tutorial In Noida

8:25 PM, April 28, 2014  
Anonymous Govardhan said...

very nice article..

2:01 PM, June 24, 2014  
Blogger Unknown said...

Thanks

2:48 PM, July 31, 2014  
Blogger Unknown said...

thank u for gining information sir..... i am waiting for ur next updates...

web-designing-training-institute-in-chennai

3:04 PM, August 14, 2014  
Anonymous Anonymous said...

Arulkumaran

When do you see the book getting updated. I also bought a copy back in 2007.

thanks
Sid

4:56 AM, October 15, 2014  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home