As Campbell says, you can add code to a specific class to count the instances. I agree with him that wanting to do this hints at poor design, although one cannot be sure without knowing your reason for wanting to do it.
If you are looking for a way to find the number of instances of any arbitrary class, there is no way to do this with the ordinary
Java API.
The JVM has several debugging, monitoring and profiling interfaces these days. I believe that one or more of these will be able to tell you how many instances there are of a particular class. But these interfaces are not intended to be used as part of an application; it might not even be possible to do so.