Common objects of Java-object class

Source: Internet
Author: User

1.API Overview

API (Application Programming Interface), application programming interface.

To write a robot program to control the robot to play football, the program needs to send the robot forward, backward, shot, ball and other commands, not programmed to imagine such a program how to write. But for experienced developers, it is important to know that the robot manufacturer will provide some Java classes for controlling the robots, which define the methods for manipulating the robot's various actions. In fact, these Java classes are the interface that the robot vendor provides to the application programming, and these classes are called application programming interfaces.


2.java API

Java APIs are the classes that Java provides to us, which encapsulate the underlying implementation, and we don't need to worry about how these classes are implemented, just learn how to use them.


3. The similarities and differences between learning Chinese and learning programming

To learn Chinese well, first of all, we must master the grammar of Chinese, learn programming, and must first learn the basic grammar of programming language.

Learn Chinese, but also to master a large number of idioms, although not to all the idioms are mastered, but at least the more mastered, the more appropriate to describe things with words, the more accurate, the faster, the article will write the more fluent. In the same way, learning the programming language to master a lot of APIs, like mastering a large number of idioms, can make it easy for us to deal with certain problems, and we can also learn from these APIs to master the Java methods, Division of class skills.

Learn Chinese, in addition to mastering grammar and idioms, but also should learn to write the skills and techniques of the article. Similarly, learning programming, but also to master the analysis and problem-solving techniques, develop good programming style and habits, experience the sense of programming. Learn Chinese, we can from a large number of Tang and song Ci and modern prose to understand the skills of writing articles, while listening to the teacher's explanation and analysis. Also, learn to program, listen to the analysis and explanation of experienced programs, and find the experience and feeling from others ' excellent programs.

Of course, learning Chinese and learning programming is still different. The biggest difference is that learning Chinese, a lot of things must first remember, otherwise the book to time side hate less. However, learning programming, it is not so, you can use the time, temporary access, now learn to use.

Before is to learn physics, go around the world are not afraid, now is the Master API, programming the world I am not afraid.


4.Object class overview and how to construct it

An overview of the object class: 1) object is the root class of the class hierarchy 2) All classes inherit directly or indirectly from the class.

Constructor method: Public Object () {}, the constructor method of a subclass is the default access to the parent class's parameterless constructor method.


The Hascode () method of the 5.Object class

Package Cn;public class Student {}package cn;/** * Object class method * public int hashcode () returns the hash code value of the object * Note: The hash value is calculated based on the hash algorithm , this value is related to the address value, but not the actual address value * */public class Studenttest {public static void main (string[] args) {Student S1 = new Student (); Student s2 = new Student (); System.out.println (S1.hashcode ()); System.out.println (S2.hashcode ());}} 705927765366712642


The GetClass () method of the 6.Object class

Package Cn;public class Student {}package cn;/** * method of the object class * public int hashcode (); Returns the hash code value of the object * Note: The hash value is calculated based on the hash algorithm, which is related to the address value, but not the actual address value * Public final class<?> getclass (); Returns the run-time class of this object */public Class Studenttest {public static void main (string[] args) {Student S1 = new Student (); Student s2 = new Student (); System.out.println (S1.hashcode ()); System.out.println (S2.hashcode ()); System.out.println (S1.getclass (). GetName ());}} 705927765366712642CN. Student


The ToString () method of the 7.Object class

package com;public class student {private string name;private int age; Public student () {}public student (string name,int age) {This.name = name;this.age  = age;} Public string getname ()  {return name;} Public void setname (String name)  {this.name = name;} Public int getage ()  {return age;} Public void setage (Int age)  {this.age = age;}} Package com;/** *  public string tostring ()   Returns the string representation of the object  *   By default: The value of the  tostring () method is equivalent to  *           getclass (). GetName () + ' @ ' +integer.tohexstring (Hachcode ()) A static method under the  * integer class:  * public static  string tohexstring (int i)  *  converting an integer to unsigned hexadecimal  */public class  Studentdemo {public static void main (string[] args)  {student s = new student (); System.out.println (S.getclass (). GetName ()); System.out.println (S.hashcode ()); System.out.println (S.tostring ());//[email protected]}}
package com;public class student {private string name;private int age; Public student () {}public student (string name,int age) {This.name = name;this.age  = age;} Public string getname ()  {return name;} Public void setname (String name)  {this.name = name;} Public int getage ()  {return age;} Public void setage (Int age)  {this.age = age;} @Overridepublic  string tostring ()  {return  "Student [name="  + name +   ",  age="  + age +  "]";}} Package com;/** *  public string tostring ()   Returns the string representation of the object  *   By default: The value of the  tostring () method is equivalent to  *           getclass (). GetName () + ' @ ' +integer.tohexstring (Hachcode ()) A static method under the  * integer class:  * public static  String tohexstring (int i)  *  convert an integer to unsigned hexadecimal  *   However, the return value by default is meaningless, so, It is recommended that all subclasses override this method.  *   How to rewrite it?  *   returns the values of all member variables of the class.  */public class studentdemo {public static void main (String[] args)  {student s = new student (); System.out.println (S.getclass (). GetName ()); System.out.println (S.hashcode ()); S.setname ("haha"); S.setage (20); System.out.println (S.tostring ());}} Com. student705927765student [name= haha,  age=20]

Note: Directly outputting the name of an object is actually the ToString () method that calls the object.


Equals () method of the 8.Object class

package com;public class student {private string name;private int age; Public student () {}public student (string name,int age) {This.name = name;this.age  = age;} Public string getname ()  {return name;} Public void setname (String name)  {this.name = name;} Public int getage ()  {return age;} Public void setage (Int age)  {this.age = age;} @Overridepublic  int hashcode ()  {final int prime = 31;int result =  1;result = prime * result + age;result = prime *  result +  ((Name == null)  ? 0 : name.hashcode ()); return result;} @Overridepublic  boolean equals (object obj)  {if  (this == obj) return  true;if  (obj == null) return false;if  (geTclass ()  != obj.getclass ()) return false; student other =  (Student)  obj;if  (age != other.age) return false;if   (Name == null)  {if  (Other.name != null) Return false;}  else if  (!name.equals (other.name)) return false;return true;} Package com;/** *   public boolean equals (Object obj)  {         return  (this == obj);     } To determine if an object is "equal" to this object, the address value is compared by default  *  but the value of the comparison address is insignificant, so we need to override this method.  * == *  Basic Data type: Compares values for equality  *   reference data types: Compares addresses for equality  * * */public  class studentdemo {public static void main (String[] args)  {Student  s1 = new student ("haha",  27); Student s2 = new student ("haha",  27); System.out.println (S1==S2);//falsesystem.out.println (S1.equals (S2));//Default False, now rewritten, so true}} 

The Finalize () method and Clone () method of the 9.Object class

protected void Finalize () throws Throwable, which is called by the object's garbage collector when the garbage collector determines that there are no more references to the object. Subclasses override the Finalize () method to configure system resources or perform other elimination.

Protected object Clone (); Creates and returns a copy of this object.

This article is from the "11831428" blog, please be sure to keep this source http://11841428.blog.51cto.com/11831428/1859162

Common objects of Java-object class

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.