Shrouded in mystery, some say it's time for Java's Unsafe API to go -- or go public Last week news broke that some developers are up in arms, claiming that Oracle’s proposed removal of sun.misc.Unsafe in Java 9 will wreck the Java ecosystem. For many developers not embroiled in low-level programming, however, the private API is likely shrouded in mystery. What is this API so dangerous that its very name is unsafe? Blogger and open source contributor Rafael Winterhalter explains in “Understanding sun.misc.Unsafe” that unsafe code is often required for low-level programming, where developers modify platform functionality for a specific purpose. While JNI (Java Native Interface) is considered the safest option for low-level Java programming, many open source projects have used Unsafe as a less constrained workaround. Winterhalter presents one of several examples utilizing Unsafe to overcome a Java programming hurdle: The first time I made use of the Unsafe class was for creating an instance of a class without calling any of the class’s constructors. I needed to proxy an entire class which only had a rather noisy constructor but I only wanted to delegate all method invocations to a real instance […] Creating a subclass was easy and if the class had been represented by an interface, creating a proxy would have been a straight-forward task. With the expensive constructor, I was however stuck. By using the Unsafe class, I was however able to work my way around it. See “Understanding sun.misc.Unsafe” and “Java magic, Part 4: sun.misc.Unsafe” for additional examples that demonstrate the why and how of using Unsafe in Java programs. Related content news analysis JSF 2.3 aims to be the default MVC framework for Java EE By Java Everywhere Jun 25, 2015 1 min Jakarta EE Web Development Java feature Can TDD factions agree to disagree? By Java Everywhere Jun 24, 2014 2 mins Core Java Web Development App Testing feature What would you do to improve dynamic proxies? By Java Everywhere Apr 22, 2014 2 mins Core Java Java ME Technology Industry tip Coding conventions: 9 areas where developers actually agree To code is to care -- about programming conventions that is By Phil Johnson Feb 25, 2014 1 min Core Java Java ME Technology Industry Resources Videos