Preface :Java We can't stop our basic knowledge .

1.Array and ArrayList The difference between

About Array Usage of , see :

Array by java.lang.reflect A class under the package , Provides a way to dynamically create and access arrays . Can contain basic data types and object types . Fixed size , Because the length of the array is determined when it is created .

ArrayList yes List Interface implementation . Can only contain object types , Size can change dynamically , Elements can be null. Default size ( Capacity ) by 10. Thread unsafe .

Add capacity :int newCapacity = oldCapacity + (oldCapacity >> 1); Equivalent to expansion 1.5 times .

ArrayList Source analysis portal :ArrayList Source code analysis

2.HashSet and LinkedHashSet

HashSet Implementation principle of , see :

HashSet The main characteristics of :

1)HashSet Inherit AbstractSet, Realization Set Interface .

2) disorder , allow null value .

3) be based on HashMap The implementation of the . So threads are not safe .

LinkedHashSet Implementation principle of , see :

LinkedHashSet The main characteristics of :

1)LinkedHashSet Inherit HashSet, Realization Set Interface .

2) Orderly , Insertion order , allow null value , Because inheritance HashSet.

3) Thread unsafe .

3.HashMap And LinkedHashMap

HashMap stay Java Basic knowledge points ( One ) It has been introduced in , Here we mainly introduce LinkedHashMap.

LinkedHashMap Implementation principle of , see :

LinkedHashMap The main characteristics of :

1)LinkedHashMap Inherit HashMap, Realization Map Interface .

2) Orderly , Insertion order , allow null value .

3) Thread unsafe .

3. Boxing and UnBoxing

About packing and unpacking , Specific details , see :

The main points of :

from jdk1.5 Start , It provides the function of automatic packing . Such as Integer i=10, This statement automatically creates the corresponding Integer object , That's packing .

And unpacking , On the contrary , The following code :

Integer i=10;// Packing

int x=i;// Unpacking

in short , Boxing is the automatic conversion of basic data types to wrapper types ; Unpacking is automatically converting the wrapper type to the basic data type .

notes :

1) The boxing process is done by calling the wrapper valueOf Method , The unpacking process is done by calling the wrapper xxxValue Method .

2)Integer、Short、Byte、Character、Long These kinds of valueOf The implementation of the method is similar .

When the boxed value is in [-128,127] In the interval , The first thing is to look up this value in the cache . If there is , The value reference is returned directly , If not, create a new object .

When the packing value is not in [-128,127] In the interval , Create a new object directly .

Especially for Character object , Packing operation is , Is to determine whether the value is less than or equal to 127, Not from [-128,127] Interval values .

Double、Float Of valueOf The implementation of the method is similar .

These two types of valueOf Method , When packing , New objects are created directly .( It can be seen directly from the source code that )

Because the number of integer values in a certain range is limited , Floating point numbers are not .

3) Specially pointed out Boolean type , Its valueOf Method :

 public static Boolean valueOf(boolean b) {
return (b ? TRUE : FALSE);

among , The above marked TRUE and FALSE For two static variables :

 public static final Boolean TRUE = new Boolean(true);
public static final Boolean FALSE = new Boolean(false);

notes :1) Wrapping objects with basic types equals When the method is used , First, we need to judge whether the types being compared are the same , Without type conversion .

2) For wrapper classes of basic data types , When doing arithmetic , Will carry out automatic unpacking operation , And then calculate the values .

4. Deep copy and shallow copy

About deep copy and shallow copy , see :

Deep copy : The object and its associated content are copied .

Shallow copy : For variables of basic data type, a new copy will be made , For variables of reference type, they just copy the reference . So shallow copy modification of one object causes modification of another .

5. Interfaces and abstract classes

About interfaces and abstract classes , Reference resources :

Key points :

abstract class :

1) from abstract Modified class , You can't create objects directly , Need to inherit .

2) Not necessarily Abstract ( Abstract methods must be created by public or protected modification , The default is public).

3) You can have common variables and methods , After all, it's a class .

4) It's an abstraction of things .

Interface :

1) from interface modification , It needs to be implemented by class .

2) It can contain variables and methods , But the method has to be abstract , That is to say, there can be no concrete implementation .

3) Variables in the interface are implicitly specified as public static final( And it can only be used public static final modification ), Method is implicitly specified as public abstract Method ( And can only be public abstract Method ).

4) It's an abstraction of behavior .

by Shawn Chen,2018.3.21 Japan , Afternoon .

Related content

Java Basic knowledge points ( One )

Java Basic knowledge points ( 3、 ... and )

Java Basic knowledge points ( Four )

Java Basic knowledge points ( Two ) More articles about

  1. java Basic knowledge point supplement --- Two dimensional array

    #java Basic knowledge point supplement --- Two dimensional array First define a two-dimensional array int[][] ns={ {1,2,3,4}, {5,6,7,8}, {9,10,11,12}, {13,14,15,16} }; It's all over the world ...

  2. Java Basic knowledge points ( Four )

    Preface : Record Java Basic knowledge points , Easy to get familiar with and master . 1. Object oriented " Six principles and one principle " “ Six principles and one principle ”: Principle of single responsibility . Opening and closing principle . Dependence Inversion Principle . Richter's principle of substitution . Interface isolation principle . Principle of composite aggregation and reuse ...

  3. Java Basic knowledge points ( 3、 ... and )

    Preface : Prepare to Java The basic knowledge points are summarized into a series , It is used to review and deepen understanding . Every article should be as short as possible , Easy to read . 1.Math Class Math.floor(x): Return is no greater than x Maximum integer for .eg:Math.f ...

  4. Java Basic knowledge points ( One )

    Preface : This essay , Main records Java The basic knowledge of , Whether it's for projects or interviews , I think they are very useful , So it will continue to update ...... 1.Java Access rights of Java There are four kinds of access rights in : Default access .public.p ...

  5. Java Summary of basic knowledge

    Preface This article is mainly my previous review Java Basic principles in the process of writing Java Summary of basic knowledge .Java In fact, there are many knowledge points , And some knowledge points are difficult to understand , Sometimes we think we understand something , In fact, it may just stay on the surface , Didn't understand it ...

  6. JAVA Summary of basic knowledge ( The complete )

    1.JAVA brief introduction 1.1java Architecture :j2se,javaweb,j2ee 1.2java characteristic : Platform independent ( virtual machine ), Garbage collection ( bring java A more stable ) 1.3 JDK And JRE,JDK:java development environment ...

  7. java Basic knowledge 2 Basic types and operators

    java  Basic knowledge 2 Basic types and operators 1. identifier Definition : For the class . Method . The name of the variable By upper and lower case letters . Numbers . Underline (_) And dollar sign ($) form , And it can't start with a number 2. keyword java Language retains a special meaning or ...

  8. java Basics ( Two chapters )

    java Basics ( Two chapters ) One , Variable 1. A variable is an identifier in memory , For storing data 2. Variable naming rule l  Must be in letters . Underline _ . Dollar symbol $ start l  variable , Can include numbers l  variable , There can't be special ...

  9. Java Foundation 12 -- Polymorphism is a characteristic of members

    Java Foundation 12 -- Polymorphism is a characteristic of members One . characteristic 1, Member variables . Compile and run with reference to the left side of the equal sign . Covering only happens on functions , It's not about variables . Fu f = new Zi();System.out.println( ...

Random recommendation

  1. 【leetcode】Symmetric Tree

    Symmetric Tree Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its ...

  2. weblogic Installation failed

    weblogic Unable to install the selected application Exception in AppMerge flows' progression Exception in AppMerge flows' progression ...

  3. C/C++ static vs global

    static has a very simple logic to it. If a variable is static, it means that it is a global variable ...

  4. Self Numbers

    Self Numbers Time Limit : 20000/10000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tota ...

  5. And put it in order (Java edition , The time complexity is O(n))

    I looked it up on the Internet and classified it into the definition of sorting , To reorganize two sorted arrays into a sorted array is to merge and sort , There are many ways to achieve it , Think for yourself , use java Implemented a version of , Ideas as follows , Since it's sorted , Just compare the two arrays in turn , ...

  6. public,private,protected, And the difference between not writing

    Scope public,private.protected. And the difference between not writing The visible ranges of these four scopes are as shown in the following table . explain : Suppose there is no access modifier written on the modified element , said friendly. Don't use ...

  7. Unity3d Copy text to clipboard and store image to album

    Two small functions are used in the development of sharing function in the game :1. Copy a link to the clipboard for pasting and sharing in other apps ,2. Save a QR code image to an album for other apps to share . But in unity It can't be done in , We need to develop corresponding plug-ins respectively . An ...

  8. modify nopCommerce Entity in

                                Add an attribute to an existing entity ( Yes Category Add one more SomeNewProperty)   Recent research nopcommerce, Here is the study of the documents on the official website ...

  9. can Network management

    The main function of network management : Is to manage ECU Whether it's in the network , If you're not here, please join us , That is to say ALIVE message , To determine whether the line is down , And the mechanism of sleep state transition , And lameness , That is to say RING message . The main implementation logic flow : from rt ...

  10. Elasticsearch5.5 Installation and deployment

    One ES Introduction to basic knowledge Near Reamtime(NRT) Elasticsearch It's a real-time query platform , From the beginning of index data to the end of index data is almost 1s Time for Cluster A cluster is a collection of one or more nodes , ...