Han shunping's Java video tutorial easily ignores knowledge points

Source: Internet
Author: User

1.

In Java, char is a two-byte string that can store one word...

Char A = 'zhao ';

Uses unicode encoding...

When char is computed in Java, it is treated as an integer corresponding to the ASCII code...

2.

Java is very accurate.

The precision is sequential from high to low

Byte <short <int <long <float <double

Only low-precision conversion to high-precision Conversion

And a decimal point in Java, such as 1.1, is double by default.

For example:

Int A = 1.2; // incorrect. Double cannot be converted to int because the precision of double is higher than that of Int.

Double A = 1; // correct

Float a = 1.2; // error...

Float a = 1.2f; // F indicates a float type.

For example:

Int A = 1;

Int B = a + 2.3; // the error message is displayed. The result of A + 2.3 is double, and double cannot be converted to int.

3. Static blocks in Java

class Parent {static String name = "hello";{System.out.println("parent block");}static {System.out.println("parent static block");}public Parent() {System.out.println("parent constructor");}}class Child extends Parent {static String childName = "hello";{System.out.println("child block");}static {System.out.println("child static block");}public Child() {System.out.println("child constructor");}}public class Monster {static {System.out.println("aaaaaaaaaaaaaaaaaaa");}public static void main(String[] args) {new Child();}}


Output:

Aaaaaaaaaaaaaaaaaaa
Parent static Block
Child static Block
Parent Block
Parent Constructor
Child Block
Child Constructor

The most, the most, the most curious is ....

If you are watching/new child ();

The output will only be:

Aaaaaaaaaaaaaaaaaaa


Object initialization sequence: first, execute the static content of the parent class. After the static content of the parent class is executed, execute the static content of the Child class. After the static content of the Child class is executed, check whether the parent class has non-static code blocks. If yes, execute the non-static code blocks of the parent class. After the non-static code blocks of the parent class are executed, execute the construction method of the parent class; after the constructor of the parent class is executed, it goes on to check whether the Child class has non-static code blocks. If so, it executes the non-static code blocks of the Child class. The non-static code block of the subclass is executed before the subclass constructor is executed. In a word, the content of the static code block is first executed, followed by the non-static code block and constructor of the parent class, and then the non-static code block and constructor of the subclass are executed.

Strong reference: http://www.cnblogs.com/panjun-Donet/archive/2010/08/10/1796209.html

4.

Package Functions

1. differentiate classes with the same name

2. Convenient management when there are many classes

3. control access scope

5. Java specifications

Naming rules for Java identifiers: 1) identifiers are composed of letters, numbers, underscores (_), dollar signs ($), or RMB signs ($). The first letter cannot be a number. 2) keywords and reserved words cannot be used as identifiers. 3) There is no length limit on the identifier. 4) The identifier is case sensitive. Java programming specifications: 1) Class Name and Interface Name: upper-case letters and lower-case letters. For example, samdoc2) method name and variable name: the first letter is lowercase, And the other letters are uppercase. Such as botheyesofdoll. 3) package name: All letters are in lower case. For example, Com. ABC. dollapp. 4) constant names: in upper case, the words are separated by an underscore. For example, default_color_dol.

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.