30 basic concepts for beginners of java

Source: Internet
Author: User

30 basic concepts for beginners of java

Core Tip: the only link in OOP is what the object interface is, just like the computer vendor, no matter what the internal structure of the power supply is, it only depends on whether the power can be provided to you, that is, as long as you know can or not rather than how and why.

Basic concepts:

1. the only link in OOP is what the interface of the object is. Just like a computer vendor, no matter what the internal structure of the power supply is, it only depends on whether it can provide electricity to you, that is, as long as you know can or not rather than how and why. All programs are composed of certain attributes and behavior objects. Different objects are accessed through function calls, And all communication between objects is done through method calls, by encapsulating object data, the reuse rate is greatly improved.

 

2. The most important idea in OOP is the class. The class is the blueprint of the template. An object is constructed from the class, that is, an instance of the class is created ).

 

3. encapsulation: it refers to the implementation process of combining data and behavior in a package) and hiding data for the object user. The data in an object is called its instance field ).

 

4. Extend a class to obtain a new class called inheritance. All classes are extended by the Object root superclass. The root superclass are described below.

5. Three main features of the object

Ehavior --- describes what this object can do.

Tate-the reflection of an object when the object applies a method.

Dentity --- a distinction between dentity and other similar behavior objects.

Each object has a unique indentity, which affects each other.

 

6. Relationships between classes:

Use-a: dependency

Has-a: Aggregation relationship

Is-a: inheritance relationship -- for example, Class A inherits class B. At this time, Class A not only has class B's methods, but also its own methods. (personality exists in commonalities)

 

7. constructor for constructing objects: constructor is a special method for constructing and initializing objects.

For example, the Data constructor is called Data.

Ew Data () --- construct a new object and initialize the current time.

Data happyday = new Data () --- assign an object to a variable happyday so that the object can be used multiple times. The declared variables and object variables are different. the value returned by new is a reference.

Constructor features: constructor can have 0, one or more parameters; constructor and class have the same name; one class can have multiple constructor; constructor has no return value; the constructor is always used with the new operator.

8. Overload: when multiple methods have the same name and contain different parameters, the overload occurs. The compiler must select the method to call.

 

9. package Java allows one or more classes to be collected together into a group called a package for organizing tasks. The standard Java library is divided into many packages. Java. lang java. util java, net, etc. packages are hierarchical. All java packages are within the java and javax package layers.

 

10. inheritance: allows you to create new classes based on existing classes. When you inherit an existing class, you reuse the methods and fields of this class, you can also add new methods and fields in the new class.

 

11. extension class: the extension class fully embodies the inheritance relationship of is-a. Form: class (subclass) extends (base class ).

 

12. Polymorphism: in java, object variables are polymorphism. java does not support multi-inheritance.

13. dynamic binding: Call the object method mechanism.

(1) The Compiler checks the object declaration type and method name.

(2) The Compiler checks the parameter types of method calls.

(3) static binding: if the method type is priavte static final, the compiler will know exactly which method to call.

(4) When a program is running and dynamic binding is used to call a method, the virtual machine must call the method version that matches the actual type of the object pointed to by x.

(5) dynamic binding: it is an important feature that enables programs to be scalable without the need to re-compile existing code.

 

14. final class: to prevent others from generating new classes from your class, this class cannot be expanded.

 

15. Dynamic calling takes longer than static calling.

 

16. abstract class: specifies that the class of one or more abstract methods must be defined as abstract.

Example: public abstract string getDescripition

 

17. Every class in Java is extended from the Object class.

18. equal and toString methods in the object class.

Equal is used to test whether an object is equal to another object.

ToString returns a string representing the object. Almost every class will reload the method to return the correct expression of the current state.

(The toString method is a very important method)

 

19. general programming: all values of any class type can be replaced by variables of the object class.

 

20. array list: ArrayList dynamic array list. It is a class library defined in java. uitl package and can automatically adjust the size of the array.

 

21. the getclass method in the class object class returns an instance of the ckass type. When the program starts, the class contained in the main method will be loaded, and the VM will load all the classes it needs, each loaded class must load the class it needs.

 

22. The class provides powerful functional reflection for programming programs that can dynamically manipulate java code. This function is especially useful for JavaBeans. Using Reflection Java can support tools that VB programmers are used. Programs capable of analyzing class capabilities are called reflectors, and Java provides this feature with a powerful reflection mechanism called Java. lang. reflect.

A. Ability to analyze classes at runtime.

B. Check the class objects at runtime.

C. Implement Generic Array code.

D. Provide method objects.

This mechanism mainly targets tool providers rather than applications and programs.

The most important part of the reflection mechanism is to allow you to check the structure of the class. The APIs used include:

Java. lang. reflect. Field returns a Field.

Java. reflect. Method return Method.

Java. lang. reflect. Constructor returns parameters.

Method pointer: java does not have a method pointer. If you pass the address of a method to another method, you can call it later, and the interface is a better solution.

 

23. Interface describes what a class should do without specifying how to do it. A class can implement one or more interfaces.

 

24. The interface is not a class, but a set of specifications for the class that meets the interface requirements. Two steps are required to implement an interface:

A. Declare the specified interface to be implemented by the class.

B. Define all methods in the interface.

To declare a class to implement an interface, you must use the implements keyword class actionB implements Comparable. Its actionb must provide the CompareTo method. The interface is not a class and cannot be instantiated with new.

 

25. A class has only one superclass, but a class can implement multiple interfaces. An important interface in Java: Cloneable

 

26. Interface and callback. A common mode of programming is the callback mode. In this mode, you can specify the method on the callback object when a specific time occurs.

Example: ActionListener interface listener.

Similar APIs include:

Java. swing. JOptionPane

Java. swing. Timer

Java. awt. Tookit

  •  

27. object clone: the clone method is a protection method for objects, which means that your code cannot simply call it.

 

28. Internal class: the definition of an internal class is defined in another internal class. The reason is:

A. An internal class object can access the implementation of the object created for it, including private data.

B. For other classes in the same package, internal classes can be hidden.

C. Anonymous internal classes can easily define callbacks.

D. Use internal classes to easily write event drivers.

 

29. proxy ):

A. All codes are required for the specified interface.

B. All methods defined by the object class (toString equals)

 

30. data Type: Java is a language that emphasizes the type. Each variable must first declare that it is of the type. java has a total of eight basic types. four types are Integer type, two types are floating point type, and the other type is character type. They are used for Unicode encoding characters and boolean type.

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.