Updated February 9, 2023
Introduction to Java 11
Java 11 is recognized to be the first Long Term Support (LTS) feature release, after Java 8, of Java Programming language. This feature was released on the date Sept 2018 following the Java release rhythm presented Java 10 onwards. Thus, it was introduced just 6 months after the release of Java 10. While, Java 9 and Java 10 are called as the non-LTS release. Whereas Java 11 release is called as a LTS release. Oracle has stopped to support java 8 from Jan’19.
Key Takeaways
1. Java 11 heightened several APIs including new methods plus options and even uninvolved the deprecated APIs plus options.
2. Some main new features of Java 11 introduced in its release are:
- JEP 181 (Access Control Based on Nest)
- JEP 318 (A No-Op Garbage Collector, Epsilon)
- JEP 321 (HTTP Client API standardized)
- JEP 323 (Included Local-Variable Syntax for Lambda Parameters)
- JEP 330 (Presented Single-File Source-Code Programs Deprived of Compilation)
- JEP 331 (Low-Overhead Heap Profiling)
- JEP 333 (A Scalable Low-Latency Garbage Collector, ZGC)
- String API Updates (Included New Methods such as isBlank(), repeat(), lines() and strip())
- Collection API Updates (New Collection.toArray (IntFunction) Default Method)
- Files API Updates (Included new methods such as writeString() and readString())
- Optional Updates (Included new method like isEmpty())
Why Use Java 11?
- From the release of Java 11, now Oracle JDK will not be free to be used for commercial purposes, but it can be used for learning only not commercially. For developing stages use you can use it but need to pay for the license. If this is not done, then the user can receive an invoice bill any day from Oracle.
- Since, Java 10 was the last Oracle JDK which could be downloaded freely and Java 8 support facility is also stopped by Oracle from Jan 2019. One is required to pay to gain extra support. Hence, the clients can use or continue it but there will not be any kind of security updates or will not receive any patches.
- From Java 11 release, Oracle is not going to deliver any free LTS (Long Term Support) feature for anyone Java version.
- Since, Oracle JDK is not free any long, therefore, one can download the Open JDK build always from Oracle or some other providers like Azul, Red Hat, IBM, AdoptOpenJDK, etc. if you take my suggestion, then until one is searching for the usage of Enterprise level having the craving to recompense for the support charges, so you can use the OpenJDK and also upgrade them when it is necessary and required.
How to Download and Install Java 11?
- The user can download Java 11 or the production ready OpenJDK version by visiting the page – Oracle Java Archive. This JDK (Java Development Kit) is known to be a development environment to build applications through Java programming language. Hence, JDK consists of tools that are beneficial to develop and test program codes scripted in Java Programming language and also executing on the JavaTM platform.
- Remember that the Oracle JDK License is updated for releases beginning 16th of April, 2019.
- Going to the download page follow the written instructions for downloading it. The binaries are saved in zip or tar format, so you will have to unzip them. Then you need to run the .exe file for installing it on the system.
- For Windows, you need to download jdk-11.0.7_windows-x64_bin.exe file.
- Now, once the Java is installed on the system, the environment variables should be set up properly that points to the right installation directories.
- After this we are able to use the Java compiler as well as Java commands.
- Check this by typing java_version in window command prompt.
It means Java 11, Oracle JDK 11 has been successfully configured on the system.
Java 11 Developer Features
1. Java file can run with a single command, not required to compile initially the Java source file with Javac tool.
2. Read/Write Strings to and from the files, easily using these static methods.
Path path = Files.writeString(Files.createTempFile("test", ".txt"), "It is displayed on JD");
System.out.println(path);
String s = Files.readString(path);
System.out.println(s); // It is displayed on JD
3. JEP 321: HTTP Client, regulates the HTTP+ Client API, refining sending and receiving process of the server.
4. Nested based access control, it discourses the Java Reflection concern giving three methods to handle it.
Method method = ob.getClass().getDeclaredMethod("myPrivate");
method.invoke(ob);
5. Local-Variable Syntax for Lambda Parameters, Java 323 is added to conclude the type of the variable written from the RHS to announce formal parameters, suppose.
(var a1, var a2) -> a1 + a2
6. New efficacy methods in String class, presenting.
i. Lines()
import java.util.stream.Collectors;
public class Main {
public static void main(String[] args) throws Exception {
String str = "Java11\nJava11\nJava11";
System.out.println(str);
System.out.println(str.lines().collect(Collectors.toList()));
}
}
Output:
ii. IsBlank()
Code:
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
// Your code here!
System.out.println(" ".isBlank());
String s = "Java11";
System.out.println(s.isBlank());
String s1 = "";
System.out.println(s1.isBlank());
}
}
Output:
iii. Strip() [Also, StripTrailing(), StripLeading()]
Code:
public class Main {
public static void main(String[] args) throws Exception {
// Your code here!
String str = " Rain ";
System.out.print("Rain");
System.out.print(str.strip());
System.out.println("GoAway");
System.out.print("Rain");
System.out.print(str.stripLeading());
System.out.println("GoAway");
System.out.print("Rain");
System.out.print(str.stripTrailing());
System.out.println("GoAway");
}
}
Output:
iv. Repeat()
Code:
public class Main
{ public static void main(String[] args) throws Exception
{ // Your code here!
String str = "=".repeat(2);
System.out.println(str);
} }
Output:
7. JEP 328: Flight Recorder, known as a profiling tool used in a running Java application to collect diagnostic plus profiling data.
Java 11 Methods
In the String class, JDK 11 or, Java 11 included some utility methods which will decrease the complexity of the program code and thus enhancing the code performance and readability.
These string class methods introduced in Java 11 are given below:
- Repeat(): This repeat(int count) method will repeat the specific string n times i.e. concatenates the string, and results this new string.
- isBlank(): This method shows TRUE when a string is empty (or, only includes white spaces) elsewhere shows FALSE.
- Strip(): This strip method eliminates all the primary and trailing white space returning a new composed string.
- StripLeading(): This strip method outputs a string that has value as string just removing the all lead white space.
- StripTrailing(): This strip method outputs a string that has value as string just removing the all trailing white space.
- Lines(): It gives a brook of lines mined from provided string which is parted by \n and \r which are line terminators.
Java 11 Modules
With evolution of Java releases, we may not be able to use some of its features that are eliminated, few remarkable ones are:
- Java EE & CORBA: These technologies are offered on third party websites in standalone versions, so since Java 9 this feature is already deprecated and now Java 11 has completely removed these modules.
- JMC and JavaFX: The JMC (JDK Mission Control) is not included in the JDK as well as JavaFX. These modules can be downloaded separately outside of JDK.
- Deprecated Modules: Further it has also removed few other modules such as: Nashorn JavaScript engine (consists of JJS tool) & Pack200 compression scheme specialized for JAR files.
Conclusion
We have learnt about some important Java 11 features and gone through the updates. The download process, new methods included, APIs, modules and importance are also described in the article.
Recommended Articles
This is a guide to the Java 11. Here we discuss the introduction, how to download and install Java 11, developer features, methods and modules. You can also look at the following articles to learn more –