35 Java Web Services Interview Questions And Answers

35 Java Web Services Interview Questions And Answers For Experienced from Codingcompiler. Test your Java web services knowledge by answering these tricky interview questions on Java web services. Let’s start learning Java web services interview questions and prepare for web services interviews. All the best for your future and happy learning.

Table of Contents

Java Web Services Interview Questions

  1. What are web services?
  2. What is the difference between SOA and web service?
  3. What is SOAP?
  4. What is REST?
  5. What is the difference between REST and SOAP web services?
  6. How would you decide which of the REST or SOAP web services to use?
  7. Explain the concept of WSDL.
  8. What is JAX-WS?
  9. Tell us about JAXB.
  10. Can we send soap messages with an attachment?
  11. What is MTOM?
  12. What is XOP?
  13. Explain the SOAP envelope element.
  14. How is the SOAP namespace defined?
  15. What do you know about encoding in SOAP (encoding)?
  16. What defines the encodingStyle attribute in SOAP?
  17. What are the two final types of web services using JAX-WS?
  18. What are the rules for coding a header record?
  19. What do you know about the wsimport tool?
  20. What do you know about the wsgen tool?
  21. What are some differences between SOAP and other remote access techniques?
  22. What is a resource in REST?
  23. What HTTP methods are supported in REST?
  24. When can I use a GET request instead of a POST to create a resource?
  25. What is the difference between GET and POST requests?
  26. What does WADL mean?
  27. What frameworks do you know that implement REST web services?
  28. What is the difference between AJAX and REST?
  29. What does the @Path annotation do?
  30. What does the @PathParam annotation do?
  31. What does the @QueryParam annotation do?
  32. What does the @MatrixParam annotation do?
  33. What does the @FormParam annotation do?
  34. What are the two ways to get the HTTP request header in JAX-RS do you know?
  35. How to download a file using JAX-RS?

Java Web Services Interview Questions And Answers

1. What are web services?

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

    • Interoperability
    • Extensibility
  • Description processing capability

2. What is the difference between SOA and web service?

Service-oriented architecture (SOA, service-oriented architecture) is a modular approach to software development based on the use of distributed, loosely coupled (eng. Loose coupling) replaceable components equipped with standardized interfaces for interoperability over standardized protocols.

Software systems developed in accordance with the service-oriented architecture are usually implemented as a set of web services that interact using the SOAP protocol, but there are other implementations (for example, based on jini, CORBA, based on REST). Web services that implement this concept use XML, JSON, etc., as well as Internet protocols like HTTP (S), SMTP, etc.

3. What is SOAP?

SOAP (from the English. Simple Object Access Protocol – a simple protocol for accessing objects; up to specification 1.2) is a protocol for exchanging structured messages in a distributed computing environment.

Initially, SOAP was intended primarily for the implementation of remote procedure call (RPC). Now the protocol is used to exchange arbitrary messages in XML format, and not just to call procedures. The official specification of the latest version 1.2 of the protocol does not decrypt the name of SOAP. SOAP is an extension of the XML-RPC protocol.

SOAP can be used with any application-level 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.

4. What is REST?

REST (abbreviated from English. Representational State Transfer – “transfer of presentation state”) is an architectural style of interaction between components of a distributed application in a network. REST is a consistent set of constraints taken into account when designing a distributed hypermedia system.

In certain cases (online stores, search engines, other data-based systems) this leads to increased productivity and simplified architecture. In a broad sense, components in REST interact in a manner similar to the interaction of clients and servers on the World Wide Web. REST is an alternative to RPC.

On the Internet, a remote procedure call can be a simple HTTP request (usually GET or POST; this request is called a REST request), and the necessary data is transmitted as request parameters. For web services based on REST, that is, not violating the restrictions imposed by them, the term “RESTful” is used.

5. What is the difference between REST and SOAP web services?

    • REST supports various formats: text, JSON, XML; SOAP – only XML,
    • REST only works over HTTP (S), and SOAP can work with various protocols,
    • REST can work with resources. Each URL is a representation of a resource. SOAP works with operations that implement some kind of business logic using several interfaces,
    • Read-based SOAP cannot be cached, and REST can be cached in this case,
    • SOAP supports SSL and WS-security, while REST only SSL,
  • SOAP supports ACID (Atomicity, Consistency, Isolation, Durability). REST supports transactions, but none of the ACIDs are compatible with two phase commits.

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

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

7. Explain the concept of WSDL.

WSDL (English Web Services Description Language) is an XML-based web services description and access language.

Each WSDL 1.1 document can be broken down into the following logical parts:

    • definition of data types (types) – definition of the type of XML messages sent and received by the service
    • data elements (message) – messages used by the web-service
    • abstract operations (portType) – a list of operations that can be performed with messages
  • service binding (binding) – the way the message will be delivered
1

2

3

4

5

6

7

8

9

10

11

12

13

14

<message name=”getTermRequest”>

  <part name=”term” type=”xs:string”/>

</message>

<message name=”getTermResponse”>

  <part name=”value” type=”xs:string”/>

</message>

<portType name=”glossaryTerms”>

 <operation name=”getTerm”>

     <input message=”getTermRequest”/>

     <output message=”getTermResponse”/>

 </operation>

</portType>

8. What is JAX-WS?

The Java API for XML Web Services (JAX-WS) is a Java-based application programming interface for creating web services that is part of the Java EE platform.

JAX-WS is a replacement for JAX-RPC technology, providing a more document-oriented message model and simplifying the development of [1] web services through the use of annotations that first appeared in Java SE 5. JAX-WS is a standard and is described in JSR 224. Some benefits:

    • Using annotations eliminates the need to create web services descriptors.
    • The endpoints are declared directly in Java classes.
    • Direct integration with JAXB 2.0.
    • Resource injection.
    • MTOM support.
  • Opportunity to choose between two development paths: bottom-up (the programmer develops endpoint-classes himself) and top-down (Java classes are generated by WSDL).

9. Tell us about JAXB.

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

In other words, JAXB allows you to store and retrieve data in memory in any XML format, without the need 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, constant changes to the schema of the XML definitions to synchronize them with the Java definitions can take a long time and can be error prone.

Web Services Java Interview Questions And Answers

10. Can we send soap messages with an attachment?

Yes it is possible. You can send attachments in various formats: PDF, images, or other binary data. SOAP messages work in conjunction with the MIME extension, which provides multipart / related:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

MIME-Version: 1.0

Content-Type: Multipart/Related; boundary=MIME_boundary; type=text/xml;

       start=”<claim061400a.xml@ javastudy.ru>”

Content-Description: This is the optional message description.

<?xml version=’1.0′ ?>

<SOAP-ENV:Envelope

xmlns:SOAP-ENV=”https://schemas.xmlsoap.org/soap/envelope/”>

<SOAP-ENV:Body>

..

<theSignedForm href=”cid:[email protected]”/>

..

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

–MIME_boundary

Content-Type: image/tiff

Content-Transfer-Encoding: binary

Content-ID: <[email protected]>

…binary TIFF image…

–MIME_boundary—

11. What is MTOM?

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

12. What is XOP?

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

13. Explain the SOAP envelope element.

The SOAP envelope element is the root element of the SOAP message and defines the XML document as a SOAP message.

1

2

3

4

5

6

7

8

<?xml version=”1.0″?>

<soap:Envelope

xmlns:soap=”https://www.w3.org/2001/12/soap-envelope”

soap:encodingStyle=”https://www.w3.org/2001/12/soap-encoding”>

 …

 Message information

 …

</soap:Envelope>

14. How is the SOAP namespace defined?

1 xmlns:soap=https://www.w3.org/2001/12/soap-envelope

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

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

16. What defines the encodingStyle attribute in SOAP?

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

1 SOAP-ENV:encodingStyle=”https://www.w3.org/2001/12/soap-encoding”

17. 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.

18. What are the rules for coding a header record?

    • the header must be identified using the full name, which contains the namespace URI and the local name. All immediate children of the SOAP header must be specified in the namespace,
    • The SOAP encodingStyle attribute should be used to specify the encoding style of the header,
  • the SOAP attribute mustUnderstand and the SOAP actor attribute should be used to specify how to process the record and by whom.

19. What do you know about the wsimport tool?

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

Web Services in Java Interview Questions And Answers

20. What do you know about the wsgen tool?

The wsgen tool is used to analyze the existing web service implementation class and creates the necessary files (JAX-WS portable artifacts) for deploying web services.

21. What are some differences between SOAP and other remote access techniques?

    • SOAP is easier to use because it’s not symmetrical like DCOM or COBRA,
    • SOAP is more platform and language independent than DCOM or CORBA,
    • SOAP uses HTTP as a transport protocol and data is stored in XML format that can be read by humans, whereas DCOM or CORBA have their own binary formats that are used to transport data in a complex way.
  • SOAP identifies an object other than the final URL. SOAP objects are independent and difficult to maintain. In the case of other methods of remote access, the work in this case may be easier.

22. What is a resource in REST?

This is a unique URL with an object representation that can be obtained using GET requests and modified using PUT, POST, DELETE.

23. What HTTP methods are supported in REST?

    • GET;
    • POST;
    • PUT;
    • DELETE;
    • OPTIONS;
  • HEAD.

24. When can I use a GET request instead of a POST to create a resource?

It is not possible to use the GET request to modify (create) a resource.

25. What is the difference between GET and POST requests?

GET sends data to the server using a URL, when POST sends data using an HTTP request body.

The length of the URL is limited to 1024 characters, this will be the upper limit for data that can be sent by GET.

POST can send much larger amounts of data. The limit is set by the web server and is usually around 2MB.

Data transfer using the POST method is more secure than using the GET method, since secret data (for example, a password) is not displayed directly in the user’s web client (unlike a URL that is almost always visible).

26. What does WADL mean?

Web Application Description Language (WADL) is a machine-readable XML description for HTTP web applications (typically, REST web services). Analog WSDL for SOAP.

WADL models the resources provided by the service and the relationships between them. WADL was proposed as a W3C standard by Sun Microsystems in August 2009, but the consortium has no plans for it and WADL has not yet received widespread use.

27. What frameworks do you know that implement REST web services?

There are many, here are some of them: Jersey, Restlet, EasyRest.

28. What is the difference between AJAX and REST?

    • In AJAX, a request is sent to the server using XMLHttpRequest objects. REST uses a URL structure and resource usage revolves around the request / response pattern.
    • AJAX asynchronously eliminates the interaction between the client and the server, while REST requires the interaction between the client and the server.
  • AJAX technology ” set “. REST – provides methods for users to request data or information from a server.

29. What does the @Path annotation do?

The @Path annotation associates a URI pattern with a Java method.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.core.Response;

@Path(“/persons”)

public class PersonRestService {

 @GET

 public Response getPerson() {

     return Response.status(200).entity(“getPerson is called”).build();

 }

@GET

@Path(“/vip”)

public Response getPersonVIP() {

   return Response.status(200).entity(“getPersonVIP is called”).build();

}

}

When calling a URI: ‘ / persons ‘, the getPerson method will be called ;

When calling the URI: ‘ / persons / vip ‘, the getPersonVIP method will be called  ;

SOAP RESTful Interview Questions And Answers

30. What does the @PathParam annotation do?

@PathParam embeds the values ​​of the URI parameter, which is specified in the expression.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.PathParam;

import javax.ws.rs.core.Response;

@Path(“/persons”)

public class PersonRestService {

@GET

@Path(“{id}”)

public Response getPersonById(@PathParam(“id”) String id) {

 return Response.status(200).entity(“getPersonById is called, id : ” + id).build();

}

}

When calling the URI ‘ / persons / 1 ‘, we get the call getPersonById and id = 1 ;

31. What does the @QueryParam annotation do?

@QueryParam injects the URI request parameter into the Java method.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

import java.util.List;

import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.QueryParam;

import javax.ws.rs.core.Response;

@Path(“/persons”)

public class PersonService {

@GET

@Path(“/query”)

public Response getPersons(

@QueryParam(“from”) int from,

@QueryParam(“to”) int to,

@QueryParam(“orderBy”) List<String> orderBy) {

return Response

 .status(200)

 .entity(“getPersons is called, from : ” + from + “, to : ” + to

+ “, orderBy” + orderBy.toString()).build();

}

}

When calling URI: “ / persons / query? From = 10 & to = 20 & orderBy = age & orderBy = name ”, we get a call to the getPersons method  and from = 10 , to = 20 , orderBy [ age, name ]

32. What does the @MatrixParam annotation do?

@MatrixParam matches the “ name = value ” in the URI path.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

import javax.ws.rs.GET;

import javax.ws.rs.MatrixParam;

import javax.ws.rs.Path;

import javax.ws.rs.PathParam;

import javax.ws.rs.core.Response;

@Path(“/books”)

public class BookService {

@GET

@Path(“{year}”)

public Response getBooks(@PathParam(“year”) String year,

@MatrixParam(“author”) String author,

@MatrixParam(“country”) String country) {

return Response

.status(200)

.entity(“getBooks is called, year : ” + year

+ “, author : ” + author + “, country : ” + country)

.build();

}

}

When calling URI: “ / books / 2015 ” the method will be called: getBooks , year: 2015 , author: null , country: null .

When calling URI: “ / books / 2015; author = doyle; country = scotland ”, the method will be called: getBooks , year: 2015 , author: doyle , country: scotland .

33. What does the @FormParam annotation do?

@FormParam binds HTML parameters in a Java method.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

import javax.ws.rs.FormParam;

import javax.ws.rs.POST;

import javax.ws.rs.Path;

import javax.ws.rs.core.Response;

@Path(“/persons”)

public class PersonService {

@POST

@Path(“/add”)

public Response addPerson(

@FormParam(“name”) String name,

@FormParam(“age”) int age) {

return Response.status(200)

.entity(“addPerson is called, name : ” + name + “, age : ” + age)

.build();

}

}

HTML form:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

<html>

<body>

 <form action=”/persons/add” method=”post”>

  <p>

  Name : <input type=”text” name=”name” />

  </p>

  <p>

  Age : <input type=”text” name=”age” />

  </p>

  <input type=”submit” value=”Add Person” />

 </form>

</body>

</html>

Advanced Java Web Services Interview Questions For Experienced

34. What are two ways to get the HTTP request header in JAX-RS?

  1. Embed method using @HeaderParam
1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.HeaderParam;

import javax.ws.rs.core.Response;

@Path(“/persons”)

public class PersonService {

@GET

@Path(“/get”)

public Response getPerson(

@HeaderParam(“person-agent”) String personAgent) {

return Response.status(200)

.entity(“getPerson is called, personAgent : ” + personAgent)

.build();

}

}

Calling the URI: “ / persons / get ” will call the getPerson method with the personAgent parameter : Mozilla / 5.0 (Windows NT 6.1; rv: 5.0) Gecko / 20100101 Firefox / 5.0

2) Programmatically using the @Context annotation

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.core.Context;

import javax.ws.rs.core.HttpHeaders;

import javax.ws.rs.core.Response;

@Path(“/persons”)

public class PersonService {

@GET

@Path(“/get”)

public Response getPerson(@Context HttpHeaders headers) {

String personAgent = headers.getRequestHeader(“person-agent”).get(0);

return Response.status(200)

.entity(“getPerson is called, personAgent : ” + personAgent)

.build();

}

}

Call URI: “ / persons / get ”, result: call getPerson method and personAgent: Mozilla / 5.0 (Windows NT 6.1; rv: 5.0) Gecko / 20100101 Firefox / 5.0

35. How to download a file using JAX-RS?

    • Set the @Produces (‘?’) Annotation over the service method indicating the type returned in the response. Instead of ‘?’ use text / plain , image / png , etc.
  • Set Conent-Description in the response header for the browser alert to show a pop-up window for downloading.
1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

import java.io.File;

import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.Produces;

import javax.ws.rs.core.Response;

import javax.ws.rs.core.Response.ResponseBuilder;

@Path(“/image”)

public class ImageService {

private static final String FILE_PATH = “c:\\my.png”;

@GET

@Path(“/get”)

@Produces(“image/png”)

public Response getFile() {

File file = new File(FILE_PATH);

ResponseBuilder response = Response.ok((Object) file);

response.header(“Content-Disposition”,

“attachment; filename=image_from_server.png”);

return response.build();

}

}

Must Read Java Interview Questions Books 2020

RELATED INTERVIEW QUESTIONS

  1. Spring Interview Questions
  2. Spring Boot Interview Questions
  3. GIT Interview Questions And Answers
  4. Network Security Interview Questions
  5. CheckPoint Interview Questions
  6. Page Object Model Interview Questions
  7. Apache Pig Interview Questions
  8. Python Interview Questions And Answers
  9. Peoplesoft Integration Broker Interview Questions
  10. PeopleSoft Application Engine Interview Questions
  11. RSA enVision Interview Questions
  12. RSA SecurID Interview Questions
  13. Archer GRC Interview Questions
  14. RSA Archer Interview Questions
  15. Blockchain Interview Questions
  16. Commvault Interview Questions
  17. Peoplesoft Admin Interview Questions
  18. ZooKeeper Interview Questions
  19. Apache Kafka Interview Questions
  20. Couchbase Interview Questions
  21. IBM Bluemix Interview Questions
  22. Cloud Foundry Interview Questions
  23. Maven Interview Questions
  24. VirtualBox Interview Questions
  25. Laravel Interview Questions
  26. Logstash Interview Questions
  27. Elasticsearch Interview Questions
  28. Kibana Interview Questions
  29. JBehave Interview Questions
  30. Openshift Interview Questions
  31. Kubernetes Interview Questions
  32. Nagios Interview Questions
  33. Jenkins Interview Questions
  34. Chef Interview Questions
  35. Puppet Interview Questions
  36. RPA Interview Questions And Answers
  37. Demandware Interview Questions
  38. Visual Studio Interview Questions

Leave a Comment