Introduction of individual classes in JDK-object, class, Arrays

Source: Internet
Author: User
Tags static class

1.java.lang.object is the root class for class hierarchies, and each class uses Object as a superclass. All objects, including arrays, implement methods of this class.

Common methods:

Protected Object Clone (): Creates and returns a copy of this object. The explanation in the JDK makes me unclear. So here's how to use the method: 1 class implements the Cloneable interface, 2. Overrides the Object.clone () method and declares it as public;3. In this method, the new returned object Properties and variable fields of a non basic type are modified . (the API says that if a class contains only basic fields or references to immutable objects, then you usually do not need to modify the fields in the objects returned by Super.clone.) )

Import java.util.Date;

Class Person implements cloneable
{
    private int age;//basic type
    private string name;//string is constant and cannot be modified. Name is a reference to invariant constants
    private Date birth;//mutable object Public person
    (int a,string n,date b) { 	
        age=a;	Name=n;	birth=b;
    }
    @Override Public
    Object Clone () throws clonenotsupportedexception{person
        p = (person) super.clone ();
        Date implements the Cloneable interface, which can be called directly to
        p.birth= (date) This.birth.clone ();
        return p;
    }
}
protected void Finalize(): This method is called when the garbage collector determines that there are no more references to the object. Subclasses can be overridden to perform other actions such as cleanup. The primary purpose of finalize is to perform a purge before the object is not undone。 For any given object, the Java virtual machine invokes only one finalize.

Others are: toString (), Equals (Object), getclass (), etc.

2. Individuals interpret java.lang.class<t> as a template whose instances represent classes and interfaces in a running Java application. You can often get class instances Obj.getclass () or Obj.class.

the methods used for reflection are:static Class forname (String className), constructor GetConstructor (Class ... parametertypes), Field GetField (string name); method GetMethod (String name,class...parametertypes).

Public T newinstance(): Creates a new instance of the class represented by this class object. Equivalent to New T ().

public boolean isinstance(Object obj): Determines whether obj is compatible with the object represented by this class, equivalent to the instanceof operator .

Others have IsArray (), Isinterface (), isprimitive () and other series methods to determine the type of class object .

Public URL getresource (String name): Finds a resource, combining the path and name of the current class. It is the top-level package as the root directory , for example in WEB applications, Web-inf classes directory is the root directory. If name begins with "/" , the root directory is the starting directory , or the path to the current class.

Returns the Test.txt
File file1=test.class.getresource ("/test.txt") in the top-level directory. GetFile ();
Returns the files Test1.txt file
file2=test.class.getresource ("Test1.txt") in the directory of Test.class. GetFile;
 

3.java.util.arraysUsed to manipulate arrays, including sorting, searching, etc. StaticMethod.

List<t> aslist(T ... a): parameters can be arrays or multiple instances (such as aslist ("abc", "Def", "Ghi"). Note: The list type returned by Aslist is arrays's inner class ArrayList, so it cannot be assigned directly to a variable of type java.util.ArrayList, which can only be converted to Abstractlist (abstract class). The API says it returns a list view of the specified array, and the operations on the list are reflected on the corresponding array, and are fixed-length and do not support Remove/add operations.

int BinarySearch (t[],t key) series method, T can be used for a variety of basic data types, using the two-fork search method query key.

T[] copyof (t[],int newlength): Copy array, less than 0 or null supplement. Similar to the Copyofrange ().

Boolean equals (t[],t[]): Determines whether two specified arrays are equal to each other.

void Fill (t[],t): Fills the specified array with the specified values.

void sort (t[]): ascending sort.


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.