#Java18 comes out later today - what can you expect from Java's newest release? Here's a 🧡 with one tweet per feature - short and sweet.

For more details and links, read this blog post: nipafx.dev/inside-java-ne…
For questions, join our #JDK18 AMA later today. πŸ‘‡πŸΎ
Pattern Matching for `switch` (2nd preview)
openjdk.java.net/jeps/420

Changes:
* constant case labels must now appear before guarded patterns of the same type
* exhaustiveness checking is now more precise when sealed classes and generics mix

Another preview is expected in #JDK19.
Vector API (3rd incubation)
openjdk.java.net/jeps/417

Changes:
* support for ARM Scalar Vector Extension (SVE)
* performance for masked ops improved on architectures that support masking in hardware

Vector API will stay incubating until Valhalla's value/primitive types.
Foreign Function & Memory API (2nd incubator)
openjdk.java.net/jeps/419

Changes:
* more carriers
* obtaining downcall method handles is simpler
* managing temporal dep's between resource scopes is simpler
* more general dereference API
* new API to copy Java arrays to/from memory
Simple Web Server
openjdk.java.net/jeps/408


Start a web server that hosts files in a directory for tests/demos/experiments with `jwebserver`. It's super simple on purpose: only HEAD and GET, no support for authentication, access control, encryption, etc.
Internet-Address Resolution SPI
openjdk.java.net/jeps/418

A service-provider interface for host name and IP resolution, so `java​.net.InetAddress` doesn't have to rely on `hosts` file or pin threads (#ProjectLoom).

More in the next Newscast - subscribe: youtube.com/java
Deprecating Finalization for Removal
openjdk.java.net/jeps/421


Due to various flaws (unpredictable timing & threading, error-prone, security implications) finalization is deprecated for removal. To preview removal, test with `java --finalization=disabled`.
UTF-8 by Default
openjdk.java.net/jeps/400
inside.java/2021/10/04/the…

If no file encoding is specified, file APIs now use UTF-8 instead of determining a fallback from OS/user settings. Stick to old behavior with `-Dfile.encoding=COMPAT`, prepare with `-Dfile.encoding=UTF-8`.
Reflection via Method Handles
openjdk.java.net/jeps/416

The JDK had three mechanisms for reflective ops:

1. VM native methods
2. bytecode stubs and Unsafe
3. method handles

Code using 2. was refactored to 3. and 2. was removed, so future lang additions require less work.
Javadoc Code Snippets
openjdk.java.net/jeps/413


Instead of writing demo code as text in Javadoc (which is agonizing and brittle), place it in a compiled and tested source file and then reference that or a section of it from Javadoc.
There are very few smaller API additions in #JDK18. The most noteworthy are in `Math` and `StrictMath`, which gained methods that combine division and modulo computations with rounding, for example to compute the result of 4 divided by 3, rounded up.
As always, there are plenty of security fixes (keep an eye out for @seanjmullan's post on seanjmullan.org/blog/) and performance improvements (also in the next Inside Java Newscast on youtube.com/java).
Now I'm curious to learn: What's the newest JDK version you'll be using in production in the next weeks. (Twitter polls only allow four choices, so please forgive me if you're in between or below 8. 😊)
πŸ€”

β€’ β€’ β€’

Missing some Tweet in this thread? You can try to force a refresh
γ€€

Keep Current with Nicolai Parlog πŸ‡ΊπŸ‡¦πŸ•ŠοΈ

Nicolai Parlog πŸ‡ΊπŸ‡¦πŸ•ŠοΈ Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @nipafx

Dec 21, 2021
#ProjectLoom's virtual threads will make high performance in concurrent systems attainable with much simpler code. But Loom aims for even more and wants to make the code clearer and more robust by introducing *structured concurrency*.

Here's what that's all about. 🧡
Important: This is about concurrency, not parallelism. See yesterday's thread πŸ‘‡πŸΎ for a more detailed distinction, but the gist is that concurrency is about processing lots of tasks that the environment throws at your system at the same time, ideally with high throughput.
Concurrency code is often unstructured:

* splitting and joining concurrent subtasks in different methods/classes
* little support to compose error-handling, cancellation, … across subtasks
* threading structure is opaque to the runtime, which only sees independent threads
* …
Read 9 tweets
Dec 20, 2021
What's it called when multiple threads execute at the same time? Parallelism? Concurrency? πŸ€” Is there a difference? (Spoiler: Yes!)

Let me explain in a few tweets, ripping off @pressron's #InsideJava blog post "On Parallelism and Concurrency". 🧡

inside.java/2021/11/30/on-…
Parallelism:
Taking a task and splitting it up, so multiple CPUs can compute partial solutions in parallel to solve the task in less wall-clock time.

Concurrency:
Having a number of tasks that need to be arranged in a way that solves as many of them per $time_unit as possible.
Some parallelizable tasks:

* sorting an array
* inverting a matrix
* rendering graphics

Some examples for concurrency:

* processing incoming web requests
* making outbound calls to DB and/or other web services
* observe file system for changes
Read 11 tweets
Dec 10, 2021
I'm no security expert and don't know how ubiquitous this vulnerability is, but if you use Log4J 2.x, you should probably update to 2.15.x and read these:

logging.apache.org/log4j/2.x/secu…
lunasec.io/docs/blog/log4…
Here's something else you can do until the updates are rolled out.
The other option until you've updated your dependency is this command line flag.
Read 4 tweets
Nov 3, 2021
From compact record constructors to pattern matching, from generic wildcards to chaining predicates and comparators, from jpackage to jlink - here are 11 #Java tricks handpicked from dev.java. 🧡

(Musical version of this thread: )

0/11
A #record's *canonical* constructor has one arg per component but in its *compact* form, you don't have to list them. You also don't have to (in fact, can't) assign fields, just do the checks/reassignments you need, rest happens automatically.

More: dev.java/learn/using-re…

1/11
Serialization works great with #records, no black magic needed! The guaranteed presence of constructor parameters and accessors makes serialization work with the object model and makes it easy to create reliable serializable records.

More: dev.java/learn/using-re…

2/11
Read 12 tweets
Mar 16, 2021
Here are 11 improvements you get when updating to #Java16 later today: from records and type patterns to `Stream`-additions and Unix domain sockets, from creating installers to more performance and observability. πŸ§΅πŸ‘‡πŸΎ

(Longer form with tons of links: nipafx.dev/java-16-guide/)
#1 Records

Express in a single line that a type is just a collection of data without need for encapsulation and let the compiler do the rest:

record Range(int low, int high) { }

That results in almost the same API as the attached class. *drops mic* Image
#2 Type Pattern Matching

This is actually two-for-one:

* first step into pattern matching
* type patterns with `instanceof`

With a type pattern you check whether a variable is of a certain type and, if so, create a new variable of that type, so you can use it without casting. Image
Read 14 tweets
Mar 14, 2021
"Towards better serialization!"

That's a guiding light of #ProjectAmber and record serialization is the first step. The Inside Java Podcast episode on that topic with Julia Boes and @chegar999 (inside.java/2021/03/08/pod…) gives great insight into how it achieves that. 🧡

1/10
First, what's wrong with regular serialization? In short:

* extralinguistic mechanism (aka "magic")
* undermines encapsulation
* causes security issues
* hinders evolving code
* holds back new Java features

In long (and why it turned out that way), see attached thread.

2/10
"The magic is where the sin was" (@BrianGoetz) and so record serialization promises "what you see is what you get", making it:

1. easy to understand
2. no magic
3. more secure
4. more performant

3/10
Read 10 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(