Simple Web Server, Incremental JVM Improvements & JEP 420 Update - Inside Java Newscast #16

In Software Development


Simple Web Server, Incremental JVM Improvements & JEP 420 Update - Inside Java Newscast #16 - read the full article about java development 2021, Software Development and from Java on Qualified.One
alt
Ujjaval Srivastav Inkoniq,
Software Developer
alt

[snoring] [snoring] [alarm clock] Oh Nicolai has a new newscast episode [Nicolai over speakers]: Share this video with your friends or colleagues. The next episode will be hosted by either José or Billy. [Nicolai over speakers]: Ill see you again in four...

Is this thing on? Ohh ok! Hello and welcome everyone to this weeks Inside Java Newscast Where we cover the latest developments in OpenJDK Im your host Billy Korando Java Developer Advocate at Oracle Today we will be covering three topics First how the JDK will be gaining its own web server Second incremental improvements to the JVM And third the second round of preview for pattern matching for switch So lets get going! JDK Enhancement Proposal, JEP, 408 Specifies a simple web server to be packaged with the JDK, Java Development Kit As the name of the JEP suggests the simple web server is just supposed to be that, simple It was built on the com.sun.net.httpserver package that has been part of the JDK since 2006 The web server only handles GET and HEAD requests With all the other request types returning a 405 or 501 The web server serves on static content and only serves HTTP so no HTTPS The goal is to provide a web server with the absolute minimum of ceremony This helps fulfill the common need for students And newcomers to Java of being able to server static pages However even seasoned Java developers will likely find the simple Web server useful for local testing and development The server can be started from the command line with java -m jdk.httpserver This might actually be getting easier pretty soon As there is an open PR for a new jdk tool jwebserver So everywhere I am using java -m jdk.httpserver Can likely replaced with jwebserver in the future [record scratch] So as it turns out jwebserver has actually been integrated (into main) since I recorded that video so that future I was talking about, is actually now Running this command will start the server on the loopback address http://127.0.0.1 and port 8000 Serving files from the directory the command was executed from And the MIME types will be automatically configured So a file ending in .html will be served as text/html While a file ending in .java will be served as text/plain Though this can be customized via the java.net.URLConnection::getFileNameMap API On the subject of customization the web server can take several optional arguments -p for setting the port number -b for the binding address -d for the directory, which can also be a remote directory -o for setting console output level None, verbose, and info, with the default being info And -h for help with can show these options To stop the server simply hit ctrl + c Or command + c for Mac users In your terminal window Currently target for JDK 18 But theres always a chance things might changes, so dont take my word for it The command line tool is great and offers some customization options But what if you need customization options beyond what is available in the command line Were are developers after all and we like to tinker Luckily there is an extendable API available That fills the gap between command-line options And writing your own implementation of com.sun.net.httpserver This API is composed of three new classes SimpleFileServer HttpHandlers And Requests All located under com.sun.net.httpserver The SimpleFileServer has three static methods createFileServer createFileHandler And createOutputFilter That can create a file server A file server handler And a filter respectively The new Request interface provides a simple API for working with requests Than what is provided by HttpExchange Which describes the full and mutable stable of an exchange The new class HttpHandlers has two static methods as well handleOrElse And of The handleOrElse method takes a Predicate and two HttpHandler arguments The Predicate can inspect the request And if the Request fulfills the Predicate the first HttpHandler will be used And second if the Predicate is false of allows for creation of handlers with pre-set response state of allows for creation of handlers with pre-set response state Finally the Filter class in com.sun.net.httpserver Has also been updated with the static method acceptRequest Which offers the ability to inspect and adapt a request, before it is handled These new APIs allow for an easy way of customizing a handler that can even be accomplished in jshell Though of course you can use all these new APIs in an IDE of your choice as well For more information on the new Simple web server and the new API it provides Be sure to check out its JEP While new language features like; records, switch expressions, text blocks, and others Often dominate the conversation when covering a new JDK version [poop] [poop] [poop] [poop] [poop] [poop] [poop] [poop] [poop] Less covered, but possibly more important are the steady improvements made to the JVM The Java Virtual Machine, with every new version of the JDK With JDK 17 one such change that caught some attention Was an improvement to String.format() that increased its throughput by about three-fold While usually individual changes like the String.format() change May not always have a measurable impact in the performance of a real-world application Collectively these JVM improvements can make a substantial difference A point that Stefan Johansson shows well in a recently published article Comparing the carnage collectors between JDK 8, 11, and 17 Stefan shows how there has been significant improvements across throughput Stefan shows how there has been significant improvements across throughput Latency Latency Pause times Pause times And memory usage in JDK 17 over JDK 8 and even JDK 11 A link to this article is in the description If you would like us to cover more improvements to the JVM in detail, let us know in the comments On the subject of new language features.

One of the big stories in the upcoming releases of Java is pattern matching Pattern matching is the concept of having a match predicate And if that predicate is met assigning the value to the pattern variables The next chapter in that story of pattern matching for Java Is the second preview for pattern matching for switch Which is covered in JEP 420 There are two changes from the first preview, JEP 406 The first change is dominance checking now forces a constant case label To appear before a guarded pattern of the same type, for readability And the second change is exhaustiveness checking Of switch blocks is now more precise With sealed hierarchies where the permitted direct subclass Only extends an instantiation of the sealed super class Well that about does it for this week of the Inside Java Newscast Help spread the word about our content by liking and sharing with your friends and colleagues If you want to stay up-to-date on the latest developments in OpenJDK Be sure to subscribe as well.

Nicolai will be back next episode, I am Billy saying, so long!

Java: Simple Web Server, Incremental JVM Improvements & JEP 420 Update - Inside Java Newscast #16 - Software Development