Hidden Services are simply servers. Tor doesn't care, or know, about what exactly is serving the service - it could be a website, or an email server, or almost anything else.
If you can write a Server in Java (or use an existing one such as Jetty for a HTTP Server), then you can use it to serve a Hidden Service. You would configure it so that it will accept TCP connections only from localhost/127.0.0.1 on a port of your choosing. Further help with either configuring an existing Java Server, or writing your own is probably beyond the scope of this site.
You would then edit your Tor configuration file to tell it to publish a Hidden Service, where your Tor Client would forward the requests to the port you specified in your Server. For further details see the Tor Documentation, or other questions such as this onethis one. If you encounter an issue with this part of the setup, that problem may be on topic here, so further questions could be asked.