In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about the relationship between basic data types and Object in java. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The relationship between basic data types and Object
I know you've all heard that Object is the base class of all types, but this is not true because the basic data types in java have nothing to do with Object.
Here's an example.
Here, when calling the swap method, you cannot directly pass the int type to the swap (Object obj) method, because Object actually has nothing to do with the basic data type, at this time a will find that our type does not match, so it will automatically be packaged as an Integer type, and then you can have a connection with Object in order to successfully call the swap method.
Object, wrapper class of basic data type Object class
The basic methods of the Object class:
GetClass (), hashcode (), equals (), clone (), finalize (), toString ()
Public final native Class getClass () / returns the class public native int hashCode () of this Object runtime / / returns the hash code public boolean equals (Object obj) of the object / / determines whether other objects are "equal" to this object protected native Object clone () throws CloneNotSupportedException / / creates and returns a copy of this object public String toString () / / the string that returns the object represents protected void finalize () throws Throwable {} / / call this method public final native void notify () / / wake up a single thread waiting on this object monitor public final native void notifyAll () / / wake up all threads waiting on this object monitor public final native void wait (long timeout) throws InterruptedException / / make the current object thread wait timeout length public final void wait (long timeout) Int nanos) throws InterruptedException / / causes the thread of the current object to wait for timeout Or other thread interrupts the current thread public final void wait () throws InterruptedException / / causes the thread of the current object to wait for the basic data type
Byte 、 int 、 short 、 long 、 double 、 float 、 boolean 、 char
There are also eight corresponding packaging types:
Byte, Integer, Short, Long, Double, Float, Character, Boolean; (final, not rewritable)
Convert the basic data type to the object wrapper type-boxing, otherwise unpacking
Public static void main (String [] args) {int num1 = 1; / boxing the basic data type into an object wrapper type, the compiler built-in method Integer num2 = num1; Integer num3 = 3; / / unboxing the object data class, which is int num4 = num3;} in the java.lang.Number class
Inheritance relationship:
The Number class is the parent class of the basic data type wrapper class
Number class:
Package java.lang;public abstract class Number implements java.io.Serializable {public abstract int intValue ();\\ unpacking method public abstract long longValue (); public abstract float floatValue (); public abstract double doubleValue (); public byte byteValue () {return (byte) intValue ();} public short shortValue () {return (short) intValue ();} private static final long serialVersionUID =-8742448824652078965L;}
Common methods of the Integer class:
ParseInt (String s) converts strings to Int
Convert toString () to a string
Another way is that any type + "" becomes a String type.
Max (), min (). Comparison of two int
Two static member variables: MAX_VALUE;MIN_VALUE (there are the same variables in other numeric types)
Compare method to compare two numbers. Return-1, 0, 1
Public class BasicNumber {public static void main (String args []) {/ / maximum and minimum int intmax=Integer.MAX_VALUE; int intmin=Integer.MIN_VALUE; System.out.println (intmax); System.out.println (intmin); / / String to Int String string= "55"; int testInt=100; System.out.println (Integer.parseInt (string) + 12) / / parseInt method System.out.println (Integer.toString (testInt)); / / toString method System.out.println (String.valueOf (testInt)); / / valueOf method System.out.println (testInt+ ""); / / implicit conversion of / / + "" / / View the number of bits occupied by int System.out.println (Integer.SIZE); / / compare method int intbig=17; int intsmall=6 System.out.println (Integer.compare (intsmall, intbig));}}
Character class
The judgment function of Character class
Public static boolean isDigit (char ch)
Determines whether the specified character is a number.
Public static boolean isLetter (charch)
Determines whether the specified character is a letter.
Public static boolean isLowerCase (char ch)
Determine if it is a lowercase character
Public static boolean isUpperCase (char ch)
Determine if uppercase characters
Two conversion functions
Public static int toLowerCase (char ch)
Converts character parameters to lowercase using case mapping information taken from the UnicodeData file.
Public static int toUpperCase (char ch)
Converts character parameters to uppercase using case mapping information taken from the UnicodeData file.
Thank you for reading! This is the end of the article on "what is the relationship between the basic data types in java and Object". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 244
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.