Interview Questions and Answers for 'Rest' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Interview Questions


 3235 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Rest' - 32 question(s) found - Order By Newest

 Q1. How to find whether a given integer is odd or even without use of modulus operator in java?Core Java
Admin
info@buggybread.com
Ans. public static void main(String ar[])
{
int n=5;
if((n/2)*2==n)
{
System.out.println("Even Number ");
}
else
{
System.out.println("Odd Number ");
}
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   code   coding   tricky questions   interesting questions   modulus operator     Agnity  Amdocs  Asurion  Oodles Technologies        frequent


Very frequently asked in companies using SOA.
  Q2. What are RESTful Web Services ?Rest
Admin
info@buggybread.com
Ans. REST or Representational State Transfer is a flexible architecture style for creating web services that recommends the following guidelines -

1. http for client server communication,
2. XML / JSON as formatiing language ,
3. Simple URI as address for the services and,
4. stateless communication.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   web services   rest   java   j2ee  architecture     Synechron  CapitalOne  Overstock.com  Ebay  At&t  HCL Technologies  Barclays  Tata Consultancy (TCS)  Cognizant (CTS)  Wipro  Infosys  EPAM  Mphasis  verchaska infotech      intermediate        frequent


  Q3. Difference between GET and POST Requests ?Web Service2016-07-22 15:00:21

Ans. GET is supposed to get information from the server. Client sends the minimal information so that Server can respond with the response body on basis of request. For example - You want to get complete employment record for employee id 123

POST is supposed to send the information for submission. Payload or a Body is usually sent so that it can be persisted on the server. For example - Sending the complete information of an employee ( id, name , dept etc ) to the server for persisting it.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     get vs post   web service   rest     Wayfair  Finacus Solutions  Elsevier  Cognizant (CTS)  FlipKart  Singsys  Overstock  One Click Retail  Spillman Technologies  HCL Technologies  Infosys Technologies      basic        frequent


 Q4. What will be the output of following Code ?

class BuggyBread {
   public static void main(String[] args) {
      String s2 = "I am unique!";
      String s5 = "I am unique!";

      System.out.println(s2 == s5);
   }
}
Core Java
Admin
info@buggybread.com
Ans. true, due to String Pool, both will point to a same String object.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   code   coding   tricky questions   interesting questions   string   string pool   .equal   ==      intermediate        frequent


 Q5. What will be the output of following code ?
class BuggyBread2 {       
   private static int counter = 0;     
   void BuggyBread2() {        
      counter = 5;    
   }     
   
   BuggyBread2(int x){
      counter = x;    
   }        

   public static void main(String[] args) {        
      BuggyBread2 bg = new BuggyBread2();        
      System.out.println(counter);    
   } 
}
Core Java
Admin
info@buggybread.com
Ans.  Compile time error as it won't find the constructor matching BuggyBread2(). 
Compiler won't provide default no argument constructor as programmer has already defined one constructor. 
Compiler will treat user defined BuggyBread2() as a method, as return type ( void ) has been specified for that. 

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   code   coding   tricky questions   interesting questions   default constructor   constructor

Try 3 Question(s) Test


 Q6. In which cases using SOAP is preferred over REST ?Web Service2017-04-27 18:08:18

Ans. SOAP services are better in case we need to establish a formal and detail contract with the client or callers and hence suitable for

1. Services published for much wider unknown audience
2. Require large input payload
3. Requiring different level for authentication

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     soap vs rest  soap  rest       Cogent Infotech Corp


 Q7. What could be the reasons for restricting inheritance using final class ?Core Java2018-07-16 06:52:00

Ans. 1. Enforcing composition over inheritance
2. Restricting overriding of certain methods
3. Final methods are faster than regular instance methods
4. Enforcing Immutability

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     final class   reasons for final class   restricting inheritance  object oriented programming (oops)  oops concepts      expert


 Q8. If you have access to a function that returns a random integer from one to five, write another function which returns a random integer from one to seven.Core Java
Admin
info@buggybread.com
Ans. We can do that by pulling binary representation using 3 bits ( random(2) ).

getRandom7() {
   String binaryStr = String.valuesOf(random(2))+String.valuesOf(random(2))+String.valuesOf(random(2));
   binaryInt = Integer.valueOf(binaryStr);
   int sumValue=0;
   int multiple = 1;
   while(binaryInt > 0){
      binaryDigit = binaryInt%10;
      binaryInt = binaryInt /10;
      sumValue = sumValue + (binaryDigit * multiple);
      multiple = multiple * 2;
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   tricky question   interesting questions   google interview questions   random


 Q9. Write a method to convert binary to a number ?Core Java
Admin
info@buggybread.com
Ans.
convert(int binaryInt) {
   int sumValue=0;
   int multiple = 1;
   while(binaryInt > 0){
      binaryDigit = binaryInt%10;
      binaryInt = binaryInt /10;
      sumValue = sumValue + (binaryDigit * multiple);
      multiple = multiple * 2;
   }
   return sumValue;
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   binary   interesting question   coding



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. Which markup languages can be used in restful web services ? Rest
Admin
info@buggybread.com
Ans. XML and JSON ( Javascript Object Notation ).

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   web services   rest   java   j2ee   xml   json   architecture      basic        frequent


 Q11. Why Web services use HTTP as the communication protocol ?Web Service
Admin
info@buggybread.com
Ans. With the advent of Internet, HTTP is the most preferred way of communication. Most of the clients ( web thin client , web thick clients , mobile apps ) are designed to communicate using http only. Web Services using http makes them accessible from vast variety of client applications.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     rest   webservices   web servuces   http   architecture   technical architect


 Q12. Name some Java REST services frameworks ?Rest
Admin
info@buggybread.com
Ans. Jersey , Restlet , RestX, Spring , RestEasy ,Restfulie, Play Framework

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   rest   web services   frameworks


 Q13. Name few Restriction Methods ?Hibernate
Admin
info@buggybread.com
Ans. eq, ge, gt , between, in , isNull, isEmpty, isNotnull, ne , like, lt , or , not

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     hibernate   hibernate criteria   hibernate restriction


 Q14. In Spring , Which class handles the Http requests for RESTful web services ?

a. Service
b. Model
c. Controller
d. Util
Spring
Anonymous
Ans. Controller

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     spring frmaework   spring mvc   rest   webservices


 Q15. Can we send a request body with the Get Request ? If not, What is the alternate to pass message to the Get Request ?Web Service2016-06-22 09:18:14

Ans. Request Body in case of Get Request has no meaning and hence it's not parsed when the request is received. Alternatively Request Parameters are passed as either Path Params or Query Params.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     rest  web services  http  http methods  get request


Frequently asked question in companies using Rest Web services.
 Q16. Different between POST and PUT in Rest Rest2016-07-22 14:33:40

Ans. PUT requests are only meant to place the object as it is on server. For example - You want a file to be uploaded and then placed in a particular folder or you want an Employee object to be persisted in the table.

POST requests are also meant to transfer information from client to server but that information once received at the server is evaluated , modified or refactored before persisting.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Put vs Post   Rest     overstock.com  HCL Technologies  Tata Consultancy (TCS)  Tech Mahindra  Indra        frequent


 Q17. Should a Database Update Request be a POST or PUT Request in RestRest2016-07-22 14:34:17

Ans. It should be a POST Request

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Put vs Post   Rest     Saba Software


 Q18. Should a DB Insert Request be a POST or PUT request in RestRest2016-07-22 14:36:02

Ans. It depends on whether the request object is persisted as it is

or

its first dismantled, modified or refactored and then inserted into DB.

In first case, it should be a PUT request whereas in second case it should be a POST Request.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Put vs Post   Rest     Ciber  Apervi Technologies      intermediate        frequent


 Q19. Is it Necessary to send a POST request with the Payload or a body ?Web Service2016-07-22 14:36:42

Ans. No, we can also send an empty body with the POST Request.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Get Request   Rest        rare



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q20. Can we send payload / body with the GET Request in Rest ?2016-07-22 14:37:22

Ans. We can send it but it's completely ignored by the server.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Get Request   Rest


 Q21. Can I hit the Rest Post Request through a browser address bar if it's not expecting any payload / body ? Rest2016-07-22 14:40:01

Ans. No, even if there is no payload, you can't hit the POST request by typing it into browser address bar. You will need a client that can make a POST Request.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Post Request   Rest  Calling Rest service through browser        rare


 Q22. What are the different ways in which information can be sent to server in web service call ?Web Service2016-07-22 14:57:32

Ans. 1. As Request Param
2. As Path Param
3. Part of Payload / Body in case of PUT and POST Request

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     web service   rest      basic        frequent


 Q23. How to specify the or/and combination restrictions within Criteria in Hibernate ? Hibernate2016-11-28 11:52:25

Ans. session.createCriteria(Employee.class).add( Restrictions.or(Restrictions.like("name", "A%"),Restrictions.like("name", "B%"))).list();

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     hibernate  Criteria  Restrictions


 Q24. How to create stateful Rest Services ?Rest2016-12-14 08:24:19

Ans. There is no direct way to make stateful REST service but when first time request send to server, generate the token on server and send back to client. When every time new request is send the token is send to identify the request is coming from same client.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Rest  Web Services     JPMorgan Chase


 Q25. What is a Webdriver ?Testing2017-02-02 08:25:41

Ans. Selenium WebDriver is a tool for automating web application testing.It helps in replicating the manual tester behavior like keyboard entry, mouse events etc and then matching the output against the expected.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     selenium  webdriver     Global Software Resources  FICO Software  Walt Disney  Softcrylic  Sky  23andMe  Endurance Group  CitiusTech  Hitachi Consulting  Crest Premedia  LivingSocial  TEKSystems  Jabong.com  Think Future Technologies  Dollar Shave Club  Zendesk  Five9  Aptify  Symphony Teleca  Collabera  Xpanxion  Fourth Technologies  Freedom Financial  Aurigo Software Technologies  Forte Group  Wipro  Infosys  Pearson  Overstock  Elsevier  Capgemini  Cognizant (CTS)  Tech Mahindra  OLA Software  Mphasis  GrayLocus  Bhavna


 Q26. How would you go about creating a get rest service if it requires multitude of params or inputs ?Rest2017-04-27 18:12:23

Ans. If the number of input values is large, we can go about passing them as query params instead of path params. If the number is even larger and complex , its better to create a post service that behaves like a get service. Though this practice is not recommended but technically it can be accomplished.I dont mind doing it if the exceptionally large number of input would make it much more confusing.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     rest  restful web services


 Q27. Can we discover end points of Rest API without looking at the code ?Rest2017-05-05 08:40:31

Ans. Generally Rest services don't have any registry like we have WSDL is SOAP and hence don't have a way to know the end points without looking at either the url mapping in controller or client code. Some restful service publish WADL (Web Application Description Language) and hence clients can locate the service end points.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     rest api endpoints


 Q28. Can you name few matchers that can be used with hamcrest assertThat method ?Junit2017-05-17 16:52:13

Ans. is
not
equals
anyOf
hasSize

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     assertThat.hamcrest


 Q29. If given a choice , which one would you prefer to send params to the Get service , path params or query param ?Web Service2017-05-22 08:28:27

Ans. If the number of params is quite large , I would prefer to either split it with majority of it in query params or all in query params.

If the params are all mandatory , I would keep it as path params. If it's optional , I would keep it as query param so as to keep consistent base url.

If we don't require the param name , then they can be kept as path params as query params necessitates the usage of param name.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Web Service  Get service  path vs query param  Rest  query param  path param



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q30. Is it necessary to specify "employeeId" with @PathParam("employeeId") in this case,

@Path("/{employeeId}")
public String employeeInfo(@PathParam("employeeId") Long employeeId){
}
Rest2017-05-22 08:30:39

Ans. No, it's optional as the name of path param required is same as method param name in this case.

Even the declaration as following should work -

@Path("/{employeeId}")
public String employeeInfo(@PathParam Long employeeId){
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Web Service  Get service  Rest  path param


 Q31. Difference between stateless and stateful rest services ?Rest2017-08-17 11:02:28

 This question was recently asked at 'Sofi'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     rest services  stateful rest service  stateless rest service     Sofi


 Q32. If SOAP is more secure than Rest, Why many applications today use Rest ?Web Service2018-07-04 16:21:38

Ans. SOAP supports only xml whereas Rest support many other formats.

Rest services are very light weight compared to SOAP.

SOAP services are code heavy as they require creation. of stubs and skeltons.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     soap  rest  soap vs rest     Deloitte  Cogent Infotech Corp




Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked:
         

X Close this