Posts

Showing posts from April, 2018

Faster Repeated Access to Java Class Names Coming to Java?

Claes Redestad has posted the message " RRF: 8187123: (reflect) Class#getCanonicalName and Class#getSimpleName is a part of performance issue " on the core-libs-dev mailing list in which he requests review of a proposed change "to enable caching of getCanonicalName and getSimpleName , repeated calls of which has been reported to be a performance bottleneck." He adds that "the caching improves performance of these methods by up to 20x." An obvious solution to the performance issue might have been to add the name of the class as a field to the Class class definition, but Redestad points out in the associated bug JDK-8187123 that "we should avoid adding more fields to java.lang.Class ." Instead, this bug was addressed by the idea to " piggy back off other reflection information that is cached in ReflectionData ." ReflectionData is a nested ( private static ) class defined within the Class class. The Class class's reference to...

Recent Java Developments - Late April 2018

There have been several recent developments in the Java-sphere this week and I summarize some of them in this post. The End of JavaOne as We Know It In the post " JavaOne Event Expands with More Tracks, Languages and Communities – and New Name ," Stephen Chin writes, "The JavaOne conference is expanding to create a new, bigger event that’s inclusive to more languages, technologies and developer communities." He adds that it has been renamed to " Oracle Code One " and that this year's edition (the "inaugural year of Oracle Code One") will be held in San Francisco's Moscone West in late October (October 22-25, 2018). GraalVM: "Run Programs Faster Anywhere" In the 17 April 2018 post " Announcing GraalVM: Run Programs Faster Anywhere ," Thomas Wuerthinger and the GraalVM Team "present the first production-ready release" of "a universal virtual machine designed for a polyglot world" called GraalVM...

Enhancing Java switch Statement with Introduction of switch Expression

In late December of last year, I posted " Switch Expressions Coming to Java? " Since then, there has been significant discussion, expressed differences of opinion, and now a coalescence of general agreement regarding the future of switch expressions in Java . I have tried to capture some of the major developments related to switch expressions as comments on my December blog post . However, I felt like this week's Brian Goetz message title " [switch] Further unification on switch " on the amber-spec-observers mailing list warranted a new blog post on Java switch expressions. Goetz opens his message with a reminder that the end game is not Java switch expressions . Instead, Goetz points out that "switch expressions are supposed to just be an uncontroversial waypoint on the way to the real goal, which is a more expressive and flexible switch construct that works in a wider variety of situations, including supporting patterns, being less hostile to null, u...

Java-Related April Fools Day Pranks

Although you'd never catch me stooping to this level , it has been interesting over the years to see some of the effort and thought put into Java-related April Fools' Day pranks. This post references and summarizes some of them. Google Annotations Gallery ( gag ) The Google Annotations Gallery (cleverly abbreviated as 'gag') is hosted on Google Code , so you may want to download that as soon as possible so that you do not miss out on it . Both gag-1.0.zip (original release) and gag-1.0.1.zip (supplements original release to "add many great user-suggested annotations"). These ZIP files include actual Java source code with the libraries that gag depends on. Some of my favorite annotations provided by gag are @AhaMoment , @Blame , @BossMadeMeDoIt , @Facepalm , @Hack , @HandsOff , @IAmAwesome , @LegacySucks , @Magic , @Noop , and @OhNoYouDidnt . I also enjoy the WHERE enumeration provided by 'gag' to allow one to specify "where" a par...

JDK 11 Early Access Build 8

In the message " JDK 11 Early Access build 8 available ," Muneer Kolarkunnu announces that " JDK 11 EA build 8 , under both the GPL and Oracle EA licenses , is now available at http://jdk.java.net/11 ." Kolarkunnu specifically highlights Build 8's changes to the Selector API that have been discussed on the nio-dev mailing list in threads such as Callback Based Selectors and More Selector Cleanup . The JDK 11 EA Build 8 announcement also mentions that "VM option ' -XX:+AggressiveOpts ' is deprecated in JDK 11 and will be removed in a future release" as of Build 7. The announcement highlights JDK-8193033 ("Release Note: remove terminally deprecated sun.misc.Unsafe.defineClass") in Build 6 and reminds that "users should use the public replacement ' java.lang.invoke.MethodHandles . Lookup . defineClass ' which was added in Java SE 9 ." The " JDK 11 Early-Access Builds " page referenced in the announcem...

Optional.isEmpty() Coming to Java?

JDK-8184693 requests that the method isEmpty() be added to the Optional class introduced with JDK 8 . Invoking Optional.isEmpty() would be the equivalent of invoking ! Optional.isPresent() . There is no JDK release currently associated with JDK-8184693 , but it is being actively worked as demonstrated in a recent core-libs-dev mailing list post titled " RFR: 8184693: (opt) add Optional.isEmpty ". Written by Stuart Marks in July 2017, JDK-8184693 provides some interesting justification for the addition of Optional.isEmpty() . Marks points out that "generally we avoid adding methods that are simple inverses of each other" and cites as examples presence of String.isEmpty() and Collection.isEmpty() without any accompanying String.notEmpty() or Collection.nonEmpty() counterparts. Marks writes this approach works well in these cases because "emptiness/non-emptiness isn't fundamental" for them: "For these objects, it's perfectly reasonabl...

Updates on Records (Data Classes for Java)

There have been several updates related to "Java Data Classes" (AKA "Records") in recent months. As I briefly mentioned in the post " Updates on JavaFX, Valhalla, Data Classes, and Java's Floating-Point ," Brian Goetz 's " Data Classes for Java " "explores possible directions for data classes in the Java Language." Sadly, despite significant discussion on this potential new Java feature on the OpenJDK mailing lists , this document also points out, "This is an exploratory document only and does not constitute a plan for any specific feature in any specific version of the Java Language." In mid-March, Goetz posted a message to the amber-spec-experts mailing list titled " Records -- current status ." He states the intent of records in Java in that message: "Our goal all along has been to define records as being 'just macros' for a finer-grained set of features. Some of these are motivated by boil...

Clearer Code with JDK 10 Local Variable Type Inference

One of the first fruits of Project Amber , Local-Variable Type Inference ( JEP 286 ), has been delivered with JDK 10 . JEP 286's "Summary" describes its purpose, "Enhance the Java Language to extend type inference to declarations of local variables with initializers." In conjunction with this release, Stuart Marks has published the March 2018 article " Style Guidelines for Local Variable Type Inference in Java ." In " Style Guidelines for Local Variable Type Inference in Java ," Marks postulates four "Principles" that lead to seven "Guidelines" that help developers to apply var properly to "help improve good code, making it shorter and clearer without compromising understandability." The articulated guidelines attempt to strike a balance that brings benefits of less redundant code with the benefits of explicitly readable code. The article outlines cases where var should be used and where it shouldn't be...