<p>I need to check CPU and memory usage for the server in java, anyone know how it could be done?</p>

If you are using Tomcat, check out
Psi Probe
, which lets you monitor internal and external memory consumption as well as a host of other areas.