Linux: which process consumed all the memory?
Ah, I see you have mistaken how to calculate free RAM in Linux.
Linux tends to heavily utilize all the RAM by caching stuff. Instead of reading directory listing from the disk every time, it caches the directory entries in RAM. It caches the frequently used files, so they don't need to be loaded from the disk every time. In case some process actually needs the RAM for its use, the cache will be immediately evicted.
So the formula for calculating the actually used RAM is total - (free + buffers + cached), in your case 3988 - (219 + 165 + 1894) or in other words 3988 - 2278. That is 1710 megabytes of RAM in use and 2278 megabytes of RAM for you still to consume.
Don't believe me? See, your server doesn't even have any swap in use. :)
But of course, a machine crash -- if you mean a hard lock up -- is a strange thing. That really should not happen. I suspect a faulty RAM stick which only gets accessed in case of >2 GB of RAM in use.
I only see older cpu options, so I suspect you have only a 32 bit cpu, but you should be able to use all 4GB, though you may need to investigate how to make that work the way you want (might need to enable PAE, for instance).
And do you mean the java app crashes, or the whole machine? The machine should not crash (though it may become unresponsive for a bit).