1202 stories
·
3 followers

Photo

1 Share


Read the whole story
robertdx
1 day ago
reply
Pittsburgh, Pennsylvania
Share this story
Delete

Java 9 and IntelliJ IDEA

2 Shares
Comments

Java 9 is released today, so let’s do a quick recap of the Java 9 support in IntelliJ IDEA, and have a peek at some of the upcoming features in IntelliJ IDEA 2017.3 for Java 9.

Jigsaw & the JPMS

The big feature for Java 9 is, of course, the Java Platform Module System (JPMS), which comes under the umbrella Project Jigsaw.  Jigsaw itself is a much bigger undertaking and includes things like the modularisation of the JDK itself, what’s interesting to us as developers is the JPMS.

IntelliJ IDEA supports the Java Platform Module System with a number of features.

You can easily create a module-info.java file for your IntelliJ IDEA modules:

01-new-module-info

This will give you the basic structure of your module declaration, including a module name that matches the name of your IntelliJ IDEA module.  While you’re working in this file you get code highlighting and completion of course.

If you run code from a module with a module-info.java file, IntelliJ IDEA will automatically use the -p argument (module path) instead of -classpath.

03-module-path

IntelliJ IDEA also offers quick fixes for some of the common problems you’ll face as you migrate your code to the JPMS, such as the ability to add a “requires” directive

04-quick-fixes

or detection of duplicate directives or other errors that can be fixed

05-delete-duplicate

IntelliJ IDEA also lets you create module diagrams to help you visualise the modules you’re using.  You can see JDK modules, your own modules and automatic modules in different colours, and transitive requirements are highlighted with a stronger line.

These diagrams are particularly useful when you’re getting started with modularity, as they help you understand which modules you’re using and where they come from.  You can even navigate to the modules from the diagram.

IntelliJ IDEA has inspections to help migrate code to Java 9. For example, you can highlight the use of automatic modules.

07-automatic-modules

This means you can see if you’re dependent on something that isn’t a true Java 9 module. This is important as these automatic modules may change over time.

08-warning-on-automatic-module

Find out more about basic support for modules in IntelliJ IDEA, and module diagrams and additional quick fixes.

Convenience Factory Methods

Java 9 introduces a lot of small API changes that made life easier for developers. One of these is to simplify the creation of Collections with fixed contents.  IntelliJ IDEA has an inspection which can show you where you can use this feature.

07-immutable-collections

This will highlight code that can be simplified by using the Java 9 factory methods

Thread.onSpinWait

Java 9 lets you give hints to the JVM that can help performance.  Specifically, if your code is spinning in a loop waiting for something to happen, you can use Thread.onSpinWait to let the runtime know. IntelliJ IDEA locates code where this hint may be useful, and can add it.

10-on-spin-wait

This inspection and the one for Convenience Factory Methods were covered previously in the blog post and video on Java 9 support in IntelliJ IDEA 2017.2.

Enhanced Deprecation

Another seemingly small feature in Java 9 that makes it easier for developers to understand the impact of their code is enhanced deprecation.  Now instead of merely tagging code as deprecated and (possibly) documenting the reasons in the Javadoc, the @Deprecated tag supports two useful new attributes, “since” and “forRemoval”.  There’s a new inspection in IntelliJ IDEA 2017.3 that highlights any use of code that has been marked “forRemoval”.

11-for-removal-inspection

If you’ve got this inspection turned on and set to “Warning” (which is the default), then when you’re using something that’s been tagged as “forRemoval”, IntelliJ IDEA will strike this method through in red, rather than the usual black.

12-deprecated

JShell

Java 9 comes with a REPL for Java for the first time, called JShell.  You can run this REPL from the command line, or from the terminal inside IntelliJ IDEA.  In addition, IntelliJ IDEA 2017.3 also has a basic console that allows you to work with JShell from inside the IDE, similar to the Groovy Console.

13-jshell-menu

You can use this console to try out code snippets, and you will be able to select the module path for running this code.

This is currently available in the 2017.3 EAP.  Please try it out and give us feedback!

Features that don’t need extra support

There are loads of new features in Java 9, including changes to the Streams API, additions to Optional, private methods on interfaces, and more.

15-streams

Of course these new methods are all available during code completion if your project code level is set to Java 9.

16-project-language

In addition, you can use the usual features of IntelliJ IDEA to take advantage of some of the Java 9 features.  For example, you can generate HTML 5 Javadoc by adding a flag when you generate your documentation.

17-html5

You can even use IntelliJ IDEA to create Multi-Release Jar Files.  This is probably something that’s best left to build tools like Gradle, Maven or Ant, but it is possible in IntelliJ IDEA, and will be the subject of a later blog post.

All that remains is to say “Welcome Java 9!  We’re ready for you!”


Comments
Read the whole story
robertdx
1 day ago
reply
Pittsburgh, Pennsylvania
fxer
2 days ago
reply
Bend, Oregon
Share this story
Delete

Ketchup

1 Share

Read the whole story
robertdx
2 days ago
reply
Pittsburgh, Pennsylvania
Share this story
Delete

Beautiful 30-day time lapse of a cargo ship’s voyage

4 Shares

Jeffrey Tsang is a sailor on a cargo ship. On a recent voyage from the Red Sea to Sri Lanka to Singapore to Hong Kong, he set up a camera facing the bow of the ship to record the month-long journey. From ~80,000 photos taken, he constructed a 10-minute time lapse that somehow manages to be both meditative and informative. You get to see cargo operations at a few different ports, sunrises, thunderstorms, and the clearest night skies you’ve ever seen. Highly recommended viewing. (via colossal)

Tags: time lapse   video
Read the whole story
robertdx
2 days ago
reply
Pittsburgh, Pennsylvania
samuel
5 days ago
reply
The Haight in San Francisco
Share this story
Delete

Photo

1 Share


Read the whole story
robertdx
2 days ago
reply
Pittsburgh, Pennsylvania
Share this story
Delete

Photo

1 Share


Read the whole story
robertdx
4 days ago
reply
Pittsburgh, Pennsylvania
Share this story
Delete
Next Page of Stories