how to use the ContactListener

I'm not sure where you're having trouble, I don't want to jump to conclusions and assume it's at a basic level but...

The ContactListener is going to be your own code, in Java terminology you implement the interface and set an instance of your new class to be the listener. This is your hook into the engine, as now whenever a contact occurs *your code* is called.

Bill
You must create a subclass of b2ContactListener which implements Add(), Persist() and Remove(), create an instance of that subclass, then add it to the world via SetListener();

I had to dig through the source myself to figure this out...

Original thread: https://box2d.org/forum/viewtopic.php?t=730