Win a copy of Spring in Action (5th edition) this week in the Spring forum!

Cay Horstmann

author
+ Follow
since Nov 14, 2004
Cows and Likes
Cows
Total received
27
In last 30 days
0
Total given
0
Likes
Total received
45
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Cay Horstmann

Congratulations to the winners and thanks for having me at the ranch!

Cheers,

Cay
9 months ago
I agree with the collection factory methods. And Optional.ifPresentOrElse(). (What a terrible name, though.)

With many of the other items on your list, I had a tough time coming up with exciting examples. Take private instance methods on interfaces. Sure, why not? But try writing a plausible example. You need multiple default or static methods that want to share something that's worth putting into a method (but that can't access fields, only call other methods).

Or the diamond operator with anonymous classes. Nowadays, how often do you have an anonymous class? Lambda expressions are almost always simpler. So, you need to override a generic class or a generic interface that's not a functional interface. Of course I can come up with an example, but not with one that is so memorable that the reader says "gotta have that feature". Truth be told, I never knew you couldn't use diamond with anonymous classes, because it never came up in my work.

Or take effectively final variables in try-with-resources. I tried



It's ok, but it's a little weird to give a writer to a method that then closes it. Definitely something that one would want to document carefully.

Or Stream.takeWhile/dropWhile. I dutifully present them, but I have never used them in practice, even though I use streams a lot. It just doesn't happen that much that I am interested in stream value until something terrible happens, and then I no longer care. I'd love a really compelling use case.

I am sure Optional.or will at some point find good uses when we all use more optionals. And it has a nice name. But explain it to someone in an elevator. Ok, you have two Optional. The or method produces the second if the first one is empty. Except, not quite. The second Optional is computed lazily. Ok?

I have a long list of features like these where I have no truly compelling use case. Every once in a while, I find one, put it into the next edition of the books, and cross it out.

Now contrast that with InputStream.readAllBytes. Of course that's something you want to do. And I can go on to show you how to read a text file into a string:



Cheers,

Cay

9 months ago
I see what you mean. But a real life example for modules would be a huge and complex project with a very long lifetime--not something that one can put in a book. I have a real-life example of what you need to do when you want to add an Apache Commons JAR to a modular program. That is something you may actually run into.

Cheers,

Cay
9 months ago
JShell is my favorite feature. And InputStream.readAllBytes and List.of/Set.of/Map.of. My least favorite feature? Modules. The kale of programming :-)

Cheers,

Cay
9 months ago
I wouldn't go as far as saying it's a cookbook. I've seen some books that were organized like that: "How to read a file". "How to run a process." "How to sort an array". But it gets artificial pretty quickly: "How to write a constructor". "How to form a subclass".

Of course, you will see in the section on files how to read and write files, and in the section on processes how to run a process.

The book is at an intermediate level. It assumes that you know how to program in some language. I am not telling you what loops, arrays, and classes are.

And yes, I talk about most of the new Java 9 stuff, including multi-release JARs (but not about propeller head stuff like OCSP stapling).

Cheers,

Cay
9 months ago
I really can't speak to that--I don't know much about certification exams. Maybe someone else can chime in?

Cheers,

Cay
9 months ago
This is a modern Java book. It introduces lambdas early and uses them as the standard mechanism for callbacks.

Cheers,

Cay
9 months ago
That is so true. It motivated me to write "Java SE 8 for the Really Impatient". And I just saw "Java EE 8--Only What's New". BTW, with a bonus HTTP/2 chapter. I couldn't resist and bought it.

Cheers,

Cay
9 months ago

A Kao wrote:
Does "a whole book" mean 500+ pages?
Your "Java SE8 for the Really Impatient" book is 240 pages.   Will you write a short book on REST for similar page counts in the future?



Many years ago, I wrote a college textbook on object-oriented design. A book reviewer of Dr. Dobb's Journal (the young ones won't know what that was) wrote "Horstmann is a man of few words", and it was meant as a compliment. I could maybe write a 100 page book on REST programming, but I marvel at the authors who can stretch it out to 300+ pages. I think I'll leave that to them, and add a quick introduction into a future edition of Core Java.

Cheers,

Cay
9 months ago
I think that's what I do. When introducing a new feature, I try hard to come up with a plausible scenario where it can be useful--and often, where I have used it.

I've never liked programming examples with ducks that quack and mice that squeak, or complex scenarios where the author triumphantly explains that now we have a creature that squeaks before quacking or some such thing. The mental effort to map the scenario to my problems seems enormous.

One of my favorite programming books of all time is the Kernighan & Ritchie C book. Many code snippets from that book could have come from a real project. I aim for the same effect. Is that what you mean with "use case"?

Cheers,

Cay
9 months ago
When I first saw the new HTTP client, I had high hopes that it would come with support for REST. At the very least, a JSON content handler. But nooo...I was told that JSON was not a part of the core platform, so that not something they'd sully their hands with. The HTTP client doesn't do forms or file upload either. This is one of the few times that I may end up breaking my own rules and cover a non-core API in Core Java. But I don't think I'll write a whole book on REST.

Cheers,

Cay
9 months ago
My students keep telling me to move to IntelliJ, and I give it the good try ever so often, and then I find myself back in Eclipse. I grant that IntelliJ can do some amazing things, but it can also suck up an amazing amount of time when it does the wrong thing and you have to mess with the settings. Maybe one day I'll make the switch for good.

Cheers,

Cay
9 months ago
I don't think the sweet spot for JShell is to create classes and functions. It can be done, but I don't often find myself doing that. But I frequently add a JAR with some library that I want to learn to the class path, and then construct instances and invoke methods. IntelliJ lets you use a JShell like thing to work with your project's classes, but I couldn't get it to work. (Undoubtedly it will evenutally when I figure out which of the multitude of settings to set just so.)

Cheers,

Cay
9 months ago
Hi, it's good feedback that you want HTTP/2 push covered.

Generally, I stick to use cases that (a) aren't bleeding edge and (b) are of interest to application programmers, not system programmers. If in a year or two, application programmers have to worry about this, I'll put it into the book.

I think it's an important skill to eyeball a new feature and gauge whether it has a broad impact. For example, someone who should remain nameless (Simon Ritter) gives presentations about new features in Java 9 that contain such gems as "PKCS12 key stores by default" and "Spin-Wait Hints". These are important features only for the small number of heroes who give us application programmers better-performing libraries and tools. The service that I aim to provide is that I don't put them in my books.

Of course, I am sometimes wrong, so if you feel that I am missing the boat on an important feature, let me know.

Cheers,

Cay
9 months ago
The dedication in "Scala for the Impatient" says it all :-)

I would like to thank my wife for making this book possible and my children for making it necessary.



Seriously, what could be better than to keep learning and to tell others about all the things that you find out?

Of course, it is impossible to follow everything--computing has become so incredibly vast. At some point, you have to filter and see what you like. I enjoy working with programming languages, but I am somehow not so attracted to machine learning. I've dabbled with it, and I appreciate its power, but it seems messy and ad-hoc. And I've made the decision that Bitcoin just isn't my thing at all. So, I spend a good amount of time keeping up with what I really like, and enough time with broad trends to understand the basics.

It's a big job, but then again, wouldn't the alternative be much worse? Imagine your specialty is divorce law or some such thing, where nothing new happens for years on end. I would find that really dreadful.

Cheers,

Cay
9 months ago