I need to create some Java interfaces to query some database tables and some web services for new framework I'm building. In a previous Java Spring web application, I used Java Beans to handle the results of the query.

In this case, I need to write some interfaces to publish the methods that will be available to end users. I'm a little bit of a newbie in this particular aspect of Java and I was wondering: is it better to allow the end user to see and use the Java beans in JSP, or to hide them using some generic type?

  • 1
    So you need to expose what queries can be run via a Web Service of some sort? Can you elaborate on how the end user is viewing/interacting with this? Via a web browser or a client piece of software? Commented Feb 7, 2012 at 14:26
  • Web Service replies with an XML. End user will call this api from web application or portlet. Commented Feb 7, 2012 at 14:38
  • That sounds like a job for some kind of WSDL document to me
    – Andy Hunt
    Commented Feb 7, 2012 at 14:46
  • 1
    Hi Andrea, it's okay and encouraged to ask your question directly instead of asking people for tutorials to answer your question. I've reworded your title to make it clearer what you're looking for: feel free to modify it if I missed the mark.
    – user8
    Commented Feb 7, 2012 at 18:39

3 Answers 3


It's okay to use those Java beans (which I'll call domain objects) to hold the results for a query. Then if you need to return them as a web service, you'll use the service to convert those objects to JSON or the desired format.

  • Or XML if JSON doesn't float your boat. Commented Feb 7, 2012 at 19:52

You sound like you want what is known as a Service Repository or a Service Registry. The following diagram I found on Wikipedia.

enter image description here

I have seen where a Service Repository had its own web service interface where one would request what kinds of web services and where the WSDL's are from a given component. The WSDL specifically will define what operations exist for the given service.

For more information on SOA, see Wikipedia.


I would definitely have them access your beans via interface types, to give you flexibility on the back end. It also provides more complete separation, as your UI code only depends on the interfaces (which can be kept in a separate jar file), not any particular implementation code. Plus, you can re-use front end code more easily. E.g., if you've got an address maintenance page, you can use it for anything that supports the IUpdatableAddress interface, regardless of whether it's a Person, Organization or Event. As long as you don't display or invoke anything that isn't part of the interface, you'll be fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.