If you want to run some java code(In server) and get the response in your javascript(in client). You can use Ajax in jquery.
http://api.jquery.com/jQuery.ajax/
Remember this is for java (advance) programming.
solved how to call java object in javascript?