Java Basics-Object oriented

Source: Internet
Author: User

Statement: The material used in this column is written by the VIP students of the Kay Academy, who has the right to be anonymous and has the final right to interpret the article; The Edith Academy is designed to promote students to learn from each other on the basis of public notes.

Method of object:
Clone () Object clone
to string () string
Equals (object) Boolean to compare objects for equality
The Get Class () class template object, which obtains the template object through this method.
Hashcode () int converted to digital
GC Garbage Collection

Hashcode (): Int converted to digital

Hashcode () method structure explained:
First, an int hash value is assigned to H, and if the H is not equal to 0, and the length is greater than 0. More than 0, there is data inside, less than 0 there is no data.
Then ask the char array there is no data, no direct return H go out, some words the value of the char array to the Val variable, given the Val variable after the value of the length of the loop, the loop process 31*h + value of the first I. (The value of the char array is taken out, the accumulation, has been circulating, the cumulative loop to H, return feedback out.) )

Hash value calculation: Take "a,b,c" calculation. Hash value: A = b=98 c=99
Calculation process:
31 * 0 + 97 = 97
31 * 97 + 98 = 3105
31 * 3105 + 99 = 96354

The calculated value is in the int range, and more than int becomes negative, and the negative number is changed back to positive. (positive and negative, negative change positive.) around the int range)

Hashcode Application Method:

Inherited:
1. Derivation
2. Specification: To be a parent class, there is only an empty method on the parent class, which requires subclasses to override these methods.
Implement a programmatic approach to programming for the parent class. (Take the parent class to do the type, take the subclass implementation)

Abstract class:
Allows you to better implement the parent class programming.
A parent class that writes an abstract method subclass must override the abstract method of the parent class.

Rules for abstract classes:
1. Abstract classes cannot be directly new objects.
Multiple inheritance is not allowed in 2.java.
3. To create an abstract class object, you must have a subclass.

General abstract class: There are abstract methods, there are implementation methods. (There are abstract methods and other methods)
Pure abstract class: Only abstract methods, no other methods. (All of them are abstract methods)
Customizing the specification requires that subclasses be implemented.

Abstract class Application Method: Add abstract keyword!
Figure 1: Parent class: An abstract method can be used without curly braces.

Figure 2: Subclass: The parent has requested an abstract method and must override the parent class's abstract method before it can report a syntax error.
Not an abstract method can be overridden.

The application of C + + to abstract classes: Multiple inheritance:
1. Inheriting a class
2. Inheriting multiple abstract classes
Interface: interface interpretation pure abstract class transformed.
Java cannot be inherited more, but it can be single-inherited, and more interfaces can be implemented.
Only method declarations are not implemented in this way:
JDK1.7 after (interface can request static method)
JDK1.9 (interface can request default strength method)
Interface is a pure abstract class, Java can only inherit a single, but can inherit more than one abstract class (interface), so more normative, strict.

The charm of the interface:
There are many databases, each database factory database access is different, the database will not be updated regularly, updated code will also change.
Java application method of the database application to the interface, the interface is done to let the database factory to achieve. Java is the specification of the interface set up, let the database factory to achieve the interface connection.
Java has developed the rules of the game, as to how to let the industry's programmers to evaluate, good evaluation of the market, so that the connection to the database problems, and Java-Independent, is not the implementation of the database is good!
Programmers can only learn the use of an interface, you do not need to learn the other connection mode can operate the database.

Java Basics-Object oriented

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.