Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the specification of java ternary operator

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what is the specification of java ternary operator". In daily operation, I believe that many people have doubts about what the specification of java ternary operator is. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the question of "what is the specification of java ternary operator?" Next, please follow the editor to study!

1. Error code specification

There is no overall description of "error code" in the previous version, but this version has added a lot of space to make a detailed specification and explanation of the important part of "error code", which is an important part of the cooperation between front and rear. The specific specifications are as follows:

[mandatory] principles for the formulation of error codes: fast traceability, easy to remember, communication standardization. [mandatory] the error code does not reflect the version number and error level information. [force] all normal, but return five zeros: 00000 when you have to fill in the error code. [mandatory] the error code is a string type with a total of 5 digits, which is divided into two parts: the source of the error + four-digit number.

Note: the source of the error is A/B/C:

A: indicates that the error comes from the user, such as parameter error, user installation version is too low, user payment timeout and other problems; B: indicates that the error comes from the current system, often due to errors in business logic, or poor program robustness; C: indicates that the error comes from third-party services, such as CDN service errors, message delivery timeouts, etc. The four-digit numbers range from 0001 to 9999, and the step spacing between large categories is reserved for 100. for details, please see the text of the Java Development Manual. two。 Extended date processing scheme

The number of days in a year written to 365 days makes everyone feel sad in a leap year, for example, cache validity = 3652460-60 seconds, as a result, all caches expire one day earlier, and the database kneels when high concurrency access occurs.

[force] do not write a year for 365 days in the program to avoid date conversion errors or program logic errors in the Gregorian calendar leap year.

Positive example:

/ / get the number of days this year

Int daysOfThisYear = LocalDate.now () .lengthOfYear ()

/ / get the number of days in a specified year

LocalDate.of (2011, 1,1). LengthOfYear ()

Counterexample:

/ / the first case: an array out of bounds exception occurs on the 366 day of the leap year

Int [] dayArray = new int [365]

/ / the second case: the membership system with an one-year validity period is registered on January 26 this year, but 365 is hard-coded to return January 25.

Calendar calendar = Calendar.getInstance ()

Calendar.set (2020, 1,26)

Calendar.add (Calendar.DATE, 365)

3. Table alias specification

[mandatory] for queries and changes of table records in the database, as long as multiple tables are involved, the table name should be qualified. Description: when querying records, updating records, or deleting records on multiple tables, an exception will be thrown if there is no alias (or table name) for the operation column, and the operation column exists in multiple tables. Positive example: select t1.name from table_first as T1, table_second as T2 where t1.id=t2.id

Counterexample: in a business, because the multi-table association query statement does not add the alias (or table name) of the table, after two years of normal operation, a field with the same name has recently been added to a table. After making database changes in the pre-release environment, the online query statement has a 1052 exception: Column 'name' in field list is ambiguous.

[recommended] the alias of the table in the SQL statement is preceded by as, and the aliases are T1, T2, T3,. The order is named in turn. Description:

The alias can be the abbreviation of the table, or it can be named in T1, T2, T3, depending on the order in which the table appears. Adding as to the alias makes it easier to identify the alias. Positive example: select t1.name from table_first as T1, table_second as T2 where t 1. Id investors 2. ID share 4. Specification for ternary operators

It turns out that in the trinomial operator:

Condition? Expression 1: expression 2

Expressions 1 and 2 trigger automatic unpacking when arithmetic calculations or data type conversions are involved. There was no problem with the unpacking operation, but when the Operand was null, a big NPE (NullPointerException) hit me in the face, as shown in the following code:

Integer a = 1

Integer b = 2

Integer c = null

Boolean flag = false

Integer result = (flag? A * b: C)

Note: if the result of aroomb is of type int, then c will force the unpacking to be of type int and throw a NPE exception.

[mandatory] ternary operator condition? Expression 1: in expression 2, pay close attention to the fact that expressions 1 and 2 may throw a NPE exception caused by automatic unpacking when the type is aligned.

Note: the following two scenarios trigger the unpacking operation of type alignment:

As long as one of the values of expression 1 or expression 2 is the original type. The type of the value of expression 1 or expression 2 is inconsistent, which forces the unboxing to be upgraded to the type that represents a wider range. At this point, the study of "what is the specification of java ternary operator" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report