Since the release of JDK1.0 in 1996, Java has become popular with a wide range of active users, including students, programmers, and people in the software industry as a whole. The language is so vibrant that it is constantly being used in projects large and small. From Java1.1 (1997) through Java 7 (2011), Java has been well updated with new features. Java 8 was released in March 2014…

JDK1.8 has become a hot topic in the JDK release and is often asked about in job interviews.

Less code and more simplicity

The biggest reason for the attention is that JDK1.8 is making changes that are, in many ways, more profound than any change in Java history. And the good news is that these changes will make it easier for you to get started without having to write tedious programs like the one below. (Sort the peopleList by age)

Collections.sort(peopleList, new Comparator<People>() { public int compare(People o1, People o2) { if (o1.getAge() > o2.getAge()) { return 1; } else { return -1; }}});Copy the code

In JDK1.8, you can write more concise code like this:

Collections.sort(peopleList, Comparator.comparingInt(People::getAge));
Copy the code

You’ll love this kind of neat code since you’ve been exposed to JDK1.8.

Better use of multi-core processors

JDK1.8 is better for multi-core processors: most computers and servers have multi-core cpus, but most existing Java programs use only one of these cores, leaving the rest idle.

Before JDK1.8, you might have been told that you had to use multiple threads to use multiple kernels. The problem is that threads are difficult to use and prone to errors. The JDK has evolved to make concurrent programming easier and less error-prone. JDK1.0 had threads and locks, and even a memory model — best practice at the time, but these basic models proved difficult to reliably use by project teams without expertise. JDK1.5 adds things like thread pools and concurrent collections. The addition of a fork/join framework in JDK1.7 makes parallelism more practical, but still difficult. JDK1.8 takes a new, simpler approach to parallelism, but with a few rules to follow.

JDK1.8 provides a new API(called “Streams”, or Streams) that supports many parallel operations on data, similar to the idea in database query languages: express what you want in a higher-level way, and the “implementation” (in this case the Streams library) chooses the best low-level execution mechanism. This avoids writing code in synchronized, which is error-prone and more expensive to execute on multi-core cpus than you might think.

faster

If your development environment is installed with JDK1.8, you are already enjoying the new features of JDK1.8.

JDK1.8 has some updates and changes to the underlying data structure, some changes to the garbage collection mechanism (memory structure), easy use of parallel operations for parallel/parallel streams, some extensions and support for parallelism.

How does it make the underlying data structure “faster”? We all know that the core of the underlying data structure is a HashMap, so how does it change the HashMap?

What was the original HashMap like? (Array + linked list)

What will HashMap look like after 1.8? (Array + linked list + red-black tree)

When the list length becomes too long (more than 8 by default), the list is converted to a red-black tree. What problem does the red-black tree improvement solve?

Optimization of HashMap collision processing, for the check of very long chains, time complexity is reduced from O(n) to O(log2n).

The HashMap optimization is just one example of how JDK1.8 is going to be faster than the others.

conclusion

This should give you a good idea of why you should pay attention to JDK1.8. Because it brings unprecedented benefits to our development and system, in the subsequent use, you will find its various advantages.