Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

JAVA 9.0 To 13.0 New Features: Learn, Implement and Migrate to New Version of Java.
JAVA 9.0 To 13.0 New Features: Learn, Implement and Migrate to New Version of Java.
JAVA 9.0 To 13.0 New Features: Learn, Implement and Migrate to New Version of Java.
Ebook459 pages3 hours

JAVA 9.0 To 13.0 New Features: Learn, Implement and Migrate to New Version of Java.

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Version release is one of the important phases of success of any programming language. Over the years, Java has made many improvements in its API to make it reliable and flexible to use. This book aims at providing you information related to all the updates from JDK9.0 to JDK13.0 in one place.

This book starts with a brief history of Java. It covers how Java has evolved as a complete programming language over the years by launching different versions. You will learn the concept of module system and other important concepts introduced in JSE9 .0 and JSE10.0. Moving ahead, the book will take you through updates in JDK11.0. Concepts like Epsilon, ZGC, and Nest-Based access control have also been discussed.
Though the version updates are good to learn, they create complexities in updating the existing code to make it compatible with the new version. This book talks in detail about how you can migrate your legacy code to match up with the new versions. It also covers how to use jshell, a tool used to test your code snippet without writing the complete application class, with numerous examples. Further, this book covers in detail the concept of reactive programming. Concepts like publisher, subscriber, subscription and back-pressure have been discussed with examples.
At the end of the book, you will learn about the very recent updates which have been released by Java. The chapters talk about JDK12.0 and JDK13.0. They cover concepts like Shenondaoh, microbenchmark suit, modified switch expression from JDK12.0. Though Java13 is still a hot-plated dish, this book gives you a fair idea about what are the new updates which have been proposed in this version.
LanguageEnglish
Release dateSep 16, 2019
ISBN9789389328615
JAVA 9.0 To 13.0 New Features: Learn, Implement and Migrate to New Version of Java.

Related to JAVA 9.0 To 13.0 New Features

Related ebooks

Programming For You

View More

Related articles

Reviews for JAVA 9.0 To 13.0 New Features

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    JAVA 9.0 To 13.0 New Features - Mandar Jog

    CHAPTER 1

    Insight of Versioning

    Introduction

    Building an application is always a challenging task. It involves working with application programming interface (API), writing business logic and developing user interface (UI). Over the years, the developers have been using several programming languages and frameworks to build various types of applications. Besides, every programming language or framework is constantly working on how it can provide better services to the developers so that they can create efficient, scalable and asynchronous applications. With traditional programming languages, such as C, C++, developers have created a plethora of applications. However, Java certainly seems to be a better programming language than its counterparts. This is particularly because of its write once, run anywhere (WORA) characteristic and other features such as, platform independence, portability, and security. Java is arguably the most widely-used programming language to develop robust, distributed and secure applications in recent days .

    The journey of Java started with the Project Green commissioned by Sun Microsystems. And, since then, it is continuously upgrading itself in terms of new API updates periodically for the current market scenario.

    Structure

    Different versions of Java

    New versioning: time-based release versioning

    Objective

    After studying this chapter, you should be able to understand the concept of versioning, different versions of Java and time-based release versioning process of the Java language.

    Project Green: the beginning

    In the 1990s, Sun Microsystem initiated a project to create a programming tool using C and C++. Patrick Naughton, the head of the project was joined by James Gosling and Mike Sheridan. In its initial days, the primary aim of this team was not to develop a new programming language but to program new electronic devices other than computers. The project was being designed for developing embedded systems, where languages like C++ were not responsive enough.

    This made Bill Joy, co-founder of Sun Microsystem to think of a new language for this project. Working on this idea Gosling started working on enhancing C++ and launched a complete programming language. Initially named as Oak after the tree that was outside this office, it was later renamed as Java.

    Developers found Java revolutionary, but that was not the end of everything. In fact, it was just the beginning. What followed next was continuous update in the API. Such updates were released as a part of different version of Java. Though most of the other languages took small incremental step for upgrading, java started to kick off the versions with a wider scope and vision.

    Over the years, Java’s API has undergone many structural changes. The package-oriented programming approach is reshaped to modular programming from JDK 1.9. This approach changed the way of traditional application development thoroughly.

    The original name given to Java was not Oak, it was C++ ++--, which says new features added and unwanted features were removed.

    Versions of Java

    It is very interesting to observe how Java is transforming from one version to another; what are the different features in a particular version; and how it is helping the developers in creating better applications.

    Let us quickly walk through the different versions of Java, from its early release to JDK8.0, in this chapter. We will be extensively discussing versions 9.0, 10.0, and 11.0 in later chapters.

    Version: JDK1.0

    Release date: 23rd January, 1996

    This is a curtain-raiser. Sun Microsystem, launched their first version of Java 1.0 with basic facilities. The codename given to this version was Oak. This included Java runtime, development tools i.e. compilers. Following were the basic features of this release:

    java.lang

    java.io

    java.util

    java.net

    Version: JDK1.1

    Release date: 19th February, 1997

    The prime focus of this release was to increase the stability, speed, and security of Java applications. This version contains around 700 classes with enhancements for performance, JDBC, and Java Bean support. Java had released a few updates of this version, which is also termed as minor versions of 1.1. The codenames of these versions are different for different API update like, Version1.1.6 (Abigail), Version 1.1.7(Brutus), Version 1.1.8(Chelsea). Following are the major changes that were implemented in this version:

    Java archive (JAR) file format

    Inner classes

    Internationalization

    Math package

    Object serialization

    Remote method invocation

    Version: JDK1.2

    Release date: 8thDecember, 1998

    This version was launched in an era when the internet was booming. So, the term J2SE (Java 2 Platform, Standard Edition) was introduced to differentiate this development kit from J2EE (Enterprise Edition) and J2ME (Mobile Edition). One of the major updates in Java was that the classes reached up to 1520 bundles in 59 packages. The code name given to this version was Playground.

    To improve the performance of the application, JDK1.2 introduced a few implementations:

    Faster memory allocation and garbage collection:

    Memory allocation in heap was a concern, which was read by using thread-local cache. So, every time there was no need for locking the majority of the heap allocation. Also, constant strings were shared among different classes, reducing the unnecessary duplicate string object creation.

    Native libraries:

    As JVM is not platform dependent, many a times the native libraries were not uniform. In this version, such libraries which supported core java classes were re-written using Java Native Interface (JNI).

    Solaris native thread support:

    Java had given the ability to the kernel so that it could schedule native threads over parallel processors. This made concurrency cheaper.

    The following major language changes/updates were implemented in this version:

    Collection framework:

    A collection is a group of objects embedded in a single unit. Before JDK 1.2, developers were using arrays, vectors, or hash tables. Though these objects were giving the services, there were no common interfaces or methods shared between them, because of which developers were required to use different methods for accessing different collections.

    To overcome this complexity, Java came up with common interface structure in the format of collection framework API. This API consists of different interfaces like set, list or map. The classes implementing these interfaces provided a common set of methods, because of which developers could use the services more effectively.

    strictfp keyword:

    Working with floating point data type had always been vulnerable, prior to JDK1.2. Floating point data was platform dependent, because of which the precision of the floating-point data was not guaranteed. The keyword strictfp resolved this issue which follows the IEEE 754 standards.

    Following were the library changes/updates that were implemented in this version:

    Just in Time (JIT) compiler implementation

    Java plug-in

    Swing graphical API

    Version: J2SE1.3

    Release date: 8th May, 2000

    This version mainly focuses on the modifications in deployment and improvements of applet performance through Java Hotspot Client. The codename given to this version was Kestrel. Following were the major updates in this version:

    Jar indexing:

    When the application is spread out in multiple JAR files, at runtime it becomes difficult for the application to find the required classes. This problem can further get complicated if the project length is of a larger volume. To overcome this issue, Java recommended indexing of a JAR file. The entire directory information is stored in index.list file, which makes the searching of classes simpler.

    Improved applet caching:

    The applet caching is an important plug-in provided by this version, which makes sure that each time when an applet is requested it need not necessarily be communicated to the server. The same cache can be used for different web pages for fetching the applet. This increased the speed of loading the web page.

    Optional package installation:

    Java runtime normally searches the file from jdk/bin where rt.jar file is located. There is folder structure lib/ext, and jre/lib/ext where the optional packages are present. At runtime, Java searches the file in the runtime environment path. If the class is not found in the runtime environment, it is searched for in optional package installation directory.

    Java Naming and Directory Interface (JNDI):

    The Java Naming and Directory Interface™ (JNDI) is an API that provides naming and directory functionality to applications written using the Java programming language. It is defined to be independent of any specific directory service implementation. Thus, a variety of directories - new, emerging, and already-deployed ones - can be accessed in a common way.

    Version: J2SE1.4

    Release date: 6th February, 2002

    This is the first version launched under the recommendations of JCP as JSR59. You can find more details about this on https://jcp.org/en/jsr/detail?id=59. The codename given to this version is Merlin. Public support and security updates for this version ended in October 2008. The following major updates were done in this version:

    Language changes:

    Assert keyword:

    An assertion gives you the facility to enable developer/tester to test the assumptions done in the program. Assertion typically contains a Boolean expression, when assumption made by developer is correct then assertion executes. If not true, the system will throw an assertion error.

    Library improvements:

    Regular expressions:

    This facility is given by Java to search, edit or manipulate the text and data.

    Chained exceptions:

    Sometimes Java code catches one exception and throws another. This normally complicates the debugging. To overcome this awkward situation for the developer, chained exception handling is introduced.

    Java Web Start:

    This software allows a user to download and run the application which is available on the web. This gives easy one-click access, guarantees that you are using an upgraded application, and avoids complicated installation process.

    Though these are not an integral part of a web page like applet, they run in a separate frame.

    Java Web Start (JavaWS/javaws/JAWS) is deprecated from JSE9.0 and removed completely in JSE11.0.

    XML processing:

    Java introduced API for XML processing or JAXP to validate and parse XML documents. In this version, some basic parsing interfaces were introduced viz. Document Object Model (DOM), Simple API for XML (SAX).

    Logging API:

    Logging is one of the important features introduced by Java. It maintains the records while a program is executed. These records or messages are then reviewed by the programmer to analyse the data. Logging is generally created by using Logger object which is provided by Java.

    Preference API:

    This API provides an effective way to store the preference configurations of the program. This may include system preference or user preference. Normally such data will be stored in key/value pair. It gives the get and put method to store and access the preference data. This API is not used to store bulk data such as application data.

    Version: J2SE5.0

    Release date: 30th September, 2004

    This version was undoubtedly one of the most important versions in the life-cycle of Java versions. Many new features are added in this version to convert Java into writing smaller, effective, safer programs. Originally named as JDK 1.5, this version was later renamed as J2SE5.0. The codename given to this was Tiger.

    Public support and security updates for this version ended in November 3, 2009.

    This version is known for one of the most important updates in Java programming as a lot of new useful features were added in this.

    The following major updates were given by this version:

    Language changes:

    Generics:

    Similar to templates in C++, generics in Java is a facility given to developers so to write the classes, methods, interfaces with type parameters. This is most important when one writes the same business implementation with different data types.

    Usage of generics gives developers benefits like:

    Type safety

    Elimination of casting

    Performance gain

    To understand the concept, observe the following snippet for creating a generic class:

    class Sample{

      T obj;

      Sample(T obj){

         this.obj=obj;

      }

      public T getObj(){

         return this.obj;

      }

    }

    The above generic class defines T as a placeholder, which says that the application developer can push any data type at runtime.

    Now, let us examine the application for this:

    Class SampleApp{

       public static void main(String[] args)

       {

         Sample s=new Sample(10);

         System.out.println(s.getObj( ));

       }

    }

    When you compile both the files and execute SampleApp, the following output can be seen:

    Figure 1.1: Generics Implementation

    Enhanced for loop:

    This loop was introduced to iterate the elements of collection more efficiently. Though it can be also used to iterate through arrays, the primary focus is not the same.

    for(int x :myArray)

    {

       System.out.println(x);

    }

    The above enhanced loop iterates through the data collection named myArray of integer type. While iterating, every element of this collection is stored in variable x.

    Autoboxing/autounboxing

    Autoboxing is the automatic process where the Java compiler converts the primitive data types to the corresponding wrapper object. e.g. converting int to Integer, or double to Double.

    Refer the following code snippet:

    Integer x= 10;

    Here, the primitive value 10 is assigned to its corresponding wrapper object Integer.

    Autounboxing is exactly the reverse process. In this, the wrapper objects are converted to their counterparts’ primitive. e.g. Integer to int, Double to double, or Float to float etc.

    Refer the following code snippet:

    Integer x= 10;

    int y =x;

    Here, the wrapper Integer object which contains value as 10 is passed to primitive with the process of autounboxing.

    Varargs:

    Java introduced a feature to reduce the number of overloaded method for different number of arguments for similar data type. This feature is called as varargs and it stands for variable-length argument.

    This a method that takes a variable number of arguments as shown below:

    public static int addition(int… x){

      //business logic

    }

    The above snippet declares the method add, which takes variable arguments of int data type. This means that a developer can call this method by passing any number of integer arguments as follows:

    int a = addition(10,20);

    int b = addition(10,23,12,43);

    int c = addition(12,43,12,43,12);

    Static imports:

    In some occasions, Java requires importing the public static members, which may contain fields or methods from other classes. JSE 5.0 gives a developer the facility of static import, using which one can refer the static members in a program without writing the reference of the class in which they reside.

    The following import statement describes how to import the static constants in a program.

    import static java.lang.Math.PI;

    import static java.lang.Math.pow;

    import static java.lang.System.out;

    public class HelloWorld {

      public static void main(String[] args) {

        int radius=5;

        out.println(circumference = + (PI * 5) + cm);

        out.println(area = + (PI * pow(2.5, 2)) + sq. cm);

      }

    }

    Annotations:

    This is a metadata facility given by Java which provides data about a program. This is not a party of the program so they don’t have direct impact on the operations of the code.

    Following 3 types of annotations were introduced:

    Information to compiler

    Compiler and deployment time processing

    Runtime processing

    Library improvements:

    Automatic stub generation for RMI

    Updates in Swing component look and feel

    Concurrent utilities

    Version: JSE6

    Release date: 11th December, 2006

    Sun replaced the earlier naming conventions of versions from J2SE to JSE. So, this version was named JSE6 instead of J2SE6.0. However, for the internal references and documentation, Sun still uses the version name as JDK1.6.0

    The codename given to this version is Mustang. This version was developed under JSR 270.

    Public support for this version ended in February 2013. But oracle released 2 more updates to this version in March and April 2013 as a solution to some security vulnerabilities.

    The following major updates were given by this version:

    Language changes:

    Collections:

    Though the collections were updated in earlier versions as well, they were still lacking in bi-directional access. Considering some of the important interfaces were provided in this version as :

    Deque

    BlockingDeque

    NavigableSet

    NavigableMap

    ConcurrentNavigableMap

    JDBC 4.0 API:

    JDBC 4.0 adds more functionality to the existing JDBC API. Following were the main features added in this API

    New implementation of data sources

    Auto-loading of JDBC drivers

    More refined SQL exceptions

    New methods added in SQL statements and connections

    Java Compiler API:

    JSR 199 proposed one very interesting feature called Java Compiler API. This gives a standard way to compile the java source files. Java Compiler API provides a way to compile Java source file within Java files. Earlier the developer could only go for such process using javac.exe. Of course, this feature is not useful for everyone, but many IDEs use it internally.

    Integrated web service:

    JSR 224 designed Java API for XML Web Service (JAX-WS). This provides full support for building, deploying RESTful web services.

    Pluggable annotations:

    Java introduced pluggable annotations through JSR 269. Using this, a developer could write customized annotations processor, which could be plugged in to the code that operates on the annotations appearing in the actual source code.

    Version: JSE7

    Release date: 7th July 2011

    This version was considered to be a major release from Java language. There were a lot of language changes done in the earlier versions. The development went on so extensively that it was divided into as long as 13 milestones and on 6 June 2011, the last

    Enjoying the preview?
    Page 1 of 1