Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Can Restful Web Services Support Multiple Types Of Response (mime) Formats?

Answer»

RESTful Web Services, by confirming to HTTP, does SUPPORT multiple types of RESPONSE (MIME) FORMATS e.g. XML, JSON, PLAIN etc.

RESTful Web Services, by confirming to HTTP, does support multiple types of response (MIME) formats e.g. XML, JSON, PLAIN etc.

2.

Give An Example Of Declaring More Than One Media Type In @consumes Declaration?

Answer»

@POST 
@CONSUMES({"application/plain","application/xml"}) 
PUBLIC VOID postMessage(STRING message) { 
... 

@POST 
@Consumes({"application/plain","application/xml"}) 
public void postMessage(String message) { 
... 

3.

At Which Levels, @consumes Can Be Applied?

Answer»

@CONSUMES can be APPLIED at both the CLASS and METHOD LEVELS

@Consumes can be applied at both the class and method levels. 

4.

Write A Method That Is Triggered On Post Request And Takes Text/plain As Input?

Answer»

@POST 
@CONSUMES("text/plain") 
public VOID POSTMESSAGE(STRING message) { 
... 

@POST 
@Consumes("text/plain") 
public void postMessage(String message) { 
... 

5.

How Will You Specify The Mime Media Types Of Representations A Restful Resource Can Use?

Answer»

@CONSUMES ANNOTATION is to be USED

@Consumes annotation is to be used. 

6.

Assume That There Is A Resource Class Capable Of Producing More Than One Mime Media Type For Get. How Will Be The Response Method Chosen?

Answer»

Resource method is CHOSEN DEPENDING on the most acceptable MEDIA type as DECLARED by the client in the request HEADER

e.g. 

Accept: text/plain. 

Resource method is chosen depending on the most acceptable media type as declared by the client in the request header. 

e.g. 

Accept: text/plain. 

7.

How Can You Declare More Than One Media Type In The Same @produces Declaration?

Answer»

@PRODUCES({"application/plain","application/xml", "application/json"}) 

@Produces({"application/plain","application/xml", "application/json"}) 

8.

Can @produces Annotation Be Overridden In A Restless Resource? Give Example?

Answer»

Yes. In the following example, the default MIME type is set as text/plain but doGetAsHtml method overrides it to text/html. 

@Path("/testResource") 
@PRODUCES("text/plain") 
PUBLIC class TestResource { 
@GET 
public STRING doGetAsPlainText() { 
... 

 
@GET 
@Produces("text/html") 
public String doGetAsHtml() { 
... 

Yes. In the following example, the default MIME type is set as text/plain but doGetAsHtml method overrides it to text/html. 

@Path("/testResource") 
@Produces("text/plain") 
public class TestResource { 
@GET 
public String doGetAsPlainText() { 
... 

 
@GET 
@Produces("text/html") 
public String doGetAsHtml() { 
... 

9.

Is It True That @produces Can Only Be Applied At Method Level?

Answer»

FALSE. It can be APPLIED at both the CLASS and METHOD LEVELS

False. It can be applied at both the class and method levels. 

10.

Explain How To Specify Mime Media Types Of A Resource That Is Sent Back To The Client?

Answer»

@PRODUCES ANNOTATION is USED for this PURPOSE..

 e.g. 

@Produces("text/plain") 

@Produces annotation is used for this purpose..

 e.g. 

@Produces("text/plain") 

11.

Will The Following Direct To The Same Resource? @path("/test/") @path("/test") 

Answer»

Yes. By DEFAULT, both should POINT to the same resource, although Jersey has arection MECHANISM that is DISABLED by default. 

Yes. By default, both should point to the same resource, although Jersey has arection mechanism that is disabled by default. 

12.

What Happens If Regular Expression Of A Uri Embedded Variable Is Not Matched?

Answer»

A 404 (Not FOUND) RESPONSE will OCCUR

A 404 (Not Found) response will occur. 

13.

How Can You Define A Regular Expression For A Variable Say Username?

Answer»

@PATH("USERS/{USERNAME: [a-zA-Z][a-zA-Z_0-9]*}") 

@Path("users/{username: [a-zA-Z][a-zA-Z_0-9]*}") 

14.

How Can You Obtain The Value Of A Method Parameter In Restful Resource Method?

Answer»

@PathParam can be used on method PARAMETER of a RESOURCE method to OBTAIN the value for a method parameter. 

e.g. 

@GET 
@Produces("text/plain") 
public String getWelcomeMsg(@PathParam("username") String userName) { 
... 

@PathParam can be used on method parameter of a resource method to obtain the value for a method parameter. 

e.g. 

@GET 
@Produces("text/plain") 
public String getWelcomeMsg(@PathParam("username") String userName) { 
... 

15.

How Embedded Variables Are Represented In The Uri Syntax?

Answer»

EMBEDDED VARIABLES are DENOTED by CURLY BRACES

Embedded variables are denoted by curly braces. 

16.

How Can You Embed Variables In The Uri?

Answer»

Variables can be embedded within the URI syntax (CALLED URI path template). The variables are substituted at RUNTIME

@Path("/TEST/{USERNAME}") 

Variables can be embedded within the URI syntax (called URI path template). The variables are substituted at runtime. 

@Path("/test/{username}") 

17.

How To You Specify Relative Path Of A Resource In Restful Web Service?

Answer»

The @Path ANNOTATION is USED to specify RELATIVE URI path. 

e.g. 

@Path("/test") 

The @Path annotation is used to specify relative URI path. 

e.g. 

@Path("/test") 

18.

Define Resource Method?

Answer»

Method of a RESOURCE CLASS that is annotated with resource method designator ANNOTATION is called Resource Method. 

Method of a resource class that is annotated with resource method designator annotation is called Resource Method. 

19.

Define Root Resource Class?

Answer»

Root resource CLASS is basically a POJO (Plain Old JAVA OBJECTS) that is ANNOTATED with @Path and has at least ONE method annotated with @Path or have at least a SINGLE resource method. 

Root resource class is basically a POJO (Plain Old JAVA Objects) that is annotated with @Path and has at least one method annotated with @Path or have at least a single resource method. 

20.

List Resource Method Designator Annotations?

Answer»

@GET, @PUT, @POST, @DELETE 

@GET, @PUT, @POST, @DELETE 

21.

What Is The Purpose Of Javax.ws.rs.httpmethod?

Answer»

HttpMethod annotation is used to ASSOCIATE the NAME of a HTTP METHOD with an annotation. 

HttpMethod annotation is used to associate the name of a HTTP method with an annotation. 

22.

Why Put Methods Is Idempotent?

Answer»

PUT is used to CREATE a resource and REPEATING the operation should NEVER create another copy of the resource. 

PUT is used to create a resource and repeating the operation should never create another copy of the resource. 

23.

In Order To Answer Http Put Requests, How Will You Annotate Your Resource Methods?

Answer»

The @PUT ANNOTATION is USED to ANSWER HTTP PUT REQUESTS

The @PUT annotation is used to answer HTTP PUT requests. 

24.

What Are Idempotent Methods?

Answer»

A METHOD is SAID to be idempotent if REPEATED calls to it does not cause DUPLICATES

A method is said to be idempotent if repeated calls to it does not cause duplicates. 

25.

Define One-to-one Mapping Between Http Methods And Crud Operations?

Answer»

PUT MAPS to CREATE, GET maps to Retrieve, POST maps to UPDATE, DELETE maps to Delete. 

PUT maps to Create, GET maps to Retrieve, POST maps to Update, DELETE maps to Delete. 

26.

Name The Most Commonly Http Methods Used In Designing Restful Services?

Answer»

PUT, GET, POST, DELETE.

PUT, GET, POST, DELETE.

27.

How Do You Annotate A Method To Respond To Http Get Requests?

Answer»

javax.ws.rs.GET ANNOTATION SPECIFIES that the ANNOTATED method will SERVE HTTP Get request. 

javax.ws.rs.Get annotation specifies that the annotated method will serve HTTP Get request. 

28.

What Is Shared Between Restful Resource That Is Used For Transfer Of State Between Client And Resource?

Answer»

A UNIFORM interface is shared between resources that comprises of a set of well‐defined operations, content TYPES and optionally supporting code‐on‐demand. 

A uniform interface is shared between resources that comprises of a set of well‐defined operations, content types and optionally supporting code‐on‐demand. 

29.

In Restful Architecture, What Represents The Application State And Functionality?

Answer»

UNIQUELY Addressable RESOURCES represent the APPLICATION STATE and functionality. 

Uniquely Addressable Resources represent the application state and functionality. 

30.

How Are Resources Addressed?

Answer»

Each resource is UNIQUELY addressable USING a universal syntax for USE in hypermedia links. 

Each resource is uniquely addressable using a universal syntax for use in hypermedia links. 

31.

If I Plan To Use The Jersey Distribution For Restful Web Services, Do I Need To Download It?

Answer»

YES. But if you are USING NetBeans IDE 6.0, downloading is not REQUIRED

Yes. But if you are using NetBeans IDE 6.0, downloading is not required. 

32.

Name Few Of The Jax-rs Implementations?

Answer»

JERSEY, RESTEasy, Restlet are to NAME a few. 

Jersey, RESTEasy, Restlet are to name a few. 

33.

How Web Service Interface For Restful Web Services Are Described?

Answer»

There is no FORMAL way of describing the Web Service interfaces. To overcome this, service producer and service CONSUMER agree on SCHEMAS that DESCRIBE the data being exchanged. 

There is no formal way of describing the Web Service interfaces. To overcome this, service producer and service consumer agree on schemas that describe the data being exchanged. 

34.

Name The Java Api That Is Used For Building And Deploying Restful Web Services?

Answer»

35.

Is Rest Stateless Or Stateful Client-server Architecture?

Answer»

REST is STATELESS client-server ARCHITECTURE

REST is stateless client-server architecture. 

36.

How Do You Refer Or Identify Resources In Rest Design Idiom?

Answer»

RESOURCES are identified by their UNIQUE URLS

Resources are identified by their unique URLs. 

37.

In Which Scenarios Restful Web Services Are Preferred Over Soap Ones?

Answer»

RESTful Web Services are preferred when: 

a) The Web Services are completely stateless. 
b) When data can be cached to IMPROVE PERFORMANCE
c) Schema of data can be agreed between service CONSUMER and service provider. 
d) Bandwidth is limited. 

RESTful Web Services are preferred when: 

a) The Web Services are completely stateless. 
b) When data can be cached to improve performance. 
c) Schema of data can be agreed between service consumer and service provider. 
d) Bandwidth is limited.