GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing javaevolved.dev โ Module import declarations | java.evolved
Language
Intermediate
Module import declarationsImport all exported packages of a module with a single declaration. Code Comparison
โ Java 8
import java.util.List; import java.util.Map; import java.util.stream.Collectors; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path;
โ Java 25+
import module java.base; // All of java.util, java.io, java.nio // etc. available in one line
See a problem with this code? Let us know.
Why the modern way wins
๐งน
One lineReplace a wall of imports with a single module import. ๐ฆ
Module-awareLeverages the module system to import coherent sets of packages. ๐
Quick startsPerfect for scripts and prototypes where import lists are tedious. Old Approach
Many Imports
Modern Approach
import module
Since JDK
25
Difficulty
Intermediate
JDK Support
Module import declarations
Available
Finalized in JDK 25 LTS (JEP 511, Sept 2025). How it works
Module import declarations let you import everything a module exports with one line. This is especially useful for java.base which covers collections, I/O, streams, and more. Related Documentation
Proof
Related patterns
Language
Beginner
Type inference with varJava 8
Map<String, List<Integer>> map =
new HashMap<String, List<Integer>>();
for (Map.Entry<String, List<Integer>> e
: map.entrySet()) {
// verbose type noise
}
Java 10+
var map = new HashMap<String, List<Integer>>();
for (var entry : map.entrySet()) {
// clean and readable
}
JDK 10+
โ
Language
Beginner
Text blocks for multiline stringsJava 8
String json = "{\n" +
" \"name\": \"Duke\",\n" +
" \"age\": 30\n" +
"}";
Java 15+
String json = """
{
"name": "Duke",
"age": 30
}""";
JDK 15+
โ
Language
Beginner
Switch expressionsJava 8
String msg;
switch (day) {
case MONDAY:
msg = "Start";
break;
case FRIDAY:
msg = "End";
break;
default:
msg = "Mid";
}
Java 14+
String msg = switch (day) {
case MONDAY -> "Start";
case FRIDAY -> "End";
default -> "Mid";
};
JDK 14+
โ
|
| You are visitor 01402503 โ GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800ร600. No cookies required. |