Learn Java Notes (3)

Source: Internet
Author: User
Notes

61. Each class has only one class variable, and objects belonging to that class share the class variable. You do not need to access class variables through objects.
62. A static method can only access the static data of a class; A static method can only access the static method of the class; it's not a problem.

Use this in the Word method; A static method cannot be replaced by a non-static method.
63, the constructor does not return a value, it needs to be the same as the same name, if the class used does not have a constructor, the Java compiler will automatically birth

into a default constructor (without parameters).
64, Java, new is not omitted, use new to indicate that the variable's memory is dynamically allocated, but must remember to release the memory.
65, the base data type holds its value on the stack, and the reference data type refers to its reference to the existing stack, but the object it references is

exists in the heap (heap).
66, Java has reference data types and basic data types, but there is only one way of passing, that is, through numerical transfer (Pass-by-value),

is not passed by reference (pass-by-reference). method receives a copy of the original value, and for the underlying data type,

A copy of the data value is received, and for the reference data type, a copy of the reference value is received instead of the

The reference itself.
67, if you want to achieve in Java, such as C + + through the reference pass effect, one way is to use the array as a parameter.
68. In addition to the data members declared as private, the same package class can inherit all other data members, while the other package classes can

Inherits public and protected data members. These guidelines apply to all data members (class or instance variables) and are also adapted to the

method, but the constructor of the parent class is not inherited. Members that are defined as final cannot be inherited.
69. You cannot declare signatures (method names, number of parameters, parameter types) of the same class but return different values when using method overloads

Method.
70. The method overload is called a static method binding or a forward binding because the compiler determines the type and number of arguments based on the

Which method is invoked, rather than at execution time.
71. Many classes can be placed in the same file, but only one class is declared public, and other classes are called helper classes

, a secondary class can also contain main (), but is ignored.
72. This class must be declared abstract as follows:
The class has one or more abstract methods (a method declared but not defined)
The class inherits one or more abstract methods from an abstract class, but does not provide an implementation method for these methods
This class implements an interface, but does not implement all the methods of the interface
73. The abstract method cannot be declared private because the abstract class is inherited by other classes. Unable to generate an abstract class

Object, but you can declare a variable of an abstract class type.
74. Polymorphism (polymorphism) represents the same notation that can be used to handle many different types of data. Overloading is a polymorphic type, called

Static polymorphism. The general polymorphism is dynamic polymorphism, which determines the behavior of a method based on the object at execution time, which is a dynamic method of binding

Set (late bound).
75, C + +, polymorphism through virtual function implementation, Java using the abstract class to achieve polymorphism.
76. An interface is used to indicate what a class can do, but does not indicate how it is done (the actual work will be done by programmers using this interface)

, so the interface is often used to develop the Protocol for Class Design (protocol), and the main spirit of Java API design is to connect the interface and the actual class

implementations, because different systems may have different implementations, but the user is using the same method, which resolves the removable

Implant sex problem.
77, interfaces and classes can be used as a data type, but like an abstract class, it cannot be used to generate new objects.
78, an interface is a group of constants and abstract methods, the constants within the interface is always public and static and final (therefore

, sometimes we simply use interfaces to store user-defined constants without any methods, and methods are always public and

Abstract, even if not expressly stated.
79, a class can implement the interface through the keyword implements, and the class can implement more than one interface.
80, the same as the class definition, an interface can inherit other interfaces through extends, but the interface supports multiple inheritance because

The methods inside the interface are undefined and do not produce problems with multiple inheritance of classes.
81, unlike the abstract class, when a class implements an interface, this class must define a method within all interfaces.
82. Combine the interface with the abstract class. In addition to using interfaces for multiple inheritance, a common design approach is to use interfaces

To generate a new data type, but will not be limited by a specific implementation, which is similar to the basic data type and does not generate the type of

object, nor does it implement any methods. Abstract classes can also be used to define new data types, but they will selectively implement common methods.

Of course, generic classes can also be used to define new data types, but all methods are implemented. Therefore, in designing a more scalable data

Type, the interface is often the topmost layer, and the abstract class is the middle layer, and the following is the general class.
83. Defining a class within another class is called an inner class.
84. An anonymous class is an inner class without a name, and it has no constructors. Such as:
Button.addactionlistener (New ActionListener ()
{
The program body used to implement ActionListener
}//This object is used only in addActionListener ()
)
85, in Java, the most common use of internal classes and anonymous classes is the GUI.
86. Because anonymous classes do not have names, the generated class files are represented by numbers, such as Outer$1.class
87, Garbage collection: A better way is to set the unused object to null.
88, the enforcement of garbage Collection: System.GC ().
89, Finalize () is executed before the object is released, which is the method that all Java objects inherit.
90, build the package: As long as the definition of the class program in front of the first plus package{packagename};



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.