1- You must install a pre-designed chat server. There are many solutions available. I advise you to choose Ejabberd ( http://www.ejabberd.im/ ). This is a chat server that is used using Erlang and is considered a highly scalable server. This is the same as on the facebook chat server, note that in the beginning facebook only used one server to process all its chat traffic around the world.
2- You need to integrate js client chat, which will interact with the chat server. There is also a cool open source solution for ijab ( http://code.google.com/p/ijab/ ). You must configure it to connect to your server.
3- , java- java, . ejabberd. java-, .
,