Version | Release Data | Notes | Important New Features |
---|---|---|---|
JDK 1.0 | January 1996 | ||
J2SE 5.0 | September 2004 | 5 releases in 8 years | Enhanced For Loop, Generics, Enums, Autoboxing |
Java SE 8 LTS | March 2014 | Functional Programming (Lambdas, Streams, …) & static and default methods in interface s |
Version | Release Data | Notes | Important New Features |
---|---|---|---|
Java SE 9 | September 2017 | 4 releases in 13 years | Modularization (Java Platform Module System) & JShell |
Java SE 10 (18.3) | March 2018 | The new (time-based) versioning system! | Local Variable Type Inference |
Java SE 11 (18.9) LTS | September 2018 | First new Long Term Support Version |
Version | Release Data | Notes | Important New Features |
---|---|---|---|
Java SE 12 (19.3) | March 2019 | ||
Java SE 13 (19.9) | September 2019 | ||
Java SE 14 (20.3) | March 2020 | switch expressions |
Version | Release Data | Notes | Important New Features |
---|---|---|---|
Java SE 15 (20.9) | September 2020 | Text blocks | |
Java SE 16 (21.3) | March 2021 | Latest Version | record classes |
Java SE 17 (21.9) LTS | September 2021 | The next LTS version |
REPL
), which evaluates declarations, statements, and expressions as they are entered and immediately shows the results.JPMS
)Modularity adds a higher level of aggregation above package
s.
The key new language element is the module
:
public interface MyInterface {
void normalInterfaceMethod();
default void interfaceMethodWithDefault() { init(); }
default void anotherDefaultMethod() { init(); }
// This method is not part of the public API exposed by MyInterface
private void init() { System.out.println("Initializing"); }
// This method is not part of the public API exposed by MyInterface
private static void doSomething() { System.out.println("Doing Something!"); }
}
Set<Integer> ints = Set.of(1, 2, 3);
List<String> strings = List.of("first", "second");
String message1 = "Good bye, Java 9";
var message2 = "Hello, Java 10";
Map<Integer, String> map = new HashMap<>();
var idToNameMap = new HashMap<Integer, String>();
It cannot be used for member variables, method parameters, return types, etc.
The initializer is required as without which compiler won’t be able to infer the type.
It is not always a good idea to use a var
.
var result = obj.prcoess();
var x = emp.getProjects.stream()
.findFirst()
.map(String::length)
.orElse(0);
JVMs are now aware of being run in a Docker container and will extract container-specific configuration instead of querying the operating system itself.
This support is only available for Linux-based platforms
java.util.List
, java.util.Map
and java.util.Set
each got a new static method copyOf(#collection#)
.List<Integer> copyList = List.copyOf(someIntList);
java.lang.UnsupportedOperationException
runtime exception.java.util.stream.Collectors
get additional methods to collect a Stream into an unmodifiable List
, Map
or Set
.List<Integer> evenList = someIntList.stream()
.filter(i -> i % 2 == 0)
.collect(Collectors.toUnmodifiableList());
java.lang.UnsupportedOperationException
runtime exception.isBlank
: Empty Strings and Strings with only white spaces are treated as blank.System.out.println(" ".isBlank()); // true
System.out.println("Noor".isBlank()); // false
System.out.println("".isBlank()); // true
lines
: Returns a stream of strings, which is a collection of all substrings split by lines.String str = "First\nSecond\nThird";
System.out.println(str);
System.out.println("---");
System.out.println(str.lines().collect(Collectors.toList()));
This will result in the following output:
First
Second
Third
---
[First, Second, Third]
strip
: Removes the white space from both, beginning, and the end of string.stripLeading
: Removes the white space from the beginning of string.stripTrailing
: Removes the white space from the end of string.String str = " Noor ";
System.out.println("|" + str + "|"); // | Noor |
System.out.println("|" + str.strip() + "|"); // |Noor|
System.out.println("|" + str.stripLeading() + "|"); // |Noor |
System.out.println("|" + str.stripTrailing() + "|"); // | Noor|
repeat
: Returns a string whose value is the concatenation of this string repeated count
times.System.out.println("=".repeat(10)); // ==========
readString
and writeString
static methods from the Files class.import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
public class StringMethods {
public static void main(String[] args) throws IOException {
Path filePath = Files.createFile(Path.of("file.txt"));
// writeString: will wtite a string to the file
Files.writeString(filePath, "Sample text");
// readString: will read the file as a string
String fileContent = Files.readString(filePath);
System.out.println(fileContent); // Sample text
}
}
not
Predicate Methodimport java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
public class StringMethods {
public static void main(String[] args) {
List<String> sampleList = List.of("Hello", "\n \n", "World", " ", "");
// Java 10 and before
List<String> notEmptyStrings10 = sampleList.stream()
.filter(s -> !s.isBlank())
.collect(Collectors.toList());
System.out.println(notEmptyStrings10); // [Hello, World]
// Java 11
List<String> notEmptyStrings11 = sampleList.stream()
.filter(Predicate.not(String::isBlank))
.collect(Collectors.toList());
System.out.println(notEmptyStrings11); // [Hello, World]
}
}
indent
: Adjusts the indentation of each line of this string based on the value of n
.String text = "Hello World!\nThis is Noor.";
System.out.println(text.indent(4));
Hello World!
This is Noor.
There are some other new methods, like transform.
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
public class StringMethods {
public static void main(String[] args) throws IOException {
Path filePath1 = Files.createFile(Path.of("file1.txt"));
Path filePath2 = Files.createFile(Path.of("file2.txt"));
Path filePath3 = Files.createFile(Path.of("file3.txt"));
Files.writeString(filePath1, "Hello world from Noor");
Files.writeString(filePath2, "Hello world from Noor");
Files.writeString(filePath3, "Hello world from noor");
System.out.println(Files.mismatch(filePath1, filePath2)); // -1
System.out.println(Files.mismatch(filePath1, filePath3)); // 17
}
}
Not a lot of finalized new features are introduced in Java 13.