To the baby child can remember the notes, it gives a good test exam

1. rewritten and overloading

Rewriting occurs (between child and parent class) ,, two classes subclass overrides the parent class ,, method name and method name of the parent class consistent parameter is just a different name or parameter type

It is overloaded and the number or type of parameters of different parameter generating method in a class, a class has two or more, the same method name.

2. Thread

There are two ways to achieve thread

1) Thread class inheritance

public class ThreadCreateDemo1 {
    public static void main(String[] args) {
        MyThread thread = new MyThread();
        thread.start(); //该方法调用多次,出现IllegalThreadStateException
    }
}

class MyThread extends Thread {
    @Override
    public void run() {
        super.run();
        System.out.println("hellow_world!");
    }
}

2) implement Runnable

public class ThreadCreateDemo2 {
    public static void main(String[] args) {
        Runnable runnable = new MyRunnable();
        Thread thread = new Thread(runnable);
        thread.start();
    }
}

class MyRunnable implements Runnable {
    public void run() {
        System.out.println("通过Runnable创建的线程!");
    }
}

When starting a thread with start (), the thread into the ready state, the virtual processor thread represented in a runnable state, which means that it can schedule and execute by the JVM. But this does not mean that the thread will run immediately. Only when cpu allocated time slice, the thread gets time slice, it began to execute run () method. start () method, it calls the run () method. The run () method is that you have to rewrite. run () method is included in the main thread

Thread class implementation inheritance
public class ThreadTest {
   public static void main(String[] args) {
        MyThread t =new MyThread();
        t.start();
    }
}
 
class MyThread extends Thread{
    @Override
    public void run() {
        System.out.println("Hello World!");
    }
}
Implement Runnable implementation
public class ThreadTest {
      public static void main(String[] args) {
        Thread t =new Thread(new MyRunnable());
        t.start();
    }
}
 
class MyRunnable implements Runnable{
    @Override
    public void run() {
        System.out.println("Hello World!");
    }
}

Thread want to say there is also a lot of it ,, ,, after getting to know

3.Java regarding ResultSet Interface

This is the result of a query when things get jdbc interface. He is the index from the beginning. CRUD when he returned value is a number, is the impact of a few lines. No need to use this interface can not.

4. About constructor

1. The structure must be the same name as the class (if there are a plurality of class source file, then the constructor must be public class with the same name)

2. Each class can have more than one constructor

3. The structure may have zero, one or more parameters of a

4. The structure does not return value

The new configuration is always accompanied with the operation invocation

6. subclass can not override the parent class constructor, but the constructor of a subclass of the first default constructor with no arguments will call the parent class ,, parent class has constructor parameters can be manually invoked.

7. constructor without displaying calls ,, here I explain that when you create an object, you can directly call the constructor, and, it is not like the other method calls, like to call the constructor.

5. array

Array is an object ,, only 8 basic data types is a large class of boolean, byte, short, char, int, long, float, double

Once the array length is fixed after the initialization of the backing, an array of basic data types may be stored, and can store reference data types ,, general, the array is the same class as what can be stored,

例 you [] = new you [3];   

  Dog [] = new Dog [2]; (Explanation: this requires prior Dog class, and this can only store array Dog class)

6. collection

  1. Collection interfaces include sub-interfaces: Set the interface and the interface List
  2. Map interface implementation class mainly: HashMap, TreeMap, Hashtable, ConcurrentHashMap and Properties, etc.
  3. Set the interface implementation class mainly: HashSet, TreeSet, LinkedHashSet etc.
  4. List the main interface implementation class: ArrayList, LinkedList, Stack and Vector etc.

1.List concern is the underlying index Arraylist is an array of structures, LinkedList is a linked list structure underlying

2.Set care uniqueness, he does not allow duplicates

3.Map concern is the unique identifier (key);

7. abnormal

1.error and exception What is the difference?
Error represents a serious problem in the case of recovery is not impossible, but very difficult. For example, memory overflow. Program can not be expected to handle such a situation.
exception that a design or implementation issues. In other words, it means that if run properly, the situation never happened.
 final, finally, finalize the difference?
final declaration for properties, methods, and classes, respectively alternating property is not, the method can not be overwritten, the class can not be inherited.
finally exception handling part of sentence structure, means always executed.
finalize is a method of the Object class, when the garbage collector execution calls this approach is subject to collection for other recycling when garbage collection, such as closing files (when the garbage collector will call this being subject to collection method)

8. class upwardly / downwardly Transformation

 

Up conversion:

Integer, character, floating point type data conversion in the mixing operation, the conversion to the following guidelines:

Small capacity type can be automatically converted into a large capacity of data types;

byte,short,char → int → long → float → double

Not interchangeable between byte, short, char, they will first be converted to an int in the calculation.

boolean type is not converted to other basic data types.

Eg:

int i = 123;

long l = i; // automatically converted, without strong turn

float f = 3.14F;

double d = f;

 

Down Conversion:

Integer, character, floating point type data conversion in the mixing operation, the conversion to the following guidelines:

Small capacity type can be automatically converted into a large capacity of data types;

byte,short,char → int → long → float → double

Not interchangeable between byte, short, char, they will first be converted to an int in the calculation.

boolean type is not converted to other basic data types.

Eg:

long l = 123L;

int i = (int) l; // turn must be strong

double d = 3.14;

float f = (float) d;

 

My summary: The type of conversion

Small turn large, automatically! Automatic type conversion (also called implicit type conversions) 

Big turn a small, strong turn! Casts (also called explicit type conversions)

 

9.Java in super () keyword

In the subclass inherits the parent class in general, there is a line of super statement, three ways to use to keep in mind:

. 1, super variable / object name;
This method may be variable or object to directly access the parent class, modify the operation of assignment and the like

. 2, super method name ();
direct access and call methods in the parent class

. 3, super ();
initialization method is called the parent class, in fact, call the parent class public xxx () method, generally refers to the third super () of the ellipsis, sentence added by default.
Special case: If the parent class is not no-argument constructor, so the subclass constructor needs to call the parent class is displayed in its own constructor, that can not use the system default "super ()", and the need to write explicit super (xxx)

Guess you like

Origin www.cnblogs.com/tomcat9/p/12152658.html