Java Beginner's Primer: 30 Java Basic concepts that beginners must master

Source: Internet
Author: User
Tags abstract constructor current time final inheritance reflection requires

Java Novice must see what the tutorial is? Of course, the green tea small make up the Java primer to grasp the 30 basic concepts, mastered these concepts for learning Java greatly beneficial, learning Java programming students come to see it.

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, he is only able to provide you with electricity, that is, as long as you know can or not instead of how and why. All programs are composed of certain attributes and behavior objects, the access of different objects is done through function call, all communication between objects is through method call, and the reuse rate is greatly improved by encapsulating object data.

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

3. Encapsulation: It is the combination of data and behavior in a package and the user of the object to hide the implementation of the data, 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

Ehavior---Explain what this object can do.

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

Dentity---The distinguishing mark from other similar behavior objects.

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

6. Relationships between classes:

USE-A: Dependencies

Has-a: Aggregation relations

Is-a: Inheritance Relationship--Example: A class inherits Class B, at which point a class not only has the B class 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 data

The EW Data ()---Constructs a new object and initializes the current time.

The 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 multiple constructors, constructors have no return value, and constructors are 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 and so on, the package is layered all the Java packages are in 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: The mechanism by which the object method is invoked.

(1) The compiler examines the type and method name of the 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: It is an important feature that makes a program extensible without the need to recompile the 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 of the classes in 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 so that it returns 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 array of the Colonel.

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 reflective functionality for writing programs that dynamically manipulate Java code, a feature that is particularly useful for JavaBeans, using reflection Java to Support tools used by VB programmers. 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.

A. Ability to analyze classes at run time.

B. Probe the object of the class at run time.

C. Implement common array manipulation code.

D. Provide method objects.

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

The most important part of the reflection 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 does not have a method pointer, passing the address of one method to another, which can be called later, and the interface is a better solution.

23. The 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 rather a set of specifications for classes that meet the requirements of the interface. It takes 2 steps to implement an interface:

A. Declares the specified interface that the class needs to implement.

B. Provide definitions of all the methods in the interface.

Declaring a class implementing an interface 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. Interface and callback. 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. The object Clone:clone method is an object protection method, which means that your code cannot simply invoke it.

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

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

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

C. Anonymous internal classes can be easily defined as callbacks.

D. The use of internal classes makes it easy to write event drivers.

29. Proxy class (proxies):

A. Specifying interfaces requires all code

B.object all methods defined by the class (ToString equals)

30. Data type: Java is the language of emphasis type, each variable must first declare that it is all type, Java has 8 basic types in total. 4 are integral, 2 are floating-point, one is character, and is used for characters in Unicode encoding, Boolean type.

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.