Java January 2021

Java January 2021 The
second stage of Java basic grammar
1- install JDK
2- operator, branch structure
3- loop structure
4- IDEA development tools
5- array
6-parameters and actual parameters
7- method overloading

The second phase of the key class and object thinking
1-object-oriented

  • Member variables and local variables
  • this pointer
  • Construction method

2-String (string constant) & StringBuilder (string variable)
Several differences
between StringBuffer (multi-threaded) and StringBuilder (single thread) Difference 1: Thread-safe
StringBuffer: Thread-safe, StringBuilder: Thread-unsafe. Because all public methods of StringBuffer are modified by synchronized, and StringBuilder is not modified by StringBuilder.
Difference 2: Buffer It
can be seen that every time StringBuffer gets toString, it will directly use the toStringCache value of the buffer area to construct a string. And StringBuilder needs to copy the character array every time, and then construct a string. Therefore, buffering is also an optimization of StringBuffer, but the toString method of StringBuffer is still synchronous.
Difference 3: Performance
Since StringBuffer is thread-safe, all its public methods are synchronized, StringBuilder does not lock and synchronize methods, so there is no doubt that the performance of StringBuilder is much better than StringBuffer.

3-Collection ArrayList&student management system
add, delete, modify and check

The third stage of object
- oriented 1-inheritance & modifier
when creating an object of a subclass, jvm will first execute the construction method of the parent class, and then execute the construction method of the subclass, if it is multi-level inheritance, it will execute the top-level parent first The construction method of the class, and then the construction methods of all levels and subclasses are executed in turn.
a. Subclasses have non-priavte properties and methods;
  b. Subclasses can have their own properties and methods, that is, subclasses can extend the parent class;
  c. Subclasses can implement the methods of the parent class in their own way ;
  D, java inheritance is single inheritance, but multiple inheritance is possible; single inheritance: a subclass can only inherit one parent class; multiple inheritance: class A inherits class B, and class B inherits class C, that is, class C is class B Parent class, class B is the parent class of class A;
  e. Inheritance improves the coupling between classes (the shortcomings of inheritance improves the connection between codes);
  f. extends keyword: class inheritance is single inheritance, one Subclasses can only have one parent class, and extends can only inherit one class;
  g, implements keyword: implements enables a class to inherit multiple interfaces, and multiple interfaces are separated by commas;
  h, super keyword: used to refer to the current object The parent class realizes access to the members of the parent class;
  i, this keyword: a reference to the current object;
  j, final keyword: declares that the class cannot be inherited, that is, the final class, the modification method cannot be overridden by the subclass;
  
2-polymorphism &Abstract class & interface

  • Compile and see on the left, and run on the right. Benefits: Improve the scalability of the program. The definition is the parent class. When used, it is the specific sub-type operation. Disadvantages: You can't use the special functions of the sub-class, you can only use the rewrite method.
  • abstract. **Abstract class is to tell the subclass must override the method. **There is not necessarily only an abstract method in an abstract class, and an abstract method must be an abstract class. Abstract classes cannot be instantiated, and the grace that is instantiated through subclass objects is called abstract class polymorphism. Subclasses of abstract classes are either abstract classes or they override all abstract methods. Abstract methods cannot have method bodies.
  • 1. All the methods and methods in the interface can only be static and public
  • 2. The method in the interface cannot have a method body
  • 3. The interface cannot instantiate objects
  • 4. Interfaces can only be implemented by implements, and cannot be inherited by extends, but extensions should be used when the interface inherits the interface
  • 5. A class can implement multiple interfaces and can only inherit one class
  • 6. The class that implements the interface must implement the methods in the interface, but the inherited class does not need to override the methods in the parent class
  • 7. The keyword of the interface is interface, and the class is class

3-Inner class (member inner class and local inner class)

  • Member inner class outer class name. inner class name object = outer class object. inner class object (the inner class cannot be used if it is private, you need to call the inner class method by creating the inner class)
  • Define the class in the local inner class method
  • Anonymous inner class: An anonymous object of a subclass that inherits this class or implements this interface, and its methods can be called. If you only need to use a local class once, then you can use anonymous inner classes. Operator: new;

The fourth stage commonly used classes

  • Math
  • System.out.println
  • Arrays
  • Integer automatic boxing and unboxing
  • Date和Calendar
  • try-catch和throw
  • Collection
  • Enhanced for
  • The hash value is an int type value calculated by the JDK based on the address or string or number of the object.
  • hashset和treeset hashmap和treemap
  • The comparator can customize the compare method to achieve sorting
  • Generic class
  • IO stream (byte stream, character stream, character buffer stream) (standard input stream and standard output stream, byte print stream and character print stream)
  • Processes and threads
  • Lambda
  • reflection

Guess you like

Origin blog.csdn.net/weixin_44177643/article/details/114368863