JAVASE basic knowledge Note 8

Source: Internet
Author: User

1. All methods declared in the interface are abstract methods. All methods in the interface are public.
2. You can also define member variables in the interface. All the member variables in the interface are public, final, and static.
3. A class cannot be both final and abstract. Because abstract aims to define a convention,
Let the subclass implement this Convention, and final indicates that the class cannot be inherited.
The inherited final clearly indicates that the class cannot be inherited, and the two are in conflict. Therefore, a class cannot be both final,
It is abstract.
4. Design Pattern ). Singleton: indicates that a class only generates a unique
Objects.
5. package ). It is used to classify the categories for different functions and place them in different directories (packages. Package
Naming rules: the company domain name is reversed as the package name. Www.shengsiyuan.com, com. shengsiyuan (Package
Name). For the package name, each letter must be in lowercase. If the package is not used during class definition
Java considers the defined class to be in the default package ).
6. You can compile Java source files with package declarations in two ways:
A) Compile directly, and then manually create the directory structure one by one based on the package name defined in the class. Finally, the generated class
Put the file in the directory structure (rarely used, it is troublesome ).
B) Use the compile parameter-d in javac-d. source file. java. After compilation, the compiler automatically helps
Help us build the directory structure corresponding to the package.
7. There are two packages named aa. bb. cc and aa. bb. cc. dd respectively. Then we call the latter as the sub-package of the former.
8. import the classes separated by package, so that the compiler can find
.
9. import Syntax: import com. shengsiyuan. PackageTest;
10. import com. shengsiyuan. * indicates to import all classes under the com. shengsiyuan package.
11. import aa. bb. * does not import the class under the aa. bb. cc package. In this case, you need to write:
Import aa. bb .*;
Import aa. bb. cc .*;
12. About the order of package, import, and class:
A) first, you need to define the package. Optional.
B) use import for import. Optional.
C) then the definition of class or interface.
13. If the two classes are under the same package, you can directly use them without importing them.
14. access modifier ).
1) public: attributes and Methods Modified by public can be accessed by all classes.
2) protected: the attributes and Methods Modified by protected can be in the same package within the class.
And the sub-classes of this class.
3) private: the attributes and Methods Modified by private can only be used within this class.
4) default (without any access modifier): used within the class and under the same package.
15. instanceof: determines whether an object is an instance of a class. Syntax format: Reference instanceof class
Name (interface name), returns a boolean value.
16. People people = new Man ();
17. System. out. println (people instanceof People); // The result is true because Man is a child of People.
Class, according to inheritance, the subclass is the parent class, so Man can also be seen as an instance of People.
18. Equality comparison (=) 1) for native data types, compare whether the values on both sides are equal.
2) for the reference type, compare whether the references on both sides point to the same object, or both sides
Whether the reference addresses of edges are the same.
19. java. lang. Object Class. The java. lang package does not need to be explicitly imported when used. during compilation, the compiler automatically
Help import.
20. Application Programming Interface (API), Application Programming Interface.
21. When a reference is printed, the return value of the toString () method of the referenced object is actually printed.
Classes directly or indirectly inherit from objects, while the Object class defines toString (), so each class has
ToString.
22. About the hexadecimal representation: in hexadecimal notation, numbers in hexadecimal notation are: 0 ~ 9, A, B, C, D, E, F,
23. equals () method, which is defined in the Object class. Therefore, every class in Java has this method,
For the equals () method of the Object class, it is used to judge the reference to call the equals () method and the introduced
Use consistency, that is, whether the two references point to the same object. For the equals () side of the Object class
It is equivalent to =.
24. For the equals () method of the String class, it is used to determine the content of the current String and the passed String.
Consistent or not.
25. For Equality Determination of String objects, use the equals () method instead of =.
26. String is a constant and its object cannot be changed once it is created. When the + concatenation string is used, a new
Instead of appending content to the original String object.
27. String Pool (String Pool)
28. String s = "aaa"; (assign values using the nominal value)
1) check whether the "aaa" object exists in the String Pool. If it does not exist, create
An "aaa" object, and then return the address of the "aaa" object in the String Pool
Use the variable s, which will point to the "aaa" String object in the String Pool.
2) If yes, no object is created, and the "aaa" object address in the String Pool is directly returned,
Assigned to s reference.
29. String s = new String ("aaa ");
1) First, find the String object "aaa" in the String Pool. If yes, it is not in the String Pool.
Create the "aaa" object, and create an "aaa" string pair directly in the heap.
And then return the address of the "aaa" object in the heap to the s reference, causing s to point to the heap
The "aaa" String object created.
2) If no, create an "aaa" object in the String Pool, and then create
Create an "aaa" object, return the address of the "aaa" object in the heap, and assign it to s reference,
As a result, s points to the "aaa" object created in the heap.

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.