Live Webinar: Real World Java 9

Java 9 was released just yesterday! Read about Java 9 and IntelliJ IDEA in this blog post. If you want to know even more about Java 9, we invite you to join our free webinar, Real World Java 9, with Trisha Gee, taking place Tuesday, October 3, at 16:00 – 17:00 CEST.

In this presentation Trisha will code live to show you:

  • What the Java Platform Module System is and how to make your code modular
  • How we can use the new Flow API to utilize Reactive Programming
  • The improvements to the Streams API that make it easier to control infinite streams
  • How to the Collections convenience methods simplify code

We hope to see you there! Don’t be shy – register now!

Speaking to you

Trisha_Gee Trisha Gee https://twitter.com/trisha_gee

Trisha has developed Java applications for a range of industries, including finance, manufacturing, software and non-profit, for companies of all sizes. She has expertise in Java high-performance systems, is passionate about enabling developer productivity, and dabbles with Open Source development. Trisha is a leader of the Sevilla Java User Group and a Java Champion. She believes healthy communities and sharing ideas help us to learn from mistakes and build on successes. As a Developer Advocate for JetBrains, she gets to share all the interesting things she’s constantly discovering.

Posted in Beta Releases | Leave a comment

IntelliJ IDEA 2017.3 EAP: Better Synchronization of your Settings Across Devices and Other improvements

Today we’re publishing a new IntelliJ IDEA 2017.3 EAP build, which includes some very interesting features. Let’s have a look! Continue reading

Posted in EAP Releases, New Features | Tagged , | 9 Comments

Java 9 and IntelliJ IDEA

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!”

UPDATE: Join us Tuesday, October 3, at 16:00 – 17:00 CEST, for our free live webinar, Real World Java 9. Register now!

Posted in EAP Releases, New Features, Tips & Tricks | Tagged | Leave a comment

Code Smells: Too Many Problems

Or: argh! Where do I start?!

This is part of a series investigating code that looks suspicious (“code smells”), and exploring possible alternatives.

For the middle articles of this series, we’ve been focusing on a single method, and demonstrating how to improve this method, one smell at a time.  While it has been… useful… that a single method has demonstrated so many smells, if you came across that method in real life it wouldn’t be obvious what to do with it.

Continue reading

Posted in Tips & Tricks | Tagged , | 6 Comments

What IntelliJ IDEA 2017.3 EAP Brings to Database Tools

We’ve recently announced the opening of the EAP for IntelliJ IDEA 2017.3, and we have already even looked at some of the interesting EAP features. However, we didn’t cover changes in the database tools yet. So let’s explore the major changes in this area.

Selecting schema when running SQL file

IntelliJ IDEA 2017.3 now prompts you to choose database/schema along with a datasource when you try to run an SQL file from the Project tool window:

Screen Shot 2017-09-14 at 12.27.17

Jumping to console from datasource

For easier navigation, the context menu on a datasource in the Database tool window was upgraded.  Choose Jump to Console  and you’ll now have a handy menu which allows you to quickly switch between your consoles. 

Screen Shot 2017-09-15 at 16.11.50

Screen Shot 2017-09-15 at 16.43.08

Right-side alignment for numeric data

For better readability, the IDE aligns the data in the table editor for numerical columns with the right side:

Screen Shot 2017-09-14 at 16.54.00

XQuery and XPath coding assistance for Microsoft SQL Server

Last but not least, the XQuery/XPath support for Microsoft SQL Server is now provided through the Injected Languages feature:

Screen Shot 2017-09-14 at 17.04.07

Place the caret to a needed code fragment and press Alt+Enter. Then choose Inject language or reference, and select XQuery or XPath:

Screen Shot 2017-09-14 at 16.22.48

Since the feature has been asked for by some of our users, we backported it to IntelliJ IDEA 2017.2 as well.

To give these new features a try, download the EAP build. And as usual, bug reports along with your feedback, are very welcome in our issue tracker.

The Drive to Develop!

Posted in EAP Releases, New Features | Tagged , , , | 1 Comment

What’s New in IntelliJ IDEA 2017.3 EAP?

Last week we announced the opening of the EAP for IntelliJ IDEA 2017.3, the upcoming IDE update which will be released this fall. In the announcement we briefly mentioned some of the major changes the update will deliver. Let’s talk about them in a bit more detail.

Continue reading

Posted in EAP Releases, New Features | Tagged , | 8 Comments

Code Smells: If Statements

This is part of a series investigating code that looks suspicious (“code smells”), and exploring possible alternatives.

The article in this series that has so far provoked the most responses was on iteration.  Today, I’m talking about if statements (conditionals). I’m not intending to go after any sacred cows or anything – for loops and if statements are pretty much the first things we learn in many programming languages.  They’re a fundamental part of languages like Java.  But just because these basic building blocks exist doesn’t mean they should be our goto strategy (see what I did there?) every time.  We could program in assembler but we don’t. We could use a hammer for every job around the house, but we don’t (well…).

If statements are very useful, and often the right tool for the job, but they can also be a smell.  Remember that by “smell” I mean “code that you should look carefully at to see if there’s a simpler/easier to understand, approach”. I don’t mean “if statements are evil never use them”.

Continue reading

Posted in Tips & Tricks | Tagged , | 8 Comments

Code Smells: Multi-Responsibility Methods

This is part of a series investigating code that looks suspicious (“code smells”), and exploring possible alternatives.

In the last article I introduced a large and complex method, validateQuery.  The focus of that article was how to simplify the method looking only at the “smell” of mutability, but there’s actually one very simple change that can chop the method nearly in half.

Continue reading

Posted in Tips & Tricks | Tagged , | 4 Comments

Java Annotated Monthly – September 2017

The major news in August was for Android, with the release of Oreo.  Other than that, the rest of the Java world seems to be holding its breath waiting for Java 9, due (finally!) this month. The lull in pure technology news gives us a chance to explore other topics that affect us as developers and members of a larger organisation, so this month we have a whole section on Culture.

JavaAnnotatedMonthly@2x

Continue reading

Posted in News & Events | Tagged | Leave a comment

Code Smells: Mutation

This is part of a series investigating code that looks suspicious (“code smells”), and exploring possible alternatives.

In the article about deeply nested code I wanted to change getMappedField to return an Optional value.  The change to the method was fairly trivial, the change to the code that calls that method… well, that turned out to be another matter altogether.

Continue reading

Posted in Tips & Tricks | Tagged , | 19 Comments