- GETTING STARTED
- BASIC JAVA
- JAVA STRINGS
- EXCEPTION HANDLING
- JAVA 9
- EFFECTIVE JAVA
Java Platform, Standard Edition(SE) 9 is a major feature release. Java 9 comes with a rich feature set. Java 9 is expected to revolutionize the way we think of and build large scale applications. Many JEPs are committed into Java 9. Below are some of the features which are an absolute must to know about in Java 9.
The JDK Enhancement Proposal (or JEP) is a process drafted by Oracle Corporation for collecting proposals for enhancements to the Java Development Kit and OpenJDK. In the words of the Oracle, the JEP serve as the long-term Roadmap for JDK Release Projects and related efforts.
It allows OpenJDK committers to work more informally before becoming a formal Java Specification Request.
Java 9 features a read-eval-print loop (REPL) tool called the JShell (Java Shell tool). It is an interactive tool for learning the Java programming language and prototyping Java code. JShell is a Read-Evaluate-Print Loop (REPL), which evaluates declarations, statements, and expressions as they are entered and immediately shows the results.
Modern applications are typically deployed through Java Web Start (with a JNLP file), native OS packaging systems, or active installers. These technologies have their own methods to manage the JREs needed by finding or downloading and updating the required JRE as needed. This makes launch-time JRE version selection obsolete.
Java 9 removes the ability to request a version of the JRE that is not the JRE being launched at launch time.
Multi-Release JAR Files extends the JAR file format to allow multiple, Java-release-specific versions of class/resource files to coexist in the same archive. This upgrade makes it easier for third-party libraries and frameworks to use language and API features introduced in newer Java releases. This will allow multiple versions of a library for different Java versions to exist in one JAR, a “MRJAR”. Click here for more details.
javac is enhanced so that it can compile Java programs to run on selected older versions of the platform. A new command-line option, --release, is defined, which automatically configures the compiler to produce class files that will link against an implementation of the given platform version.
In Java 9, the Applet API is deprecated, which is rapidly becoming irrelevant as web-browser vendors remove support for Java browser plug-ins.
To run a Java applet in a web browser requires the use of a browser plug-in. As of late 2015, however, many browser vendors have either already removed plug-in support or else announced timelines for such removal. Once browser plug-ins disappear, there will be no reason to use the Applet API.
Five items in this JEP introduce small changes to the language.
This annotation was introduced in Java 7 to allow a programmer to signal to the compiler that a variable arity method performs safe operations on its varargs parameter. Before Java 9, @SafeVarargs could be applied to either static or final methods. In Java 9, the annotation can also be used on private methods.
Java 9 allows effectively final variables to be used as resources in the try-with-resources statement. Click here for more details.
In Java 9, we can use diamond Operator Extension operator in conjunction with anonymous inner classes. Click here for more details.
In Java 9, underscore is completely removed from the set of legal identifier names.
In Java SE 9, we can write private methods in Interfaces using ‘private’ access modifier like other private methods. Click here for more details.
The process API has been improved for controlling and managing operating-system processes.
For controlling and managing processes on your operating system, Java provides the ProcessAPI. But the API lacks some key functionality, which makes handling with processes in Java a mess. With Java 9, this API will get a considerable update.Click here for more details.
Java 9 brings a new improved string, which in most cases, will reduce String memory consumption to half. Previously, the String class stored characters in a char array, using two bytes (16 bits) for each character. The new internal representation of the String class is a byte array plus an encoding-flag field.
The change does not affect any public interfaces of String or any other related classes. Many of the classes were reworked to support the new String representation, such as StringBuffer or StringBuilder. Click here for more details.
Java 9 brings in new static factory methods on the List, Set, and Map interfaces which make it simpler to create immutable instances of those collections.For example:
alphabet = Set.of("c", "o", "r", "e");
Click here for more details.
Deprecation is a notification to library consumers that they should migrate code from a deprecated API. In prior releases, APIs were deprecated but virtually never removed. Starting with JDK 9, APIs may be marked as deprecated for removal. This indicates that the API is eligible to be removed in the next release of the JDK platform. Click here for more details.