I am kite, the public account “ancient time kite”, a not only technology public account, I have been in the app community for many years, mainly Java, Python, React also play 6 slash developer. The Spring Cloud series is complete, and you can check out the full series on my Github. You can also reply “PDF” in the public account to get the full PDF version of my elaborate tutorial.

On April 22, Alibaba released taishan version of “Java development manual”, thought that the ultimate version is really the ultimate version before, did not think or think too simple, after the ultimate version and released a detailed version, Huashan version, this is not, Taishan version came again. Think about it, the industry has been evolving, the JDK has been updated, how can there be a final version.


Since the release of the final version of Alibaba in 2017, I have used this manual as a development specification, put it in the most prominent place on the computer, and read it from time to time, and promoted it among the team, and also gave it to some friends of Amway. Take it down and reread it every time a new version comes out.

The Taishan version of the release, compared with the previous version has the following updates:

  1. Release the unified error code solution.
  2. 34 new protocols are added, such as leap year and leap month problems for date and time, automatic unboxing of trinary arithmetic, restriction of table aliases for SQL queries, and precautions for using the toMap() methods of Collectors.
  3. Change description 90, for example, block wait lock, build table decimal type, etc.
  4. Improve several examples, such as the ISNULL example, etc.

Why read it so often?


Manuals cover everything from project design to coding and deployment. But for individual developers, there are some areas that are not often touched, such as concurrency control, which many people have limited access to. For example, exception definition and MySQL management may have been customized by core developers or architects at the beginning of the project. Some students just follow the principles of design and implementation without caring about specific design principles and implementation details.

The manual is not very long. At only 57 pages, it doesn’t take long to read. Some of these aspects are often discussed, such as command style, constant definition, etc., and some aspects are not so much noticed, such as comment specification, how to write comments, where to write comments, and what format. It is no exaggeration to say that many times, it is already very good to be able to write notes, let alone write notes clearly, and even many people do not write notes at all, thinking it is a waste of time.

This manual is the crystallization of Alibaba’s years of development experience. In addition to naming, annotation and other regulations mentioned above to improve code readability and readability, it also includes correct table building, good engineering structure, good exception handling, security control, and some commonly used JDK anti-pit guide.

Naming style, constant definition, code format

These several basically have written code for several years will have a similar specification, basically and Alibaba developer manual is almost the same.

OOP code

6.【 mandatory 】Object’s equals method is prone to nullpointer exceptions. Call equals using constants or objects that are determined to have values.

Is: “test”. The equals (object); Example: the object. The equals (” test “); Note: Java.util.objects #equals(a utility class introduced in JDK7) is recommended.

Object in the counter example is a variable, and if the variable is null, an exception is thrown. Objects.equals(s1, s2) is recommended.

8. [Mandatory] Any monetary amount shall be stored in the smallest monetary unit and of integer type.

For example, if the minimum unit of RMB is fen, then if the price of a commodity is 1 yuan, it will be stored in the price field of the database. The field type is int or Bigint, the value is 100, and the unit is fen, that is, 100 cents.

I stumbled on this problem a few years ago when a system had a price field that used floating point numbers, units or units, which made it very difficult to calculate prices later, and floating point numbers were not completely accurate, especially when decimal places were involved. Finally, the field was set to int, and everything in the code related to the price was refactored.

So, when I read this rule in the handbook, it was like I had never seen it before. I learned this lesson the hard way, and it would have saved me a lot of trouble if I’d seen it sooner.

9. [mandatory] Equals between floating-point numbers. Base data types cannot be compared with equals, and wrapper data types cannot be compared with equals.

Example:

float a = 1.0 f - 0.9 f

float b = 0.9 f - 0.8 f;

 if (a == b) {

 // Expect to enter this code quickly, execute other business logic // but in fact a==b results in false

}

Float x = Float.valueOf(a);

Float y = Float.valueOf(b); 

if (x.equals(y)) {

  // Expect to enter this code quickly to execute other business logic

  // The result of equals is false

}

Copy the code

Until you write floating-point calculations, you think that’s just math, and that’s what computers are designed to do. It was not until I came into contact with floating-point calculation that I found it completely different from what I had imagined, just like the counterexample above. The reason is that computers use binary and cannot express decimal exactly. If you are interested, you can search for the principle behind it.

The correct approach is to use a high-precision BigDecimal, which is intended to do high-precision calculations that floating point numbers cannot do.

The date format

There are a lot of students are not very familiar with the date processing, often for a long time do not use, use to go to the Internet to check, in fact, I am not often used, to let me now hand write a date processing method also have to check API, for this purpose specially wrote a date processing tool class. For example, LocalDateTime issued after JDK 8 can replace the previous Date.

Date2)java.sql.Time3) java.sql.Timestamp** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** * I’m already using LocalDateTime anyway.

Set processing

Collections are very frequently used data structures in our development, and we recommend reading each one carefully and applying them to our projects. This is not a development manual, this is to tell us how to use Java collections properly.

Concurrent processing

How to use thread pools correctly SimpleDateFormat is not thread-safe and uses ThreadLocal correctly. There are lessons behind each one.

Exception handling

How try-catches are used, how the same module handles exceptions, how different services handle exceptions, and so on.

MySQL

How to create tables, when to split tables, how to name tables, field names, appropriate field types, how to create indexes, good SQL statements, ORM mapping, all can be dug down.

Engineering structure

What is the hierarchical structure of the project standards, the management of the dependent libraries, the key tuning metrics of the server, etc.

Design specifications

Standardize a project’s documentation, design process, and so on from an architect’s perspective.

Error code

Error codes are friendly responses to logic problems or system errors. Each platform should have only one copy of the error code, no more, no less. A complete list of error codes is published at the end of the manual.

Can read the manual understand at one time, that is absolutely a master, most people may not understand a part of the statute. But it’s all very basic, so getting this manual completely understood before you start reading all those interview manuals will improve your programming skills a lot, too.

Alibaba code specification IDEA plug-in

Alibaba also issued a development statute of IDEA plug-in, with the development manual is perfect. You can search “Alibaba Java Code Guidelines” on the INTERFACE of IDEA plug-in management for installation.

After that, you can see this plug-in under the Tools menu of IDEA. It can be dynamically enabled or disabled and the language can be switched.


When enabled, when we write code that violates the protocol, it will give you a warning. For example, if I compare two integers with == in the code, it will give you a warning under == and tell you what the correct posture is.


Manual download

For those of you who haven’t downloaded it, download it and read it twice.

Official download address, need to log in ali cloud.

Developer.aliyun.com/topic/java2…

If you don’t have Aliyun, you canClick download


I am kite, public id “ancient Time kite”, I have been working in the application circles for many years, mainly Java, Python, React also play very 6 slash developer. Can add my friends in the public account, into the group of small partners exchange learning, a lot of dachang students are also in the group yo.

Technical exchange can also add group or directly add my wechat.