# introduction

Speaking of Mount Tai, I can’t help but think of the last version of Mount Huashan, I believe I have seen many old iron. But the update of the new version of the manual content is more not to be underestimated, Taishan is the Chinese traditional meaning of the seal of the mountain, which also means that Ali this production of Taishan version of the Java development manual, is the most heavyweight so far.

Huashan version is the last version, when was it updated? June 13, 2019. It’s been almost a year now, and it’s time to update.

What has been updated in the new edition? We can see this by comparing the official version history.

First, release the unified solution of error codes

What’s the error code for? The answer is an exception log, which allows us to quickly identify the source of the error and determine who caused it. In the figure above, A indicates that the error originated from the user. And grade B, which means the error originated in the current system; Level C: indicates that the error originated from a third-party service, such as a CDN server.

This solution is worth learning, many mature systems are using error codes, if you have connected to wechat pay, you should be familiar with error codes. It’s nice to see the error code and then look it up in the manual to quickly figure out what kind of error it is.

Ii. Add 34 new regulations

However, 34 points are a little too much to say, so I’ll pick out a few important ones here.

1. Date and time

Remember the tech scene last time? That’s the problem with YYYY and YYYY. The big Y is the week of the day, and the little Y is the year of the day, so there’s a big difference. You taste, you fine taste.

Also, capital M is not the same as lowercase M, capital H is not the same as lowercase H.

Also, keep in mind detailed rules such as using System.currentTimemillis () instead of new Date().getTime() to get the current number of milliseconds.

2. NPE problem of ternary operation

To tell the truth, this problem I have never paid attention to, this time to see, to learn together. Let’s start with the following code:

public class TestCondition {
    public static void main(String[] args) {
        Integer a = 1;
        Integer b = 2;
        Integer c = null;
        Boolean flag = false; Integer result = flag ? a * b : c; }}Copy the code

If a * b is an arithmetic operation and the result of the multiplication is an int, then the Integer c will be unboxed automatically. If the value is null, the following error will be raised:

Exception in thread "main" java.lang.NullPointerException
	at com.cmower.mkyong.TestCondition.main(TestCondition.java:9)

Copy the code

You may be wondering why two variables of type Integer multiply together to make an int. This is largely determined by the compiler, which is how it is designed. Take a look at the decomcompiled bytecode:

public class TestCondition
{
    public static void main(String args[])
    {
        Integer a = Integer.valueOf(1);
        Integer b = Integer.valueOf(2);
        Integer c = null;
        Boolean flag = Boolean.valueOf(false); Integer result = Integer.valueOf(flag.booleanValue() ? a.intValue() * b.intValue() : c.intValue()); }}Copy the code

IntValue () = intValue(); intValue() = intValue(); intValue(); See?

3, Collectors toMap () method of the manual, in the use of Java. Util. Stream. The Collectors class toMap () method to turn the Map, be sure to use contains the parameter types for BinaryOperator, Method with the parameter name mergeFunction, otherwise IllegalStateException will be thrown when the same key value is present. This paragraph may be a little difficult to understand, so let’s look at a piece of code!

String[] departments = new String[]
Map<Integer, String> map = Arrays.stream(departments)
        .collect(Collectors.toMap(String::hashCode, str -> str));

Copy the code

When this code is run, an exception is thrown with stack information like this:

Exception in thread "main" java.lang.IllegalStateException: Duplicate key 867758096 
	at java.base/java.util.stream.Collectors.duplicateKeyException(Collectors.java:133)
	at java.base/java.util.stream.Collectors.lambda$uniqKeysMapAccumulatorThe $1(Collectors.java:180)

Copy the code

The key is duplicated because the two “codes” have the same hashCode.

String[] departments = new String[] 
Map<Integer, String> map = Arrays.stream(departments)
        .collect(Collectors.toMap(String::hashCode, str -> str, (v1, v2) -> v2));

Copy the code

Add an additional argument (v1, v2) -> v2. Take a look at the toMap() method called at this point.

public static <T, K, U> Collector<T, ? , Map<K,U>> toMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper, BinaryOperator<U> mergeFunction) {return toMap(keyMapper, valueMapper, mergeFunction, HashMap::new);
}

Copy the code

Are BinaryOperator and mergeFunction present?

Iii. Modify 90 parts of the description

The manual says, for example, that the descriptions of blocking wait locks, the decimal type of the table are changed, and I spent half an hour without finding any differences from the previous version.

I don’t know if the handbook is small make up, if you can find the difference, let me know.

Four, improve several examples

For example, the ISNULL example in the SQL statement column does add a more detailed counter example than the Huashan version, as shown below.

But to be honest, I had to read that counter example description at least six times before I figured it out. First of all, it’s true that line breaks before NULL affect readability; Second, do not use column is null for nullation. Use ISNULL(column) for nullation, which is more efficient and does not result in line breaks.

select * from cms_subject where column is null and
column1 is not null;

select * from cms_subject where ISNULL(column) and
column1 is not null;

Copy the code

Five, the last

In December 2016, Ali opened the Java Development Manual to the industry for the first time. It has been more than 3 years since the taishan edition was released. This manual has also become a universally followed development standard in the industry with the joint efforts of Java developers around the world. This manual contains very comprehensive knowledge points, seven dimensions programming protocol, exception log, unit testing, security protocol, MySQL database, engineering protocol, design protocol are listed.

You can also get more Java learning documents by replying to “Information”. Are arranged by small editor, as shown in the following picture!

Also sincerely wish everyone, can learn something, today’s content is over here, thank you for watching!!