Java Learning (2)

Source: Internet
Author: User
Tags bitwise operators

Java Basic Detail Record

The index of Java is not the case starting from 0:

  The format parameter index is starting from 1, not 0:system.out.println (%1 $ s%2$s, "Test:", "OK");

In Java, when using the while loop, be careful to endless loop, because while is when the meaning, it is easy to stop the condition without stopping the operation can not be terminated;

Each case in a switch in Java needs to have a "break;" and the default statement is used to handle any case other than the case; And the case label must be an integer or enumeration constant;

String equals (), disables "= =", except (string A = = null); The = = Comparison of string is a comparison of storage addresses, and if strings are obtained by stitching or other operations, there will be inconsistencies, so you cannot use them to avoid the occurrence of bugs:

e.g.

1  Public Static voidMain (string[] args) {2         //TODO auto-generated Method Stub3         4String A = "AB";5String B = "A";6String C = b + "B";7         if(A = =C) {8System.out.println ("A==c is true");9         }Ten          One         if(A.equals (C)) { ASystem.out.println ("A equals B is True");  -         } -}

Output:a equals B is true;

Constant declaration: final (constant is not recommended for reserved keywords)

operation of double type note: 2.0-1.1=0.8999999 ...

operator with self-decrement: use note because the order of updates and operations affects the final result

confusion of bitwise operators and relational operators:

"|, &, ^, ~" and "| |, &&,!"

Conversion of numeric types:

  Countless data loss conversions

BYTE---------long

|--> Double <--Float

CHAR-to-int

  There is data loss

int---> FLOAT <---long---> Double

Methods of the Math class:

Math.Round implementation rounding;

Java.math.XXXX compare cattle break;

Copy assignment:

The assignment of an object is the assignment of a reference, and if the copy is modified, the reference points to the content being modified, causing the entire object value to change, and if the other single assignment statement is only a single aspect of the value change does not affect each other;

Commonly used statement writing:

Condition?expression1:expression2;

for (type Para:paraset) {}

Java Learning (2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.