java--Common Classes

Source: Internet
Author: User

1. Parameter passing in method: value passing

基本数类型:具体的实际值  引用数据类型:对象的地址值

2. Inheritance:
Keyword: extends
Single inheritance
Inherit non-private members of parent class
Multiple inheritance

2. Modifier of Permission:
Private only accesses the default package access rights within the current class
Protected sub-class access rights
Public, all places are available.

注意:1、default不建议使用。2、这个四个权限是用来修饰类的成员的。3、public和default还可以修饰外部类。

3, the method of overwriting (overwrite, rewrite, override)
Two together, two small, one big

Project method Overrides Overloading of methods
Happening Place In the Child parent class In the same class
Method name Same Same same
Parameter list Same Different
return value type Child class less than equals parent class No requirement
Thrown exception Child class less than equals parent class No requirement
Access rights Child class greater than or equal to parent class No requirement

Final keyword: modifier class, variable, method
Modifier class: Class cannot have subclasses
Modifier variable: A constant can only be assigned once
Modification methods: Methods cannot be overridden in subclasses.

Abstract classes: Classes that are decorated with an abstract
1. Objects of abstract classes cannot be created directly, only objects can be created by the non-abstract subclasses of the abstract class.
2, abstract class can put all members of the ordinary class, in addition, there can be an abstract method.
3. Abstract method: modified with abstract, only method declaration, no method body (without that pair of braces)
4, abstract class can have an abstract method, or can not. However, abstract methods must be placed in abstract classes.
5. Subclass inherits abstract class, must implement abstract method of abstract class all, if not, subclass is also marked as abstract class.

Polymorphic: Compile-time class and run-time type inconsistency a = new B ();
Compilation can pass, see compile-time type.
Run-time specific results, see run-time type.

Common class one, object class

In Java, any class has a parent Class!!! If a class does not explicitly inherit a class, the class must inherit object. The object class is a God Class! Any class is indirectly or directly inherited from the object class.

GetClass () is not speaking today.    Speak again when you are talking about reflection. return value typeClass xxx.Class loaded into memory is also an Object!    Everything in Java is Object! Xxx.What class is the object? IsThe object of class. So:Class is all.Class object. Hashcode () returns the hash value of this object. The default is the memory address of the object represented. In the actual use, we will often go to overwrite this method, according to our own needs, to return the corresponding value. System.identityhashcode (a);//, that is, the memory address of this object. ToString () returns a string! Objcect returns the object's: Class name @hash value by default. The general case is to return a string that consists of the value of the property. When outputting an object directly, it is equivalent to calling the ToString () method of the object. Equals (object obj) determines whether the contents of two objects are equal! The default for object is to determine whether two objects are the same object. = = The reference data type determines the address value. Determines whether two objects are the same object equals: Determines whether the contents of the two objects are the same. //if NULL is passed in, it is bound to return false. A method that invokes any object, preferably a non-null judge, prevents the null pointer exception from appearing. if (obj = null) {return FALSE;} if (! ( obj instanceof User) {return  false;} //replace if with the following (obj = = null | |! ( obj instanceof User) {return  false;}                

Second, packaging class
Packing (boxing): The process of wrapping a basic data type into a wrapper class object is called packaging. Integer I1 =New Integer (10);Packing the integer 10 packaging (packing) unpacking (unpacking): The object of the wrapper type is transformed into a basic data type, called unpackingint i = I1.intvalue ();Split Package//common static method: Parsexxxint i2 = Integer.parseint ( "12345"); System. out.println (I2); //converts a string in a binary form into a 10-binary integer int i3 = Integer.parseint ( "
                 
                  16); System. 
                  out.println (i3); //toxxxstring converts the specified int number to the specified string System.7)); System. out.println (integer.tohexstring (127)); //Integer i5 = integer.valueof ( "10"); System. out.println (i5);          
                   
Basic data Types Package Type
Int Integer
Char Character
Byte Byte
Short Short
Long Long
Float Float
Double Double
Boolean Boolean
new Integer(1);Integer i7 = 1;//从jdk1.5新增的功能:自动打包(自动装箱)    基本数据类型直接赋值给包装类型int i8 = i6; //自动拆包(自动拆箱) 包装类型直接赋值给基本数据类型
Third, string related class 3.1, String class

1, final decoration, can not have sub-class
2, Immutable Class! The string object will be immutable in the future!
(Packaging classes are also immutable classes) Intent i = new Integer (2);
i = new Integer (3);

1. Use the New keywordStringS1 = newString ("AB");2. Use string constants to assign values directlyStringS2 = "ABC";3. Use the "+" operator for string connectionsStringS3 = "ABC" + "D";StringS4 =S3 +5; Abcd5StringS0 ="AB";StringS1 = newString ("abc");StringS2 = newString ("abc");System.out.println (S1 = =S2);StringS3 =  "abc" ;//Direct designation string S4 = s0 + " C " Span class= "hljs-comment" >; string concatenation string S5 =  "AB" +  "C" ; System.out.println (S3 = = s2) ;< Span class= "Hljs-label" >system.out.println (S3 = = S4) system.out.println (S3 = = S5)               

总结:  1、如果有new则最终指向堆中的对象2、如果在计算的过程中有变量参与,也是指向堆中的。3、如果只有常量参与,则堆中不会有对象产生,最终指向常量池中的对象。4、在常量池中只要内容一样,则一定是同一个对象
3.2, StringBuffer and StringBuilder
他们两个的功能完全相同!!!

StringBuffer is thread-safe when using StringBuffer in multithreading. Safe but low efficiency
StringBuilder is thread insecure, StringBuilder is preferred when single-threaded operation. Unsafe but highly efficient

Iv. Time-related classes

Date

时间类,描述一个具体的时间点。

SimpleDateFormat

格式化时间

Calendar

日历类
V. Math Class VI, Random class seven, System and runtime Class 7.1 system
currentTimeMillis()       返回以毫秒为单位的当前时间。arraycopy(Object src, int srcPos, Object dest, int destPos, int length) 从指定源数组中复制一个数组,复制从指定的位置开始,到目标数组的指定位置结束。identityHashCode(Object x) 返回给定对象的哈希码,该代码与默认的方法 hashCode() 返回的代码一样,无论给定对象的类是否重写 hashCode()。
Eight, regular expression nine, enumeration class
class 类名{}public enum 枚举类名{}特点:1、枚举类也是一个类,只是他提前限制了这个类的对象的个数!!!2、枚举类,必须在类的首行声明这个类都有哪些对象3、枚举类的构造方法一定是私有!如果枚举类的构造方法没有写权限修饰,则这个构造方法默认也是private4、枚举类可以有抽象类有的任何成员。在定义每个对象的时候,需要分别对抽象方法进行实现。

java--Common Classes

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.