Introduction to Services


Let us begin with some real world examples of services we use. We call up a nearby restaurant and post an order, the food arrives. Here we are using the service provided by the restaurant. We use taxi booking mobile apps to avail taxi service. Here we are using the service provided by taxi booking application.

In the above examples the restaurant, taxi booking application are service providers. We are service clients. Typically service providers announce some End points to which service clients can communicate. In the restaurant example the End point is the restaurant phone number. A client has to call on the phone number to place an order. So the communication is happening over phone network.

In the taxi booking scenario the client will be using a mobile app which is programmed to call some url internally for booking purposes. The End point in this case is the url. Here the communication is happening over the web via http.


In the Information Technology world also service client and service provider almost work the same way. Service provider refer to any resource (resource can be any class, object of a class which is already created, any ip address etc) which when invoked returns some response to service client. The different service invocation scenarios in java applications are


  1. invoking a method in the same class
  2. invoking a method in a class in same package
  3. invoking a method of  a class belonging to another package
  4. invoking a method of a class belonging to another library/jar
  5. invoking a method beloning to a class running in an different JVM in same machine
  6. invoking a method belonging to a class running in a different geographical location


The scenarios 1 to 4 all come under local service scenarios. If you see closely no additional hardware/software apart from JVM and jars are needed for the above service communication.


In scenario 5 think as if in a same host we have two JVMs running and an object in JVM1 wants to invoke service provided by another object in JVM2.

In scenario 6 the JVM's are not in the same host or not even the same network. One machine is in india and another is in France. To make this communication happen something additional is needed. The typical steps in this communication would be


  • Send the client request over some network via some protocol
  • Client can optionally say how his request looks like what response he is expected etc
  • Service checks the request and prepares the response
  • Server may optionally modify the response to the way the client requested before sending it.


Java community has tried addressing this problem in many ways. The different solutions that they came up with are

  • Java RMI (Remote method invocation) - Uses RPC protocol over ftp/http
  • JMS (Java Messaging Service) - Uses messaging protocol  over ftp/http
  • JAX-WS (Java Api for Xml- Web Services) - Uses SOAP protocol over http
  • JAX-RS (Java Api for Restful  Web Services) - Uses No protocol but based on http



Only JAX-WS and JAX-RS are termed as web services because they use http protocol internally to allow client server communication happen. Of these two JAX-RS is even more easier as it does not have any protocol to follow where as JAX-WS has to follow SOAP.

In the next tutorial we will talk in detail JAX-WS and JAX-RS.