How can I use pointers in Java?

All objects in Java are references and you can use them like pointers. abstract class Animal {… } class Lion extends Animal {… } class Tiger extends Animal { public Tiger() {…} public void growl(){…} } Tiger first = null; Tiger second = new Tiger(); Tiger third; Dereferencing a null: first.growl(); // ERROR, first is … Read more

Why does sun.misc.Unsafe exist, and how can it be used in the real world?

examples VM “intrinsification.” ie CAS (Compare-And-Swap) used in Lock-Free Hash Tables eg:sun.misc.Unsafe.compareAndSwapInt it can make real JNI calls into native code that contains special instructions for CAS read more about CAS here http://en.wikipedia.org/wiki/Compare-and-swap The sun.misc.Unsafe functionality of the host VM can be used to allocate uninitialized objects and then interpret the constructor invocation as any … Read more