The fundamental question is, whether your goal is to learn programming (in which case the language doesn't matter at all … theoretically at least) or to learn Java.
If you want to learn programming, the programming language and the version doesn't really matter. It only matters insofar as to understand the examples, and to understand the concepts behind the code, you need to understand the programming language. So, the code and the programming language should be as simple as possible … e.g. a language like Scheme or Smalltalk, or you already need to know the language.
If you want to learn Java, then you should use a recent book, because there has been a lot of stuff introduced that not only makes stuff easier to read and write, but that fundamentally changes the way Java programs are written.
Sun dropped the "2" from "Java 2" in 2004. That should give you an indication as to how old this book is. It covers Java 2 1.4, which was released in 2002.
You don't have to chase every version, every release, every edition, every new feature (especially with the new 6-month release cycle), but since 2002, there have been multiple new features in the Java language that fundamentally change how Java code is written:
- Java 5 (2004):
- Generics
- Annotations
- Autoboxing/Autounboxing
enum
s
- Varargs
- The enhanced
for
loop
- [LIB] JSR166 Concurrency APIs
- Java 7 (2011)
- [LIB] Extended JSR166 Concurrency APIs
- [LIB] NIO.2
- Java 8 (2014)
- Lambdas
default
methods on interface
s
- [LIB] The
Stream
API
- Java 9 (2017)
module
s
- [LIB] Reactive Streams
- Java 10 (2018)
- Local variable type inference
- Java 14 (2020)
[I bolded the ones I deem to be particularly disruptive. I marked some features as [LIB] which are library additions to the Java platform and not language features, but are nonetheless important. E.g. NIO.2 offers a whole new, much higher-level, much improved way of interacting with files. And Stream
s essentially mean that you will never have to iterate over a collection ever again.]
Value Types and sealed
Types will bring another major shift in the near future (possibly as early as Java 15 (October 2020)). In particular, sealed
Types will allow modeling Algebraic Sum Types in Java, which opens up a fundamentally different way of structuring programs.
Oracle has recently started to include so-called Previews as well, these are features that are shipped as part of an official release, so they reach a wide audience, but that are not guaranteed to be supported in future releases in that form. They may be changed or dropped completely. One of those features is record
s that currently ship as a preview in Java 14. While they aren't as disruptive as some of the others (Generics, lambdas, Value Types, sealed
) as they are just syntactic sugar, they allow to drastically reduce the amount of code for simple data classes, and thus make it easier to see what is going on.
For example, this:
final class Point {
private final int x;
private final int y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
public int x() {
return x;
}
public int y() {
return y;
}
@Override
public boolean equals(Object that) {
if (!(that instanceof Point)) {
return false;
}
var other = (Point) that;
return x() == other.x() && y() == other.y();
}
@Override
public int hashCode() {
return x() ^ y();
}
@Override
public String toString() {
return "Point[x=" + x + ", y=" + y + "]";
}
}
Can be written in Java 14 as this:
record Point(int x, int y) { }