How can i create a dangling pointer using Java?
Not available on all JVMs, but Sun's JVM does give you sun.misc.unsafe#allocateMemory(long bytes). That call returns a pointer.
sun.misc.unsafe#allocateMemory(long bytes)
sun.misc.unsafe#freeMemory(long address) frees that memory. Your initial pointer is now "dangling".
sun.misc.unsafe#freeMemory(long address