0% found this document useful (0 votes)
781 views20 pages

RESTful Java Web Services Interview Questions You'll Most Likely Be Asked: Second Edition

RESTful Java Web Services Interview Questions You’ll Most Likely Be Asked is a perfect companion to stand ahead above the rest in today’s competitive job market. Rather than going through comprehensive, textbook-sized reference guides, this book includes only the information required immediately for job search to build an IT career. This book puts the interviewee in the driver’s seat and helps them steer their way to impress the interviewer.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
781 views20 pages

RESTful Java Web Services Interview Questions You'll Most Likely Be Asked: Second Edition

RESTful Java Web Services Interview Questions You’ll Most Likely Be Asked is a perfect companion to stand ahead above the rest in today’s competitive job market. Rather than going through comprehensive, textbook-sized reference guides, this book includes only the information required immediately for job search to build an IT career. This book puts the interviewee in the driver’s seat and helps them steer their way to impress the interviewer.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

RESTful Java Web

Services Interview
Questions
Review these typical interview questions and think about how you would
answer them. Read the answers listed; you will find best possible answers
along with strategies and suggestions.
This page is intentionally left blank
Chapter 1

Introduction to REST

1: What is REST?
Answer:
REST stands for REpresentational State Transfer. It is an
architectural style for developing web services. In a REST
application, the REST server exposes various services and client
applications access those services. It makes use of the HTTP
protocol, so the REST client and server communicate via HTTP.
The data exchanged between the client and server can be in
different formats like plain text, XML, HTML or JSON. So, a REST
client requests a REST service via a URI, the REST service
processes the client request and sends back the data in the
appropriate format.
2: Which are the six principles on which REST API is based?
Answer:
a) Client server – Concerns should be separated between
clients and servers. This allows client and server
applications to be developed independently.
b) Stateless – The communication between the client and
server should be stateless. The server need not remember
the state of the client.
c) Layered System – Layered system simply means there can
be several layers on the server side, but the client application
need not be aware of this. So, your server code may be on
one machine, database on another, etc. Multiple hierarchies
such as gateways, firewalls, proxies can also be present
between the client and server.
d) Cache – Responses from the server should be cacheable
where possible in order to improve performance for the
client.
e) Uniform Interface – The services provided by a REST
application must be exposed via URIs. All interactions
between client, server and intermediary components are
based on the uniformity of their interfaces.
f) Code on demand – In addition to static data like XML or
JSON, the REST application can send code like JavaScript,
Applets which can be downloaded and executed by client
applications.

3: Why is a REST service considered stateless?


Answer:
A REST application uses the HTTP protocol. HTTP is considered
to be stateless. Statelessness simply means that the server does not
store any state information about the client application. So, a client
application needs to send all possible data that the server will
require in order to process the client request. If at all the
application needs to store some state specific data, this needs to be
stored on the client side and sent with each HTTP request. At the
server side, each HTTP request is processed independently.

4: Explain the differences between SOAP and REST.


Answer:
Both SOAP and REST technologies are used to create web
services. However, there are some differences between the two:
a) SOAP is a protocol like HTTP whereas REST is an
architectural style for developing web services - it can use
any underlying protocol.
b) Though REST applications mostly use HTTP as the
underlying protocol, they can use SOAP as well. However, a
SOAP application cannot use REST.
c) SOAP uses the JAX-WS Java API, REST uses the JAX-RS
Java API.
d) SOAP application provides its services via a WSDL file. A
REST application, on the other hand, exposes its services
using URIs.
e) When SOAP is used, only XML data format can be used.
When REST is used, you can use XML, JSON, HTML or
plain text as the data format.
5: What are the steps in building a RESTful API?
Answer:
The following are the steps involved in building a RESTful
application:
a) Identify resources – Central to REST are resources. We need
to model resources that are of interest to the consumers.
b) Identify endpoints – Next, we need to design URIs that
map resources to endpoints.
c) Identity actions – We need to identity the HTTP methods
that can be used to perform operations on the resources.
d) Identity responses – We need to identify the supported
resource representation for the request and response along
with the right status code to be returned.

6: What are the benefits of using a REST API?


Answer:
REST is an architectural style. It has several features that make it
very powerful and easy to use:
a) It is independent of language or technology. So, the REST
server can be written in any programming language and the
REST client can be written in any programming language.
b) It is platform independent. So, the server can be on any
operating system like Windows, Unix, etc. and the client can
be on a different operating system.
c) It allows the application to scale easily. Since the client and
server side are developed separately, each side can be scaled
easily without affecting the other.
7: Explain the HATEOAS principle in REST with an example.
Answer:
HATEOAS stands for Hypermedia As The Engine Of Application
State. This principle allows embedding links to other resources or
services in a REST response. So, the REST client need not know
about the services provided by a REST application. As and when
the client requests information, along with information, the server
provides links to other services that the client can access. Consider
the following REST request which queries a REST service for
employee information:
GET /employees/123
This will return a response as follows:
<employee>
<employee_id>123</employee_id>
<name>John Smith</name>
<department>Admin</department>
<link rel="payroll"
href="/employees/123/payroll" />
</employee>
So, along with the employee information, a link is provided which
can be used by the client application to fetch payroll information
for the employee.

8: How is a REST application different from an ordinary web


application?
Answer:
Just like an ordinary web application, a REST application uses the
HTTP protocol for the communication between the client and
server application. However, there are couple of differences
between the two:
a) Normally, a web application serves content in HTML
format. A REST application can serve content in XML, JSON
or HTML format.
b) The end users of a web application are humans who access
the web application via their browsers. Though a REST
application may be accessed via a browser for testing
purpose, they are generally used by software applications
itself which are known as REST clients.

9: Explain the principles of the Uniform Interface constraint.


Answer:
The Uniform Interface principle states that there should be a
uniform interface between clients and servers. It consists of the
following four principles:
a) Resource identification – Resource needs to be identified. A
URI needs to be provided in order to identify and access a
resource.
b) Resource representation – The resource needs to be
serialized into a representation before being sent to a client.
c) Self-descriptive messages – Each message sent to the client
needs to have information about how that message should
be processed.
d) HATEOAS – Hypermedia As The Engine Of Application
State (HATEOAS) allows embedding links to other
resources or services provided by a REST server in a REST
response.
10: What does the term "messaging" refer to in the context of a
REST application?
Answer:
In a REST application, the client and the server communicate with
each other via the HTTP protocol. So, the client application sends
an HTTP request and the REST server sends an HTTP response.
This is referred to as messaging. Each message consists of the
message data and metadata, that is data about the message data.
So, an HTTP Request consists of the HTTP Method being
requested, parameters if any and request headers which is the
metadata. So, also an HTTP Response consists of the Response
Headers and actual data being requested.
This page is intentionally left blank

You might also like