Top 5 features added to Java SE 9

Background

Java has been evolving at a good pace ever since it was introduced in early 90’s. With every passing year and each release it has tried to keep pace with emerging market demands.Java has been evolving at a good pace ever since it was introduced in early 90’s. With every passing year and each release it has tried to keep pace with emerging market demands.

Let’s take a look at the top 5 features added to Java 9

1. Modules
The result of Project Jigsaw, modules are the most important addition to Java 9.

  • Java is now modular which means the library packages are now organized as modules.
  • It changes the way we design and build Java Applications.
  • It is different from OSGi.
  • It helps Programmers to be more productive.
  • Managing and evolving modules is easier.

2. JShell : Read-Eval-Print loop for Java
A tool that allows you to develop and test Java code interactively.

Earlier:

class Sample{
	public static void main(String[] a){
		System.out.println("Hello World");
	}
}

And now using JShell you can print Hello without writing other stuff.
You can type JShell at command line to get started.
And write

System.out.println(“Hello !!”);

3. Private Methods in Interfaces

You can now add private methods to your Interfaces. This can help you to create  reusable code.

Example:

public interface Sample {

private void printMyStuff(String abc){

System.out.println(abc);

}

}

4. Collections
Earlier you would write

List<Employee> empList = new ArrayList<>();

empList.add(new Employee(1, “Ankur”));

empList.add(new Employee(2, “Rohan”));

Now you can write

List<Employee> empList = List.of(new Employee(1, “Ankur”), new Employee(2, “Rohan”));

Reason – Thanks to changes in Java 8. Interfaces can now have default methods.

5. Concurrency Updates

Java 8 introduced Streams. Java 9 has gone a step ahead and added

  • Reactive Streams publish-subscribe framework
  • Enhancements to CompletableFuture class which was introduced in Java 8.

Other Notable Changes

HTTP Client API to support HTTP/2 and WebSocketThe new incubator HTTP Client is capable of working with both HTTP/1.1 and HTTP/2

 

Learn how to create and use a Android Module in your Android Project

You saw why using modules is important and how to create a Java module in an earlier Post. In a similar fashion you can add an Android module to your project.

Android Studio makes it easy to add a new module. Follow the video to understand the steps.

Source code is available here

Learn how to create and use a Java Module in Android Project

Creating modules is a good practice since it aids in reusability. In your Android project you can easily add a Java or Android module.

Follow the video to create a Java module and add it as a dependency in your Android Project.

Project source code is available in GitHub