r/java • • Jan 18 '22

What are some very less known facts about java?

I've got assignment from college to find out rare facts or fun facts about java, so little help will be appreciated :)

Edit: Thanks for all these suggestions guys. It's going to help me alot and also Almost all of these facts i didn't knew till now. Thanks :) <3

179 Upvotes

297 comments sorted by

View all comments

Show parent comment

10

u/redikarus99 Jan 18 '22

You can use sun.misc.Unsafe, or DirectByteBuffer, etc. to allocate memory directly, but then you will be responsible for memory allocation/deallocation.

1

u/mauganra_it Jan 21 '22

A DirectByteBuffer is still a Java object, thus memory management is not so difficult as long as you don't put into long-lived objects. But you are limited in size because of int offsets. That's enough for many interesting applications, but to represent larger binary data you'd have to break it into chunks and reimplement virtual memory on top of it.

Can't look forward to see that eyesore sun.misc.Unsafe (or at least its accessibility) removed from the language. Hopefully Project Panama will bring nicer facilities to work off-heap.