I guess you'll need to setup a Database where you want to register every single message send from the clients while updating said clients to make sure they get the last messages added to the database.
You're going to need JSON as it's probably the best way to exchange informations between server and client, here are some functions you should look at to handle the JSON parsing part.
What is a JSON object : (just to be clear) A .json file contains text-based representations of data structures and objects. A JSON object is delimited by "{" and "}" and represent a single object/structure inside a .json file.
JSONObject : It's a type representing a single JSON object in JAVA.
JSONArray : Seems obvious, but it's an array wich contains JSONObject elements,
i recommend you to use this to keep your objects packed into an array,
this type is providing a lot of usefull methods aswell as JSONObject does,
i'll list some of them below it's up to you to search for the others.
JSONArray.getJSONObject(index) : Pass it an index and it will return the JSONObject stored
at this index.
JSONArray.put([value] | [index, value]) : This might be extremly straightforward but it's actually pretty
usefull if you want to build a JSONArray, pass it a JSONObject
or another common type (int, String, etc) and it will add it to
your JSONArray.
Depending on what you pass it you'll need an index aswell.
JSONObject.keys() : Returns an iterator of the String names in your JSONObject.
JSONObject.put(name, value) : Create a field in your JSONObject using the name you passed
and assigning the value to it.
JSONObject.getString(name) : Pass the name of a field to it and it will return
it's value as a String. As you may have guess already, there is a couple of those, not only getString().
As for the Database connexion and interaction part it can differ depending on what you chose to use and how you chose to do it (you could directly access your DB and it's data or use HTTP calls using the HttpClient Java class to recover the data the same way as you'll do with an API), there is plenty of tutorial, i'am gonna update this with some links (can't remember them at the moment).
Hope this will help guiding you own researches.
The rest is up to you.