Http2 in java 9


In this java tutorial we will learn new features which will be introduced in Java 9. Java 9 is likely to be introduced in March 2017.


We can define  new HTTP client API that implements
  • HTTP/2 and
  • WebSocket,
It can replace java.net.HttpURLConnection used earlier.
This API will be as available as incubator module.
This API will be defined in the incubator JEP (i.e. in jdk.incubator namespace.)

So, this API won’t be part of Java SE.

Why to replace HttpURLConnection API?
Because it was designed to work with protocols (like gopher, ftp ) out of which most of them not functional now.

HttpURLConnection API is too abstract.

It has only one thread per request/response (So, it works only in the blocking mode).
It is very hard to use and maintain, most of its stuff is not documented.

Features of new HTTP client API that implements HTTP/2 and WebSocket
  • Much better performance than HttpURLConnection .
  • Much faster and lightweight can HttpURLConnection .
  • Consume less memory than HttpURLConnection.
  • Work in simple blocking mode.
  • Provide Asynchronous notification of events such as
    • "headers received",
    • "response body received" and
    • Errors
    • Server push (HTTP/2 only)
  • Simple and very concise API.
  • Serve almost all the application needs.
  • handle following >
    • HTTP request to a server,
    • HTTP response from a server
  • Highly secure.
  • Easily set up the WebSocket handshake.
  • Support HTTP/2.
  • Support HTTPS/TLS.
  • Support lambda expressions introduced in java 8.
  • Support HTTPS (by using SSLEngine)
  • Proxy support
  • Cookies support
What are available alternatives >
There are few existing HTTP client APIs available >
Jetty and
Apache HttpClient.
But both are very heavy in because of high numbers of packages and classes.
Also, they even doesn’t use lambda expressions introduced in java 8.




Having any doubt? or you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.


RELATED LINKS>

varHandle (variable handle) in java 9

Improved JVM compiler control and handling in java 9


Improve Locking performance in java 9

JVM logging system in Java 9 - Levels, tags, output, rotation, decoration




Labels: Core Java Java 9
eEdit
Must read for you :