Java re-learning, a summary of important knowledge points (hidden skills, object-oriented thinking, abstract classes, interfaces, exceptions, etc.)

Java re-learning important knowledge points summary


There should be a table of contents in the upper right corner of the page, I do n’t know if you can see it

Numbers can be separated by underscores so that we can count the digits

Insert picture description here


static modifier

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here


final modifier constant

  • final modified class cannot be inherited
    Insert picture description here

Bit operation

Insert picture description here


String position causes different output

Insert picture description here


Wildcard

* 为通配符

Insert picture description here


hasNext ()… determine related applications of input content

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Insert picture description here


Switch to pay attention to case penetration and write to break;

Insert picture description here


The difference between while and do while

do while executes first, then judges, so execute at least once


for loop and enhanced for loop

It is recommended to use a for loop for arrays. Subscripts are faster and
related summary. There should be a table of contents in the upper right corner to find them faster


Xunhua label

Insert picture description here
Insert picture description here


Value passing and reference passing

  • By value transfer, a copy of the value of the original variable a is assigned to the new variable b. Modify the value of the new variable b without changing the value of the original variable a.
  • Pass by reference, you can experience when using the method to change the property value of the object, as shown below
    Insert picture description here
    Insert picture description here

Method overloading

Insert picture description here


Passing parameters on the command line

Command line execution can not find or can not load the main class, roll back the directory to the upper level of the package, and then execute with the full package name
Insert picture description here


Variable parameters of the method

Insert picture description here


Memory analysis

Insert picture description here
Insert picture description here


Array initialization method

Insert picture description here

Insert picture description here


toString method output

Insert picture description here


Common methods of Arrays class

Insert picture description here


Sparse array (the principle of compression)

Insert picture description here

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here


OOP object-oriented programming

OO means object-oriented
Insert picture description here


Constructor also construct method

Insert picture description here


Package

High cohesion, low coupling
Insert picture description here


inherit

  • final modified class cannot be inherited
  • All classes inherit the Object class by default
  • Private cannot be inherited
  • Subclasses use the superclass constructor by default, and super () defaults to the first line in the subclass constructor
    Insert picture description here

super、this

Insert picture description here
Insert picture description here
Insert picture description here

Method rewriting

  • StaticMethods andNon-staticThe method is different

  • Static methods, method calls are only related to the left
    Insert picture description here

  • Non-static method, rewritten. The subclass overrides the parent class method and executes the subclass method
    Insert picture description here
    Insert picture description here


Relationship between polymorphic methods

  • When the parent class reference points to a child class object, both the child class and the parent class have methods (the child class overrides the parent class's method).
    Insert picture description here
    Insert picture description here
    Insert picture description here

instanceof

  • Only the inheritance relationship can be compared, otherwise directly report an error

Insert picture description here


Code block

  • An anonymous code block, before the constructor (method)
  • Static code block, executed directly when the class is loaded, and only once
    Insert picture description here
    Insert picture description here
  • Static code block is executed only once
    Insert picture description here

Static import package

  • Before the package is imported, the class name is called by the method name
    Insert picture description here

  • After guiding the package, use it directly
    Insert picture description here


Abstract class, abstract method

  • In the abstract classAbstract methodYou only need to write the method name, not the method body (because the abstract method must be rewritten by the subclass)
  • You can define common methods in an abstract class. You must have a method body to define common methods, and you can override or not override them in subclasses. If not overridden, the method of the parent class is called.
  • Abstract classes cannot be new objects, they can only be inherited
  • AbstractAbstract methodMust be overridden by subclasses
  • If there is an abstract method in a class, then this class must be modified by abstract (that is, this class must be an abstract class)
    Insert picture description here

interface

  • Only methods can be declared in the interface
  • The class that implements the interface must override the method in the interface
  • Interface can inherit more
  • The attribute value defined in the interface is added by default public static final, which is a constant (generally not so)
  • The methods defined in the interface are added by defaultpublic abstract
  • Interface cannot be instantiated, is not a class, and has no constructor
    Insert picture description here
    Insert picture description here

Inner class

  • Non-static inner classes can obtain private properties of outer classes and use methods of outer classes
  • Static inner class, unable to access non-static attributes of outer class
    Insert picture description here
    Insert picture description here
    Insert picture description here
  • Classes written in methods are local inner classes
    Insert picture description here
  • Anonymous inner class
  • The new interface, followed by rewriting the method, returns the class that implements the interface
    Insert picture description here

abnormal

  • Five keywords
    • try
    • catch
    • finally will be executed
    • throw
    • throws

Insert picture description here

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Try to catch finally

  • Once the statement in try is abnormal, jump to the catch statement immediately.
  • Type the type of exception to be caught in the brackets
  • The highest type of exception is Throwable, including Error and Exception
  • Finally, it will be executed regardless of whether there is a try or an exception. It is usually used to handle the aftermath work, such as closing the stream, etc.
  • finally can not write
    Insert picture description here
    Insert picture description here
  • Use multiple catch statements when catching multiple exceptions, but the range of exceptions in parentheses should be from small to uppercase. (Only one catch statement will be executed. Once the exception in parentheses is satisfied, other catch statements will not be executed)
    Insert picture description here

Exception printing in catch

  • e.printStackTrace() Print out what exceptions you caught (almost the same as when you don't try the system to automatically pop up), usually add a line of your own output information in front.
if (b==0){ //主动抛出异常
	throw new ArithmeticException();
}

Insert picture description here


[Reference]
B Station God

Published 318 original articles · Like 44 · Visitors 20,000+

Guess you like

Origin blog.csdn.net/qq_43594119/article/details/105620402