You may wonder if double checked locking (DCL) works in Java. It does and it doesn’t. I explain why. Continue reading “Double Checked Locking in Java”
Category: Misconceptions
Common misconceptions on programming and computer science in general.
I try answerings questions in a facebook group and often stumble over the same misconceptions. These are merely my thoughts on the topic and not a substitution for a proper text book. A good book can sometimes leave out certain details but it would not lead you to a complete misunderstanding of the topic.
What are References in Java?
So Java has references. But what about pointers and pass-by-reference? References in Java are different to PHP, C# and other languages. And this can cause some confusion. Continue reading “What are References in Java?”
Java knows no Constants
Java (both the language and the JVM) are not aware of constants. To reduce confusion it’s better to not use the term “constant” in Java code, unless it’s actually a universal constant. Continue reading “Java knows no Constants”
Java is not slow
A language can’t be slow. Or how fast do you think English is?
And modern JVMs are highly optimized. Continue reading “Java is not slow”
Dos and Don’ts
Here’s some advice to all who have just begun learning Java. This also serves as an overview to my blog, where I write about all kinds of misconceptions and common problems with programming in Java. Continue reading “Dos and Don’ts”
Misconceptions about the “extends” Keyword
Some Mammals can fly. Dog extends Mammal, but it can’t fly. The term “extends” leads to some misconceptions. Continue reading “Misconceptions about the “extends” Keyword”
Functions in Java
There’s a lot of confusion about “functions” in Java. Java doesn’t really have them, but an object could represent a function so it kind of does have them. I try to explain the different meanings of “functions” in Java, other languages and in mathematics.
Continue reading “Functions in Java”Misconceptions about the new Operator
New is used to create new objects. But it’s used carelessly.
Continue reading “Misconceptions about the new Operator”Misconceptions about Object.hashCode()
The given implementation for hashCode
is somewhat a mystery. Some misconceptions about it confuse students. I try to explain it. Continue reading “Misconceptions about Object.hashCode()”
Generics
Generics have one thing in common with regular expressions: Students think they are an easy to use tool but they just end up with code they do not understand and can’t maintain. Regular expressions can often be replaced by well written and documented code. But you can’t just replace generics. A student using collections with generic type parameters but not fully understanding the concept is still better than one using “raw” collections. And it’s often ok to use something just to get familiar with the idea before learning the theory. The downside is that many misconceptions emerge from this approach of teaching. In this post I try to explain some of the common misconceptions on generics in Java.
Continue reading “Generics”