Lessons from Advent Of Code 2023 - Part 2: Streams
Cay Horstmann's unblog
by
2M ago
In this series of articles, I reflect on what I learned from working through the 2023 Advent of Code problems in Java. This installment is all about streams. When should you use them, and when should you stick with loops ..read more
Visit website
Lessons from Advent Of Code 2023 - Part 1: Introduction
Cay Horstmann's unblog
by
3M ago
This year, I was inspired to participate in the Advent of Code puzzle event and doggedly worked every problem until I collected my fifty stars. I learned a lot about algorithms that I had previously only seen in dull theory. And I reflected on effective Java programming. This is the first of several posts where I try to relate my advent experience to everyday programming ..read more
Visit website
Twelve Days of Pattern Matching
Cay Horstmann's unblog
by
4M ago
Pattern matching in Java was derived from the syntax of the switch and instanceof statements in order to leverage the familiarity that programmers have with those constructs. As pattern matching has become more powerful in recent Java versions, that familiarity is colliding with the new needs of the pattern matching syntax and semantics. In this article, also published at Java Advent, I present six puzzlers and six principles to help you understand the latest pattern matching features ..read more
Visit website
Stop Using char in Java. And Code Points.
Cay Horstmann's unblog
by
7M ago
As I am editing the 13th edition of Core Java, I realize that I need to tone down the coverage of Unicode code points. I used to recommend that readers avoid char and use code points instead, but I came to realize that with modern Unicode, code points are problematic too. Just use String ..read more
Visit website
Pattern Matching for Switch (JEP 441)
Cay Horstmann's unblog
by
7M ago
This article, updated for Java 21 and also posted on http://javaalmanac.io, describes pattern matching for switch, in its fifth and final iteration. Type patterns allow you to match on the type of the selector value and analyze the value further in a variable of the appropriate type. There are fiddly rules about null, fall through, and case ordering. At the end of each section is a “sandbox” with somewhat contrived code to try out the syntax variations ..read more
Visit website
Record Patterns (JEP 440)
Cay Horstmann's unblog
by
7M ago
This article, updated for Java 21 and also posted on http://javaalmanac.io, describes record patterns. A record pattern lets you “deconstruct” a record value, binding each component to a variable. Record patterns work with instanceof and switch pattern matching. Guards are supported. They are particularly compelling with nested deconstruction and sealed record hierarchies ..read more
Visit website
Java 21: The Nice, The Meh, and the ... Momentous
Cay Horstmann's unblog
by
7M ago
When Java 17 was released in 2021 as a “long term support” version, I wrote an article dissecting its features and came to the conclusion that it had a few nice features, but none that were compelling reasons to upgrade. Except one: tens of thousands of bug fixes. Java 21 was released today, as another “long term support” release. How does it rate on the momentousness scale? Read on for an unbiased opinion ..read more
Visit website
Virtual Threads (JEP 444)
Cay Horstmann's unblog
by
9M ago
Virtual threads are one of the most significant contributions to the Java programming language in recent history. They support a “direct” style for concurrent programming, without cumbersome callbacks or async/await code transformations. After a couple of rounds of prereleases, they became finalized in JDK 21. Rean on to find out when and how to use virtual threads in your applications. This article is also published on https://javaalmanac.io ..read more
Visit website
Unnamed Classes and Instance Main Methods (Preview)
Cay Horstmann's unblog
by
11M ago
When people complain that Java is too verbose, they like to point at public static void main(String[] args). That is a pain point when teaching beginning students. I always tell students to just copy/paste without worrying, and I never had anyone complain. But many instructors dutifully explain each syntactical element, and I wouldn't be surprised if the students' eyes glaze over. JEP 445 to the rescue. You can pick a version of main that makes sense for your teaching style. And if you teach “objects late”, you can use what looks like global variables and functions. They are actually instance ..read more
Visit website
Unnamed Patterns and Variables (Preview)
Cay Horstmann's unblog
by
11M ago
Sometimes, Java syntax requires you to specify a variable name even when you never refer to it. JEP 443 allows you to use an underscore in many of these cases. This feature is probably most useful in record patterns, where an underscore can even replace a type + name. This article shows all situations where you can use the “unnamed” underscore. This article is also published on https://javaalmanac.io ..read more
Visit website

Follow Cay Horstmann's unblog on FeedSpot

Continue with Google
Continue with Apple
OR