Questions tagged [java-9]

Use this tag for questions specific to Java 9, which is version 9 of the Java platform, released on the 21st of September 2017. In most cases you should also specify the java tag.

Oracle has released its updated list of proposed or targeted Java 9 enhancements. In addition to previously confirmed Java modularity updates, the most recent list includes a common logging system for all JVM components (JEP 158), more HotSpot JIT compiler controls (JEP 158), and refinements to improve the efficiency of garbage collection (JEP 214), and repair issues introduced by Project Coin language updates in JDK 7 (JEP 213). This is also the first release under the new version-string schema (JEP 223) and will hence be officially be numbered 9, not "1.9.0" as was the case for earlier versions.

Even with delays, Oracle has been steadily moving forward with its plans to modularize the JDK. But the scope of Java modularity took a step up in September, when Oracle announced four new JEPs, including JEP 220: Modular Run-Time Images. Ben Evans, writing for InfoQ, noted that swapping JARs for modules is the "point of no return for modularity," with serious implications for IDEs, toolmakers, and many Java application frameworks:

After this point, The Java Runtime Environment (JRE) will no longer be contained in jar files, and instead will be composed of modules (JSR 376). Files such as rt.jar and tools.jar no longer exist in the JRE. The platform will continue to accept and run applications and libraries packaged in conventional jar files, modular jar files, or in the new module file format. The intention is that over time, application developers wil migrate to the new modular formats as well.

See "Oracle Commit to Java Modularity" for more from Ben Evans on modularity updates in Java 9. Also see Takipi Blog: "Java 9 – The Ultimate Feature List" for a comprehensive (as of November 20, 2014) description of new features accepted or proposed for the next major release of Java, and "What's New in Java 9? (Besides Modules)" for another more recent compilation of features.

The API documentation of the release can be accessed at Oracle's technetwork.

1606 questions
39
votes
3 answers

What is the use of Map.ofEntries() instead of Map.of()

From the documentation of Map.java - The Map.of() and Map.ofEntries() static factory methods provide a convenient way to create immutable maps. But when I already can use overloaded method ... Map.of("k1","v1","k2","v2","k3","v3"...); ... what is…
Mani
  • 1,068
  • 3
  • 13
  • 27
39
votes
1 answer

Correct way to use VarHandle in Java 9?

I have been spending much time investigating some of Java 9's new features, but I didn't find any useful and practical examples. Consider next code snippet that creates a VarHandle: class Counter { int i; } class VarHandleInAction { static…
Oleksandr Pyrohov
  • 14,685
  • 6
  • 61
  • 90
39
votes
2 answers

newInstance vs new in jdk-9/jdk-8 and jmh

I've seen a lot of threads here that compare and try to answer which is faster: newInstance or new operator. Looking at the source code, it would seem that newInstance should be much slower, I mean it does so many security checks and uses…
Eugene
  • 117,005
  • 15
  • 201
  • 306
37
votes
1 answer

JSR-305 annotations replacement for Java 9

So far we have been using the Findbugs JSR-305 annotations (com.google.code.findbugs:jsr305) and everything including tool support (Sonar, Eclipse, Findbugs, …) has been working fine. However it is our understanding that Jigsaw in Java 9 is going to…
36
votes
3 answers

How to resolve module reads package error in java9

I am trying to understand new modularity in java 9 with spring-boot so I want to run some simple application for example: https://github.com/tmatyashovsky/java9-springboot I am using maven 3.5.0 with java 9: Apache Maven 3.5.0…
hudi
  • 15,555
  • 47
  • 142
  • 246
36
votes
3 answers

How to shutdown jshell at the end of the script?

How to instruct jshell to terminate at the end of the script similarly to interpreters of other languages like for example python3 or node? Following command ./jshell -q /tmp/shell.java with script /tmp/shell.java System.out.println("Hello…
czerny
  • 15,090
  • 14
  • 68
  • 96
36
votes
4 answers

Does Project Lombok support Java 9?

I have used Lombok in my project, but my colleague do not agree to use it, and his reason is (from controversy of lombok documents) Both of these pieces of Project Lombok make use of non-public APIs to accomplish their sorcery. This means that…
zhuguowei
  • 8,401
  • 16
  • 70
  • 106
35
votes
3 answers

How to log request/response using java.net.http.HttpClient?

The HttpClient introduced experimentally in Java 9 is now stable in Java 11, but not surprisingly, very few projects seem to actually use it. Documentation is almost non-existing. One of the most commons asks while making a HTTP call is logging of…
Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219
34
votes
2 answers

Properly implementing Java modules in a Maven build with inter-module test dependencies

I have a multi-module project using Maven and Java. I am now trying to migrate to Java 9/10/11 and implement modules (as in JSR 376: Java Platform Module System, JPMS). As the project was already consisting of Maven modules, and the dependencies…
Harald K
  • 26,314
  • 7
  • 65
  • 111
34
votes
2 answers

Generics behavior differs in JDK 8 and 9

The following simple class (repo to reproduce it): import static org.hamcrest.*; import static org.junit.Assert.assertThat; import java.util.*; import org.junit.Test; public class TestGenerics { @Test public void thisShouldCompile() { …
alostale
  • 770
  • 1
  • 11
  • 21
34
votes
5 answers

In JShell, how to import classpath from a Maven project

I have a local Maven project under development. How can I launch jshell with the project class path with all the dependencies, so that I can test project or dependency classes inside JShell.
Jianwu Chen
  • 5,336
  • 3
  • 30
  • 35
34
votes
7 answers

Cassandra and Java 9 - ThreadPriorityPolicy=42 is outside the allowed range

Very recently I installed JDK 9 and Apache Cassandra from the official site. But now when I start cassandra in foreground, I get this message: apache-cassandra-3.11.1/bin$ ./cassandra -f [0.000s][warning][gc] -Xloggc is deprecated. Will use…
Martin Matak
  • 351
  • 1
  • 3
  • 8
34
votes
4 answers

Error:BUG! exception in phase 'class generation' in source unit '_BuildScript_' unsupported Target MODULE

I'm trying to create a new Java 9 project using gradle but right after project creation I received error from gradle: Error:BUG! exception in phase 'class generation' in source unit '_BuildScript_' unsupported Target MODULE Java version: 9 (build…
Michał Szewczyk
  • 7,540
  • 8
  • 35
  • 47
34
votes
14 answers

Error:java: invalid flag: -release

I use Java : Java(TM) SE Runtime Environment (build 9-ea+143) Java HotSpot(TM) 64- Bit Server VM (build 9-ea+143, mixed mode) and IntelliJ IDEA: IntelliJ IDEA 2016.2.5 Build #IU-162.2228.15, built on October 14, 2016 Get error when compiling:…
Sergii Getman
  • 3,845
  • 5
  • 34
  • 50
33
votes
5 answers

How to apply Filtering on groupBy in java streams

How do you group first and then apply filtering using Java streams? Example: Consider this Employee class: I want to group by Department with a list of an employee having a salary greater than 2000. public class Employee { private String…
Niraj Sonawane
  • 10,225
  • 10
  • 75
  • 104