Writing simple RESTful Web Service



RESTful web services are POJOs that are annotated with @javax.ws.rs.Path and contains one method.

@Path("/item")
public class ItemRestService {

@GET
@Produces("text/plain")
public String getItemTitle() {
return "New_Item";
}
}

here ItemRestService is class annotated with @Path("/item"), idicates that the item will be hosted at URI path "/item".
The method getItemTitle() is annotated with @GET indicating it will serve the http get request and it will produce the text.

Requirements to write a REST service
The class must be annotated with @javax.ws.rs.Path (in JAX-RS 2.0 there is no XML
equivalent to meta-data as there is no deployment descriptor).

The class must be defined as public, and it must not be final or abstract.

Root resource classes (classes with a @Path annotation) must have a default public constructor.Non-root resource classes do not require such a constructor.

The class must not define the finalize() method.


Ref:  Beginning JavaEE7