Oracle provides new Java versions every six months. Even before it was launched, the September Java 11 version created quite a stir in the computer science industry by announcing that commercial usage of Java would subsequently be charged. The following articles will highlight major JDK 11 features, advancements, and deprecated functionality.
Important Changes and Information:
- The deployment stack necessary for executing applets and web apps has been removed from JDK, which was deprecated in JDK 9 and was removed from JDK 10.
- Due to the unavailability of the deployment stack, a whole portion of supported browsers has been deleted from the list of allowed configurations.
- JRE auto-update has been discontinued from Windows and macOS installs.
- JavaFX and Java Mission Control are now available for download separately.
- Java language translation is no longer available for French, German, Italian, Korean, Portuguese (Brazilian), Spanish, and Swedish.
- JRE and Server JRE are no longer supported in this version. Just JDK is available.
- The Windows package format has been updated from tar.gz to.zip.
- The macOS package format has been updated.app to.dmg.
1. New String Methods:
isBlank(): This method is boolean. It just evaluates to true when a string is empty and false otherwise.
public class String { public static void main(String args[]) { String str1 = ""; System.out.println(str1.isBlank()); String str2 = "InnovationM"; System.out.println(str2.isBlank()); } } Output: true False
lines(): This function returns a collection of strings separated by line terminators.
import java.util.*; public class Line { public static void main(String args[]) { String str = "Java\nIs\nPlatform\nIndependent"; System.out.println( str.lines().collect(Collectors.toList())); } } Output: Java Is Platform Independent
repeat(n): The combined string of the input string repeated multiple times in the parameter is the result.
public class Repeat { public static void main(String args[]) { String str = "Java"; System.out.println(str.repeat(4)); } } OutPut:JavaJavaJavaJava
stripLeading(): It’s used to remove the white space in front of the string.
public class StripLeadind { public static void main(String args[]) { String str = " InnovationmTechnolgy "; System.out.println(str.stripLeading()); } } Output: InnovationmTechnolgy
stripTrailing(): It is used to delete the white space at the end of the string.
public class StripTrailing { public static void main(String args[]) { String str = " InnovationmTechnolgy "; System.out.println(str.stripTrailing()); } } Output: InnovationmTechnolgy
strip(): It is used to eliminate the white spaces in the string’s front and rear ends.
public class Strip { public static void main(String args[]) { String str = " InnovationmTechnolgy "; System.out.println(str.strip()); } } Output: InnovationmTechnolgy
2. New File Methods
writeString(): This will create content for a file.
jshell>Files.writeString(Path.of(example.txt), "InnovationmTechnolgy!"); readString(): This can be utilized to read a file's content. jshell>Files.readString(Path.of(example.txt)); Output: " InnovationmTechnolgy!"
isSameFile(): With this technique, one may determine if two paths go to the same file or not.
jshell>Files.isSameFile(Path.of("example1.txt"), Path.of("example1.txt")); Output: true jshell>Files.isSameFile(Path.of("example2.txt"), Path.of("example1.txt")); Output: false
3. Pattern Recognizing Methods
asMatchPredicate(): AsPredicate from Java 8 is comparable to this method ().
If the pattern fits the input string, this method, which was introduced in JDK 11, will produce a predicate.
jshell>var str = Pattern.compile("AVA").asMatchPredicate(); jshell>str.test(AABB); Output: false jshell>str.test(AVA); Output: true
4. Epsilon Garbage Collector
Although it manages memory allocation, it lacks a true memory reclamation
system. JVM will shut down whenever the available Java heap has been used up.
Goals include: Performance testing, memory pressure testing, and improvements to last-drop latency.
5. Discard the Java EE and CORBA modules
These modules were marked as deprecated in Java 9 with a directive to remove
them from further JDK releases.
6. Discard thread functions
The JDK 11 has deleted the stop(Throwable obj) and destroy() objects since they only throw UnSupportedOperation and NoSuchMethodError, respectively. They had no other purpose than that.
7. TimeUnit Convert
The supplied time may be converted using this approach to a unit like DAY, MONTH, or YEAR, as well as for time.
jshell>TimeUnit c = TimeUnit.DAYS; Output: DAYS jshell>c.convert(Duration.ofHours(24)); Output: 1 jshell>c.convert(Duration.ofHours(50)); Output: 2 Optional.isEmpty(): If any object's value is null, this function returns true; otherwise, it returns false. jshell>Optional str = Optional.empty(); jshell>str.isEmpty(); Output: true jshell>Optional str = Optional.of("AbhinavKaushik"); jshell>str.isEmpty(); Output: false
8. Local Variable Syntax for Lambda Parameters
Var can be used in lambda expressions according to JDK 11. This was added to be compatible with Java 10’s local “var” syntax.
public class LambdaExample { public static void main(String[] args) { IntStream.of(8, 9, 10, 11, 12, 13) .filter((var i) -> i % 2 == 0) .forEach(System.out::println); } } Output: 8 10 12