Java Second Lecture notes (20160512)

Source: Internet
Author: User

    1. Polymorphism, is a variety of states, a variety of forms, is to use different angles to observe it

      To focus on the different aspects of the object,

      One is to inherit one is the embodiment of the interface is polymorphic

      is a form of programming,

      Overloading is a method with the same name in a class

      Class richer{

      public void Buy () {

      }

      }

Reuse

Class Dog Extedns animal{

public void Run () {

}

}

Class Jing8 extends dog{


public void Run () {

}

}


Methods can be overridden, but properties are assets that cannot be overwritten.



Class richer{

public void Buy () {

}

public void Beauty () {

}

}

Adapter adapter: Used to simplify programming

-------------------

interface only the declaration of the method, without the implementation of the method

Interface listener{


public void A1 ();

public void A2 ();

public void A3 ();

public void A4 ();

..

}

Abstract class MyListener implements listener{


public void A1 () {}

public void A2 () {}

public void A4 () {}

}

Class Baselistener implements listener{

NULL implementation

public void A1 () {}

public void A2 () {}

public void A3 () {}

..


}

The implementation of the interface is called an adapter, pre-completed a lot of basic work.

Convenient for a lot of people to do their own things, suitable for the appropriate to cooperate with people to do their own things.

The adapter is generally pumped into your class.

Because Baselistener implements all the interfaces so that the class that you write becomes concise.

Class MyListener extends baselistener{


public void A1 () {

}


}


Class app{


public static void Main (string[] args) {

MyListener l=new MyListener ();


Coherent

New Baselistener () {

public void A1 () {

This is the anonymous inner class object.

....

}

};

The code must be written in a pair of existence, clear

}

}



static variables, static functions, static classes, access to static code blocks, initialization process

A static relationship with a class is not related to an object.


Class demo{

static String name;

Static String GetName () {

return name;

}

static {

}

}

Static members in

There are static zones in the method area

Static code block


The ClassLoader class loader loads the class into the method area of the class

Static code blocks are called once when the class is loaded.

The static code block is called after the class completes the member variable and the member function.

Static code blocks are post-processing loaded. Post-processing of the load.

Postloader

---------------------------

The static code blocks of a class are called after the members of the class have finished loading them.





-------------

Static components of a class

Producers and consumers

Path

------------------

Path:

Environment variables: path= The search Order of the path program.

This path is the operating system



Classpath: classpath: Searching the order of classes

Details determine success or failure

Watch out for help, JDK is Chinese help.



Exception//Can be solved by

Error//Fatal, mishap

Class MyException extends exception{




}

Throws new MyException ();


Class a{

public void xxx () throws myexception{

throw new MyException ();

}


}




Class MyException extends runtimeexception{




}

Throws new MyException ();


Class a{

Custom Methods

public void xxx () {

throw new MyException ();

}


public static void Main (string[] args) {

try{

xxx ();

} catch (MyException e) {

E is a reference to the exception object

}

}


}


1.java.lang.throwable

2. Sub-class

Java.lang.Exception---> java.lang.Throwable

Java.lang.Error---> java.lang.Throwable


3. Run-time exceptions do not need to be declared in the method

Non-run-time exceptions, which need to be declared.

Multithreading primarily writes flexible responses to desktop programs.

Daemon is the daemon thread that serves other programs.


This article is from the "Daily Learning record" blog, so be sure to keep this source http://wangyang1987.blog.51cto.com/2577621/1772852

Java Second Lecture notes (20160512)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.