Question: I have a requirement to store user ids appending with numbers like:

If user id is "stackoverflow", then first 7 letters of id "stackov" is taken and if it not there in the DataBase then it should be stored as "stackov001".

Now if another user gives similar user id as "stackoverflowed" then its user id should be stored as "stackov002" because 

I tried this by using substring but i am not able to get "00". I am able to get "stackov1" "stackov2" but not "stackov001".

Can soemone please help on this.

Answer: 
`XmxSIZE` can be greater then Java core dump because `OutOfMemory` happen when you try to allocate a large object!

Our application with `-Xmx1000m` and 670 MiB dump crashed by `OutOfMemory` on uploading 300 MiB attachment by a user.

We discover this in VisualVM in "Show Threads" trace on `System.arrayCopy`. Reference from local stack frame variable point to 300 MiB byte array.

Now we limit attachment size and save our application from future crashes.
The Salah reply is wrong at so many levels I would consider this outright harmful. 

First, the JVM will not trigger Stop The World GC and clean out heap just before dying with OutOfMemoryError. The reason for OOM is that the GC has failed to clean the memory, usually during tens and hundreds of runs prior the OOM.

Second, the recommended ratios are not actually recommended by JVM vendors. The best ratios are heavily application dependent, so without knowing what you are doing you are better off keeping the defaults than following this advice.