Java Essential Basics (3)

Source: Internet
Author: User
Tags naming convention

1. The methods that are declared in the interface are abstract methods. The methods in the interface are public.
2.You can also define member variables in an interface. The member variables in the interface are PublicFinalStaticOf
3. A class cannot be both final and abstract. Because the main purpose of abstract is to define a convention,
Let the subclass implement this Convention, and final indicates that the class cannot be inherited, so that abstract expects that class to
Being inherited and final clearly stating that the class cannot be inherited, the two contradictions. So a class cannot be both final,
It's abstract again.
4. Design pattern. Singleton mode (Singleton): Indicates that a class will only generate a unique
An object.
5. Packages (Package). Used to classify classes that complete different functions, and put them under different directories (packages). Package
Naming convention: Reverse the company domain name as the package name. Www.shengsiyuan.com, Com.shengsiyuan (bag
Name), for the package name: lowercase is required for each letter. If the package is not used when defining the class, then
Java thinks that the class we define is in the default package.
6. There are two ways to compile a Java source file with the package declaration:
A) compile directly, and then manually build the directory structure based on the package name defined in the class, and finally the generated class
The file is placed in the directory structure (rarely used, more cumbersome).
b) Use the compile parameter –d, in the form of javac–d. source files. Java, so that after compiling, the compiler will automatically help
Help us build the directory structure of the package.
7. There are two package names, respectively aa.bb.cc and AA.BB.CC.DD, then we call the latter as the former sub-package.
8. Import, import the various classes separated by the package, so that the compiler can find the required
The class.
9. Import syntax: import com.shengsiyuan.PackageTest;
Import com.shengsiyuan.*, which indicates that all classes under the Com.shengsiyuan package are imported.
One. Import aa.bb.* does not import the classes under the aa.bb.cc package. This is the time to write:
Import aa.bb.*;
Import aa.bb.cc.*;
12. Questions about the order of the package, import, class:
A) You need to define the package first, optionally
b) Next use import for importing, optional
c) Then the definition of class or interface.
13. If the two classes under the same package, then you do not need to import, directly use.
14. Access modifier (modifier).
1) Public: the properties and methods that are modified by publicly can be accessed by all classes.
2) protected (Protected): Properties and methods modified by protected can be inside the class, the same package
And the subclass of the class that is accessed.
3) Private (private): properties and methods that are modified by private can only be used inside that class
4) Default (without any access modifiers): used within the class and the class under the same package.
Instanceof: Determines whether an object is an instance of a class. Syntax form: reference name instanceof class
Name (interface name), which returns a Boolean value.
People people = new Man ();
System.out.println (People instanceof people); The result is true, because man is a child of the people
Class, according to inheritance, the subclass is the parent class, so man can also be seen as an instance of people.
18. Comparison of equality (= =)
1) For native data types, the comparison is between the left and right sides of the value is equal.
2) for reference types, compare whether the left and right references point to the same object, or about two
Whether the reference address of the edge is the same.
Java.lang.Object class. The Java.lang package is not explicitly imported when used, and is automatically compiled by the compiler
Help us to import.
API (Application Programming Interface), application programming interface.
21. When a reference is printed, the return value of the toString () method that refers to the object is actually printed, because each
Classes are inherited directly or indirectly from object, and toString () is defined in the object class, so each class has
ToString () This method.
22. About the representation of the system: 16 binary, every 16 into one, 16 binary numbers include: 0~9, A,b,c,d,e,f,
% equals ()Method that defines the method in theObjectclass, soJavaHas this method in each class in the
ForObjectClass ofequals ()method, it is the judgment callequals ()The reference to the method and the incoming citation
Use consistency, that is, whether the two references point to the same object. ForObjectClass ofequals ()Party
method, it is equivalent to==
A .ForStringClass ofequals ()method, it is the content that determines the current string and the string passed in
are consistent.
25. For the equality judgment of a String object, use the Equals () method instead of = =.
String is a constant, and its object cannot be changed once it has been created. When using the + stitching string, a new
String object instead of appending content to the original string object.
. String pool (String pools)
String s = "AAA"; (value is assigned in literal form)
1) Find out if the object "AAA" exists in the string pool, and if it does not exist, create it in the string pool
An "AAA" object, and then returns the address of the "AAA" object in the String Pool, assigning the
Use the variable s so that s points to the "AAA" string object in the string Pool
2) If present, do not create any objects, directly return the "AAA" object address in the String Pool,
Assign to S reference.
string s = new string ("AAA");
1) First find the String object with "AAA" in the string pool, if there is one, it is not in string pool
To create an "AAA" object directly in the heap (heap) to create an "AAA" string pair
And then returns the address of the "AAA" object in the heap to the S reference, causing S to point to the heap
This "AAA" string object is created.
2) if not, first create an "AAA" object in the String Pool, and then in the heap (heap)
Build an "AAA" object, and then return the address of this "AAA" object in the heap to the S reference,
Causes S to point to the "AAA" object created in the heap.

Java Essential Basics (3)

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.