Java Language Foundation Lesson 02 Summary of the second lecture

Source: Internet
Author: User

A good habit of programming

1. comment habits. Single-line Comment://, Multiline Comment:/* */.

2. add the appropriate blanks in the program:4 spaces .

3. The file name must be the same as the public class name, which is the common class name .

there can be more than one public class in 4.java, but the public class behind must be nested in the previous public class, as well as a public class that can be used locally .

5. constants that are defined by the final keyword are not modified .

Two. Java specification of identifiers

1. Define the class name first letter capitalization

2. First letter of the two words of the function name

3. Constant name All uppercase

4. Package name All lowercase

5. Make sense of the name of the identifier

6. The name of Chinese characters may appear garbled in code porting platform, so it is less used or not.

Three Principle of use of variables

The variable is guaranteed to have an exact value before it is used .

Four. Scope of variables

each variable has a "valid" area, and the out-of-zone variable is no longer valid . Java follows the masking principle of a variable of the same name, and the private static variable value=1is defined in the class. A value=2 is defined in the function, the value is output in the function , and the result is 2. If there is no definition in the function value , the output is 1.

Five. on The accuracy of double type numerical operation and its solution

defines two variable number1=0.01;number2=0.05 of type double;

number1+number2=0.06000000000000005;

It is obvious that the result is imprecise.

reason: Binary with decimal conversion of the pot .

Workaround: Define String type number1,number2 , etc., accepted with Objects of the BigDecimal class number,

in the call the subtraction function in BigDecimal .

Six. hands -on brain- problems with output in java

The + sign in System.out.println() , which is an operator when a numeric type is concatenated, is a connector when the string is concatenated .

Java Language Foundation Lesson 02 Summary of the second lecture

Related Article

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.