In this article we are going to discuss about the frequently asked Java Web services interview questions and answers.

What are web services?

Web service, web service – a software system identified by a web address with standardized interfaces. Web services can interact with each other and with third-party applications through messages based on certain protocols (SOAP, XML, REST, etc.). The Web service is a unit of modularity when using a service-oriented application architecture. The characteristics of web services include:

  • Interoperability
  • Expandability
  • Ability to machine description processing

What is the difference between SOA and web service?

Service-oriented architecture (SOA) is a modular approach to software development based on the use of distributed, loose coupling replaceable components equipped with standardized interfaces for interaction on standardized protocols.

Software packages developed following the service-oriented architecture are usually implemented as a set of web services interacting over the SOAP protocol,

but there are other implementations (for example, based on Jini, CORBA, based on REST). Web services implementing this concept use XML, JSON, etc., as well as Internet protocols like HTTP (S), SMTP, etc.

What is SOAP?

SOAP (from English Simple Object Access Protocol – a simple protocol to access objects, up to specification 1.2) – the protocol for exchanging structured messages in a distributed computing environment. Initially, SOAP was intended primarily for the implementation of remote procedure calls (RPCs).

Now the protocol is used to exchange random messages in XML format, and not just for calling procedures. The official specification of the latest version 1.2 of the protocol does not decrypt the name SOAP. SOAP is an extension of the XML-RPC protocol.

SOAP can be used with any application layer protocol: SMTP, FTP, HTTP, HTTPS, etc. However, its interaction with each of these protocols has its own characteristics, which must be defined separately. Most often, SOAP is used over HTTP.

What is REST?

REST (abbreviated to English Representational State Transfer) is the architectural style of the interaction of components of a distributed application on a network.

REST is an agreed set of constraints that are taken into account when designing a distributed hypermedia system. In some cases (online shopping, search engines, other data-based systems) this leads to increased productivity and simplified architecture. In a broad sense, components in REST interact like the interaction of clients and servers on the World Wide Web. REST is an alternative to RPC.

On the Internet, calling a remote procedure can be a standard HTTP request (usually GET or POST, which is called a REST request), and the required data is passed as query parameters. For web services built with REST in mind, that is, without violating the restrictions imposed by it, the term “RESTful” is used.

What is the difference between REST and SOAP web services?

REST supports various formats: text, JSON, XML; Where SOAP is only XML,

REST works only over HTTP (S), and SOAP can work with different protocols,

REST can work with resources. Each URL is a representation of a resource. SOAP works with operations that implement any business logic using several interfaces.

Whereas;

SOAP on the basis of reading cannot be placed in the cache, and REST, in this case, can be cached,

SOAP supports SSL and WS-security, while REST only supports SSL,

SOAP supports ACID (Atomicity, Consistency, Isolation, Durability). REST supports transactions, but none of the ACIDs is compatible with the two-phase commits.

How would you decide which of the REST or SOAP web services to use?

REST versus SOAP can be paraphrased as “Simplicity vs. Standard”. In the case of REST (simplicity), you will have speed, expandability, and support for many formats. In the case of SOAP, you will have more security capabilities (WS-security) and transactional security (ACID).

What is JAX-WS?

Java API for XML Web Services (JAX-WS) is the Java application programming interface for creating Web services that are part of the Java EE platform. JAX-WS is a replacement for JAX-RPC technology, providing a more document-oriented messaging model and simplifying the development of [1] web services by using annotations first introduced in Java SE 5. JAX-WS is a standard and is described in JSR 224. Some advantages:

  • Using annotations eliminates the need to create Web service descriptors.
  • The endpoints declaration occurs directly in the Java classes.
  • Direct integration with JAXB 2.0.
  • Resource injection.
  • Support for MTOM.

The choice between two development paths: bottom-up (the programmer develops endpoint classes himself) and top-down (WSDL generates Java classes).

Tell us about JAXB.

Java Architecture for XML Binding (JAXB) allows Java developers to align Java classes and XML representations. JAXB provides two main features: serialization of Java objects in XML and vice versa, that is, deserialization from XML back to the Java object.

In other words, JAXB allows you to store and retrieve data in memory in an XML format, without having to perform a specific set of procedures for loading and saving XML. It is similar to xsd.exe and XmlSerializer in the .NET Framework.

JAXB is especially useful when the specification is complex and changing. In this case, permanent changes to the schema of XML definitions to synchronize them with Java definitions can take a long time and are prone to errors.

What is MTOM?

MTOM (Message Transmission Optimization Mechanism) – the use of message coding using the mechanism for optimizing the transmission of messages. E the mechanism of transfer of large attachments in binary format SOAP messaging protocol as the raw bytes that are permitted for smaller messages.

What is XOP?

XOP (XML-binary Optimized Packaging) is a mechanism recommended by the W3C for embedding binary data into a set of XML Information Set (XML Information Set).

What do you know about encoding in SOAP (encoding)?

Coding SOAP is a method for structuring a query that is proposed within the SOAP specification, known as SOAP serialization.

What defines the encoding Style attribute in SOAP?

SOAP encoding Style defines the serialization rules used in the SOAP message. This attribute can appear on any element, and the scope of this attribute will extend to all child elements, even those that do not explicitly have this attribute. For default SOAP messages, the encoding is undefined.

What are the two final types of web services using JAX-WS?

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

What are the rules for encoding a header entry?

The header must be identified by using a full name that contains the namespace of the URI and the local name. All immediate child elements of the SOAP header must be specified in the namespace.

The SOAP encodingStyle attribute must be used to define the style of the header encoding.

What do you know about the wsimport tool?

The wsimport tool is used to parse existing Web Services Description Language (WSDL file) and generate the required files (JAX-WS portable artefacts) for the web service client to access the published Web service.

Close

About The Author

Ruchi Singla
An enthusiast writer with years of experience, who loves to create beautiful thoughts into words. She writes with a zeal and enjoys reading vogue with a good cup of coffee when not writing. Ruchi is working as a content writer for many businesses, helping them gain an extra edge over their competitors. As a content writer, she is responsible for enhancing engagement and traffic on the blog by brainstorming exciting content ideas.

This site uses Akismet to reduce spam. Learn how your comment data is processed.