Four, the fourth day of Android learning--java Basic Review

Source: Internet
Author: User

(Transferred from: http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html)

Four, the fourth day of Android learning--java Basic Review

This is to learn the fourth day of Android, in the program has encountered some of the Java in the previous not commonly used knowledge points, hurriedly review review, lay the foundation

Here's a simple summary:

First, anonymous internal class

    • Anonymous inner class It's just a Java class that's not named.

Using anonymous inner classes under the following conditions is appropriate:

① only one instance of the class is used

The ② class is used immediately after the definition.

③ class is very small (sun recommended is below 4 lines of code)

④ naming a class doesn't make your code easier to understand

When using anonymous inner classes, you need to be aware of:

① Anonymous Inner classes cannot have a constructor method

② anonymous inner class cannot define any static members, methods, and classes

③ anonymous inner class cannot be public, protected, private, static

④ can only create an instance of an anonymous inner class

⑤ an anonymous inner class must be after new, with its implicit implementation of an interface or implementation of a class

⑥ the anonymous inner class is a local inner class, so the restriction of the local inner class takes effect

Specific examples of people can be viewed from the Internet, I am just a general summary of what needs attention.

Second, the thread

    • A thread is plainly a different execution path in a program.

Thread-to-process comparison:

① each process has separate code and data space (the context of the process), there is a significant overhead involved in switching between processes

② threads can be seen as lightweight processes, sharing code and data spaces with a single thread, each with a separate run stack and program counter (PC), and a small overhead for thread switching

③ Multi-process: multiple tasks (Programs) can be run concurrently in the operating system

④ Multithreading: Multiple sequential streams executing in the same application

A new thread class will typically use one of the following two methods:

One: Inherit the thread class to create a new thread and override the Run method

Two: Implement Runnable method

It is important to note that:

Thread Start: Thread.Start ()

Method invocation: Run ()

The difference between the two ways: actually to start a new thread, you need to execute the start () method; the run () method does not start a new thread, but pauses to execute the method body in the Run method under the current thread, and then proceeds to the next program.

The difference between the two methods will be introduced in detail in the future

Four, the fourth day of Android Learning--java Basic Review (Turn)

Related Article

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.