4..21 Summary of learning content

One:
1.Object: is the root class of the class hierarchy. Each class uses Object as the superclass (parent class)
2.public int hashCode() returns the hash code value of the object. It understands the address value (not
3. public final Class getClass() returns the runtime class of this Object 4.
There is a method in the Class class: public String getName() returns the entity represented by
this Class object in the form of String (class,
interface, array class, primitive type, or void) name.
A method in 5.Object:
public String toString(); Returns the string representation of the object
6.1>public boolean equals(Object obj) Indicates whether some other object is "equal" to this object.
2> ==: The comparison value is equal (address value)
3> equals: It belongs to the method in the Object class, and the default comparison is whether the address value is the same
4> According to the normal situation: the two objects actually executed at the bottom of the equals method are in = =, the comparison is the address value; if: the student's age and name are the same, it is regarded as the same person
5> In the custom class, override the equals() method in Object, and compare the value of the member variables of the two objects. same.

  1. 1>protected Object clone() creates and returns a copy of this object
    2>The clone method of the Object class performs a specific copy operation. First, if the class of this object cannot implement the interface Cloneable, a CloneNotSupportedException will be thrown.
    !!!!! Note that all arrays are considered to implement the interface Cloneable.
    Two:
    1.Scanner class: a simple text scanner.
    2. Steps of keyboard entry
    1> Need to create keyboard entry object
    Scanner sc =new Scanner(System.in);
    2> Import package: import java.util.Scanenr; ctrl+shift+o
    to receive data
    XXX variable name = sc.nextXXX ();
    3> Construction method:
    public Scanner(InputStream source): InputStream that records data in the form of an input stream
    : Byte input stream
    InputStream in = System.in ; //The underlying execution returns a byte input stream (standard Input stream)
    3. Some common methods of the Scanner class:
    1> XXX variable name = keyboard entry object. nextXXX();
    2> In the Scanner class it provides a judgment function:
    3> public boolean hasNextXXX(): the current scanner Determine if there is the next XXX type data that can be entered
    nextXXX()
    java.util.InputMismatchException: The entered data does not match the received data type. Exception
    three:

    1. String: Represents strings:
      2. Strings are constants; their values ​​cannot be changed after they are created.
      3.String is a special reference type:

      1. Constructor:
        String(): No parameter construction
        String(byte[] bytes): Convert the number of bytes to a string
        public String(byte[] bytes, int index, int length): Convert a part of the byte array to a character String
        public String(char[] value): Converts a character array to a string toCharArray(): Converts a string to a character
        public String(char[] value, int index, int count): Converts part of a character array to a character String
        public String(String original): Constructs a string constant into a string object

        1. Commonly used methods:
          public int length() returns the length
          of this string Interview questions: ??
          Is there length() in the array, is there length() in the string, is there length() in the collection? There is no length()
          in the array ) method, only the length attribute
          string has length()
          6. The biggest feature of String: once the string is assigned, its value cannot be changed
          7. Common judgment functions of the String class
          1>boolean equals(Object obj ): Compare this string with the specified object
          2>boolean equalsIgnoreCase(String str) Compare this String with another String, regardless of case
          3>boolean contains(String str): Determine whether the current Dachuan contains a substring (emphasis)
          4>boolean startsWith(String str): start with the current str string (emphasis)
          5>boolean endsWith(String str): end with the current str string (emphasis)
          6>boolean isEmpty(): determine whether the string is Empty
          7>public String concat(String str): The unique function of the string: the splicing function and the + splicing character are the same meaning
          8. Commonly used acquisition functions of the String class:
          1> public int length(): Get the length of the string
          2 >public char charAt(int index) returns the character at the specified index
          3>public int indexOf(int ch) returns the index of the first occurrence of the specified character in this string
          4> Question: Since the incoming character: why use the int type
          'a' and 97 to represent a
          5>public int indexOf(int ch, int fromIndex) returns the index of the first occurrence of the specified character in this string, starting the search at the specified index.
          6>public int indexOf(String str) returns the index of the first occurrence of the specified substring in this string
          7>public int indexOf(String str,int fromIndex) returns the first occurrence of the specified character in this string The index at the string, starting the search at the specified index.
          8> Interception function
          a> public String substring(int beginIndex): intercept from the specified position, intercept to the end by default, and return a new string
          b> public String substring(int beginIndex, int endIndex): start from the specified position to the specified position At the end,
          the common conversion functions of 9>String are not included before the package:
          a> public byte[] getBytes() : Convert the string to a byte array
          b> public char[] toCharArray() : Convert the string to a character array (emphasis)
          c> public static String valueOf(int i): Convert data of type int to string (emphasis)
          d> This method can convert any type of data into String type
          c>public String toLowerCase(): Convert to lowercase
          d>public String toUpperCase(): Convert all characters in the string to uppercase
          10>Other functions of String type:
          a>public String replace(char oldChar, char newChar): Replace Replace a character in the large string with a new character
          b>public String replace(String oldStr,String newStr): Replace a substring in the large string
          c>public String trim(): Remove both ends of the string Space
          d> public int compareTo(String anotherString) compares two strings in lexicographical order
          Four:
          StringBuffer: thread-safe variable character sequence
          1. Thread security is difficult (multi-threading is difficult) Multi-threading--- --->Solved the multi-thread safety problem------>It is deadlock: production consumption mode (waiting for wake-up mechanism in Java)

                           2. 线程安全    --->同步的---->执行效率低
                           3. 举例:
                                  银行的网站,医疗平台...
          
                           4. 线程不安全---->不同步---->执行效率高
                              举例:
                              新闻网站,XXX论坛...

    !!!! Interview questions:

    1. The difference between StringBuffer and String?
      1> The former is a variable sequence of characters, the latter is an immutable sequence of characters
      2> From a memory perspective, when String is defined, it will open up space in the constant pool, which consumes more
      memory3 > And StringBuffer, the string buffer (all stored in it is a string), it will be released
      1. The construction method of StringBuffer:
        1> StringBuffer() : the form of no-parameter construction, the initial capacity is 16
        2>StringBuffer(int capacity): the specified capacity constructs a string buffer
        3>StringBuffer(String str) constructs a string buffer, and initialize its content to the specified string content
      2.                              1>StringBuffer的获取功能:
                                        2>public int length()返回长度
                                     3>public int capacity()返回当前容量 (如果超过容量,系统自动分配(存储字符串的时候,英文的))

        4. StringBuffer addition function
        1> (used in actual development): public StringBuffer append(String/boolean....): Append data in the string buffer (append at the end), and return the string buffer itself
        2>public StringBuffer insert(int offset,String str): add the current str string to the specified position, it returns
        the string buffer itself 5.StringBuffer delete function:
        1> public StringBuffer deleteCharAt(int index): move Remove the character at the specified position..
        2>public StringBuffer delete(int start,int end): Remove the substring from the specified position to end-1...
        3>The reverse function of StringBuffer:
        public StringBuffer reverse () : Reverse and replace the character sequence in the buffer and return it (string flush) itself
        5>StringBuffer interception function:
        public String substring(int start): intercept from the specified position, intercept to the end by default, return value It is not the buffer itself, but a new string
        7> public String substring(int start, int end): intercept from the specified position to the specified position, the return value is not the buffer itself, But a new string
        8> StringBuffer's replacement function:
        a>public StringBuffer replace(int start,int end,String str)
        b> From the specified position to the end of the specified position, replace it with a new str string, the return value is the string buffer itself
        !!!!!! Several interview questions:
        1. The difference between StringBuffer, String, StringBuilder?
        StringBuffer and StringBuilder is a variable sequence of characters that provides a buffer. (Both are regarded as containers)
        StringBuffer: thread-safe, synchronized, and inefficient.
        StringBuilder: thread-unsafe, unsynchronized, and efficient, And in single thread, StringBuilder StringBuffer is preferred
        , although the execution efficiency is low, but due to String type and its variable character sequence, it provides the
        difference between Buffer 2 StringBuffer and array?
        Array: It is a container that can store multiple data, and The types of multiple data must be consistent.
        Array length function: length attribute
        StringBuffer: it is a container, it can only store data of string type in the
        buffer to obtain the length of the buffer: length()
        The Integer class is a wrapper class of the int type Type
        ?? Question: Need to convert 100 decimal (integer default decimal) its binary, octal, hexadecimal...
        1>Requirement: get the maximum value of Integer
        public static final int MAX_VALUE
        public static final int MIN_VALUE
        Integer provides static Function:
        public static String toBinaryString(int i)
        public static String toOctalString(int i)
        public static String toHexString(int i)
        2> There is a guaranteed type corresponding to the basic type, the purpose is to convert the basic data type to String type.
        byte Byte
        short Short
        int Integer (speaking )
        long Long
        float Float
        double Double
        char character (speaking)
        boolean Booleaan 3. Integer
        constructor:
        public Integer(int value)
        public Integer(String s)
        4. How to convert int to String type?
        1>valueOf(int i) ;
        2> Convert String to int type
        3> static int parseInt(String s)
        5. JDK5 provides automatic
        unboxing 1> Integer--> unboxing int type
        2> Int type --->
        What features does boxed Integer type JDK5 also provide:
        1> Generics, variable parameters, enhanced for loops (in sets), etc..
        6. JDK8 features:
        1> Stream --> Expression
        2>Character class:
        3>Character class wraps a value of basic type char in the object. An object of type Character contains a single field of type char.
        To determine the category of characters (lowercase letters, numbers, etc.),
        4>Construction method:
        public Character(char value)
        7.Character class judgment function:
        1>public static boolean isDigit(char ch) Determine whether the specified character is a number .
        2>public static boolean isLowerCase(int ch): Determine whether it is a lowercase letter character
        3>public static boolean isUpperCase(int ch): Determine whether it is an uppercase letter character
        8. Two conversion functions:
        1>public static int toLowerCase(int codePoint)
        2>public static int toUpperCase(int codePoint)
        9. Bubble sort: compare the two pairs, put the larger ones later, after the first comparison, the maximum value appears at the maximum index...
        10. Selection sort: corresponding to 0 index The elements of the following indexes are compared with the corresponding elements, 1 index..... Small data forward method, you can get a sorted array...
        11. Element search method in the array (basic search method)
        Half search (binary search): The array must be ordered
        analysis:
        A: Define the minimum index and the maximum index
        B: Calculate the intermediate index
        C: The element corresponding to the intermediate index is equal to the element to be searched
        , and the direct return intermediate index
        is not equal: if it is
        large, find
        max = mid -1 on the left; if it is
        small, find
        min = mid + 1 on the right;
        E: Recalculate the intermediate index , go back to B to continue searching

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324934597&siteId=291194637