Java Basic Concepts

Source: Internet
Author: User
Tags abstract array final implement inheritance variables variable tostring
Concept recently intends to revisit the Java basics, first put a




The only relationship in
1.OOP is what the object's interface is, like a computer vendor. Regardless of the internal structure of the power supply, it is only possible for him to supply you with electricity, that is, if you know can or not instead of how and Why. All programs are composed of a certain number of attributes and behavior objects, the access of different objects through function calls to complete, all communication between objects through the method call, through the encapsulation of object data, greatly improve the reuse rate.




The most important idea in
2.OOP is class, where a template is a blueprint that constructs an object from a class that creates an instance of the class (instance)





3. Encapsulation: It is to combine data and behavior in a package and to hide the implementation of data from object users, and the data in one object is called his instance field (instance field)





4. By extending a class to get a new class called Inheritance (Inheritance), all classes are extended by the object root superclass, and the root superclass is described below.





5.3 main characteristics of the object





Behavior---Explain what this object can do.





State---The reflection of an object when an object exerts a method.





Identity---Distinguishing mark from other similar behavior objects.





Each object has a unique indentity and these 3 interact with each other.





6. The relationship between classes:





use-a: Dependencies





has-a: Aggregation relationship is-a: Inheritance Relationship--Example: Class A inherits Class B, at which point a class not only has a class B method, but also its own method. (Personality exists in commonness)





7. Construction objects use constructors: The constructor is proposed, which is a special method of constructing and initializing the object. Example: The constructor for the data class is called the data




The
New Data ()---Constructs a fresh object and initializes the current time.





Data happyday=new data ()---assigns an object to a variable happyday so that the object can be used more than once, where the variable is declared differently from the object variable. The value returned by new is a reference.





Constructor Features: The constructor can have 0, one or more parameters





constructors and classes have the same name





A class can have more than one constructor constructor and no return value constructor is always used with the new operator.





8. Overloading: Overloading occurs when multiple methods have the same name and contain different parameters. The compiler must pick which method to invoke.





9. Package (Package) Java allows one or more classes to be collected together into a group called packages to facilitate the organization of tasks, and the standard Java library is divided into many packages. Java.lang Java.util java,net etc., The package is layered and all Java packages are within the Java and Javax package hierarchy.





10. Inheritance thought: Allows you to build new classes on the basis of existing classes, and when you inherit an existing class, you reuse the methods and fields of the class, and you can add new methods and fields to the new class.





11. Extended Class: The extended class fully embodies the is-a inheritance relationship. The form is: Class (subclass) extends (base class).





12 polymorphism: In Java, object variables are polymorphic. Multiple inheritance is not supported in Java.





13. Dynamic binding: A mechanism for invoking an object method.





(1) The compiler examines the type and method name of an object declaration.





(2) The compiler checks the parameter type of the method invocation.





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





(4) when a program runs and uses dynamic binding to invoke a method, the virtual machine must call the method version that matches the actual type of the object that X points to.





(5) Dynamic binding: Is an important feature that makes programs extensible without the need to recompile stored code.





14.final class: This class is not extensible to prevent others from deriving new classes from your class.





15. A dynamic call takes longer than a static call,





16. Abstract class: A class that prescribes one or more abstract methods must itself be defined as abstract





Example: Public abstract string Getdescripition




Each class in the
17.Java is extended from the object class.





the equal and ToString methods in the 18.object class.





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





ToString Returns a string representing the object, and almost every class overloads the method to return the correct representation of the current state.





(ToString method is a very important method)





19. Universal Programming: All values of any class type can be substituted with variables of object class.





20. Array list: ArrayList dynamic array list, is a class library, defined in the JAVA.UITL package, can automatically adjust the size of the array.





The GetClass method in the 21.class class object class returns an instance of the Ckass type, the class that is included in the main method when the program starts is loaded, the virtual confidential loads all the classes he needs, and each loaded class loads the class it needs.




The
22.class class provides powerful reflexes for writing programs that dynamically manipulate Java code, a feature that is particularly useful for JavaBeans, using reflection Java to Support tools that VB programmers are accustomed to using. Can analyze the class ability of the program called Reflector, Java provides this function of the package called Java.lang.reflect reflection mechanism is very powerful.





1). The ability to analyze classes at run time.





2). The object of the class is explored at run time.





3). Implement common array manipulation code.





4). Provides method objects.





and this mechanism is mainly aimed at the tool rather than the application and the program.




The most important part of the
reflex mechanism is allowing you to examine the structure of the class. The APIs used are:





Java.lang.reflect.Field returns the field.   Java.reflect.Method return method. Java.lang.reflect.Constructor return parameters.





method Pointer: Java has no method pointers, passing the address of a method to another method, which can be called later, and the interface is a better solution.





23. Interface (Interface) describes what the class does without specifying how to do it, and a class can implement one or more Interface.





24. An interface is not a class, but a set of specifications for classes that meet the requirements of an interface.





It takes 2 steps to implement an interface:





1). Declares the specified interface that the class needs to implement.





2. Provides definitions of all methods in the interface.





declares that a class implements an interface that requires the use of the Implements Keyword Class ACTIONB implements comparable its actionb needs to provide a CompareTo method, the interface is not a class, and an interface 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. Interfaces and callbacks. Programming a common pattern is the callback pattern, in which you can specify a method to callback the object when a particular time occurs.   Example: ActionListener interface Monitor. Similar APIs are: Java.swing.JOptionPane java.swing.Timer java.awt.Tookit





27. Object Clone:clone method is a protection method for objects, which means that your code cannot simply invoke it.





28. Internal class: The definition of an inner class is a class defined within another





reason is: 1. An object of an inner class can access the implementation of the object that created it, including private data 2. For other classes in the same package, the inner class can be hidden.   3. Anonymous inner classes can be easily defined as callbacks. 4. The use of internal classes makes it easy to write event drivers.





29 Proxy: 1. Specifies that the interface requires all methods (ToString equals) defined by all code 2.object classes





30. Data type: Java is the language of emphasis type, each variable must first declare that it is the type, in Java there are 8 basic types. 4 are integral, 2 are floating-point, one is character, and is used for characters in Unicode encoding, 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.