[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Alyxandra Harp wrote:From my understanding of null, it means the variable has no value. It is not any number, not even 0.
Baz Edwards wrote:
It's very annoying and probably one of the main downfalls of Java as a language because it means you have to check variables for null everywhere, otherwise you'll get NullPointerExceptions being thrown, which is never a good thing.
In Java 8 there has been some attempt to alleviate the pain ... but it's still a bit of a pain, but one you learn to live with ;)
Junilu Lacar wrote:
Baz Edwards wrote:
It's very annoying and probably one of the main downfalls of Java as a language because it means you have to check variables for null everywhere, otherwise you'll get NullPointerExceptions being thrown, which is never a good thing.
In Java 8 there has been some attempt to alleviate the pain ... but it's still a bit of a pain, but one you learn to live with ;)
Well, ...
When you find yourself dealing with that problem too much, then you have to look at the design. For example, if a method that declares an object reference return type like List is returning null, then you have to ask why it does that instead of returning an empty List. If it returns an Object and is returning null, you should ask if it's better to return a Null Object instead. These are just two ways you can create a better API and relieve the client code from having to check for null all the time.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Baz Edwards wrote:I'm just making the point that Java should never have been designed with the concept of null in the first place, but that's just my opinion.
Regards Pete
Sydney Baxter wrote:Null is the lack of anything. A value hasn't been assigned to a saved space, so it doesn't have anything it can output or use for any other function.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Is “fortunately” quite the right word there? If you abuse a null in C you are liable to get a segmentation fault, which is much harder to understand than an Exception in Java®.Tim Holloway wrote:. . . Fortunately, C doesn't throw NullPointerExceptions. . . .
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Campbell Ritchie wrote:Thank you. Does that mean Eckel was mistaken, or have I simply misread the book?
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Tell me how it all turns out. Here is a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|