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

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 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' - 35 question(s) found - Order By Newest

next 30
 Q1. How to find whether a given integer is odd or even without use of modulus operator in java?Core Java
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     Asked in 4 Companies        frequent


Very frequently asked in companies using SOA.
  Q2. What are RESTful Web Services ?Rest
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     Asked in 14 Companies      intermediate        frequent


  Q3. Difference between GET and POST Requests ?Web Service
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     Asked in 11 Companies      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
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
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. What is a Webdriver ?Testing
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     Asked in 37 Companies


 Q7. In which cases using SOAP is preferred over REST ?Web Service
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     Asked in 2 Companies


 Q8. What could be the reasons for restricting inheritance using final class ?Core Java
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


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


 Q10. Write a method to convert binary to a number ?Core Java
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


 Q11. Which markup languages can be used in restful web services ? Rest
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


 Q12. Why Web services use HTTP as the communication protocol ?Web Service
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


 Q13. Name some Java REST services frameworks ?Rest
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


 Q14. Name few Restriction Methods ?Hibernate
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


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

a. Service
b. Model
c. Controller
d. Util
Spring
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


 Q16. Can we send a request body with the Get Request ? If not, What is the alternate to pass message to the Get Request ?Web Service
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.
 Q17. Different between POST and PUT in Rest Rest
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     Asked in 5 Companies        frequent


 Q18. Should a Database Update Request be a POST or PUT Request in RestRest
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     Asked in 1 Companies


 Q19. Should a DB Insert Request be a POST or PUT request in RestRest
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     Asked in 2 Companies      intermediate        frequent


 Q20. Is it Necessary to send a POST request with the Payload or a body ?Web Service
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


 Q21. Can we send payload / body with the GET Request in Rest ?
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


 Q22. Can I hit the Rest Post Request through a browser address bar if it's not expecting any payload / body ? Rest
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


 Q23. What are the different ways in which information can be sent to server in web service call ?Web Service
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


 Q24. How to specify the or/and combination restrictions within Criteria in Hibernate ? Hibernate
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


 Q25. How to create stateful Rest Services ?Rest
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     Asked in 1 Companies


 Q26. How would you go about creating a get rest service if it requires multitude of params or inputs ?Rest
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 ?Rest
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 ?Junit
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 Service
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


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

@Path("/{employeeId}")
public String employeeInfo(@PathParam("employeeId") Long employeeId){
}
Rest
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


next 30

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: