You need to write it in native code (not java) - java doesn't give you low-enough level access to the NIC hardware to do this kind of thing efficiently.
However, in 99% of cases you dont want what you asked for, you instead just want to know "which ip addresses are also running a copy of my app?". In which case, just look at the javadocs for the "broadcast" parts of UDP.
NB: the 1% includes people writing viruses, which has long been used as the semi-official excuse for not providing lower-level decenta access. Pisses me off, because you can't write really good, efficient, intelligent P2P cluster code like this. Grumble grumble