A detailed analysis of the root class object of Java

Source: Internet
Author: User
Tags class definition

The object class is the ancestor of all the other classes in Java, and there is no object-oriented Java OO. As the base class for all other classes, object has attributes and behaviors that are the embodiment of the thinking behind the Java language design.

The object class is located in the Java.lang package, and the Java.lang package contains the most basic and core Java classes, which are imported automatically at compile time. The object class has no properties defined, there are 13 methods, and the specific class definition structure is as follows:

1. Class Builder public Object ();

In most cases, Java passes through A shape such as new A (args.). form to create an object that belongs to that type. Where A is the class name, a (args..) That is, the corresponding constructor in this class definition. Objects created in this form are completed through constructors in the class. To embody this attribute, Java stipulates that in the class definition process, for classes that do not define constructors, the default is a parameterless constructor, as the base class for all classes, the object class naturally reflects this attribute, in the source code, does not give the object class constructor definition, but in fact, This constructor is present.

Of course, not all classes are constructed in this way, and it is natural that not all class constructors are public.

2.private static native void Registernatives ();

Registernatives function preceded by the native keyword decoration,java, with the native keyword decorated function shows that the implementation of the method is not in Java to complete, but by the C + + to complete, and was compiled into a. dll, called by Java. The concrete implementation of the method in the DLL file, for different platforms, its specific implementation should be different. With native modification, which means the operating system, this method needs to be provided and Java itself needs to be used. Specific to the registernatives () method itself, its main role is to map the C + + method in the Java native method, the implementation of the method named decoupling.

In this case, one might ask, registernatives () modifier is private, and does not execute, how does the function reach? In fact, in Java source code, the declaration of this method followed by a block of static blocks:

Java code
    1. Private static native void Registernatives ();
    2. static {
    3. Registernatives ();
    4. }
private static native void Registernatives (); static {     registernatives ();}

3.protected native Object clone () throws Clonenotsupportedexception;

See, the Clode () method is another method that is declared as native, so we know that the Clone () method is not a native method of Java, and that the implementation is done in C + +. Clone English translates to "cloning", which is intended to create and return a copy of this object. Image point understanding, there is a Cruze, you look good, want an identical. You can call this method to change the exact same Cruze out of the magic. Configuration, looks the same. But from now on, if the original Cruze had a new decoration, it had nothing to do with this Cruze you cloned. The object you cloned is exactly what you have done with the cloned Cruze. The Java term is expressed as: The Clone function returns a reference to a new clone-out object that occupies a different heap space than the original object.

Java enterprise-Class generic rights security framework source SPRINGMVC MyBatis or Hibernate+ehcache Shiro Druid Bootstrap HTML5

"Java Framework source code download"

A detailed analysis of the root class object of Java

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.