Java Notes-5

Source: Internet
Author: User

-bounds Use the Extends keyword

And some new syntax to limit the parameter types, the May is applied to a generic type.

Class employeelist< T extends Employee & ranked & Printable > {...}

-as we ' ll see-in-section, wildcards is Java ' s-a-introducing polymorphism into
The type parameter portion of the generic equation.


-the unbounded wildcard instantiation is a kind of supertype of all of these concrete
Instantiations.


-we saw the extends construct used to specify a upper bound for both type variables
and wildcard instantiations. It implies a type that's "at the top" of the object hierarchy
for the bound.


-generic methods can
appear in no class (not just generic classes) and is very useful for a wide variety of
Applications.

-like generic classes, generic methods have a parameter type declaration using the <>
Syntax. This syntax appears before the return type of the method:


-in General, wildcard instantiations of generics can is used as the base type for arrays in
The same to that concrete instantiations can. Let's look at an example:



-all execution in Java was associated with a thread object, beginning with a "main" thread
That's started by the Java VMs to launch your application. A New Thread is born when
We create an instance of the Java.lang.Thread class


-any class that contains a appropriate run () method can declare that it implements the
Runnable interface. An instance of this class are then a runnable object that can serve as
The target of a new thread.

-A newly born thread remains idle until we give it A figurative slap on the bottom by
Calling its start () method. The thread then wakes up and proceeds to execute the run ()
Method of its target object. Start () can is called only once in the lifetime of a thread.





-. We could also
Start the thread without saving a reference to it if we won ' t is using it later:


-the methods Wait () and join () coordinate the execution of or more threads.
We ' ll discuss them in detail if we talk about the thread synchronization later in this
Chapter.
? The interrupt () method wakes up a thread, that's sleeping in a sleep () or wait ()
Operation or is otherwise blocked on a long I/O operation.

-finally, if you need to coordinate your activities with another thread by waiting for it
To complete it task, you can use the join () method.

-A thread continues to execute until one of the following happens:
? It explicitly returns from its target run () method.
? It encounters an uncaught runtime exception.
? The evil and nasty deprecated stop () method is called.

-Thread can live on, even after what is ostensibly the
Part of the application that created it has finished.

-the Devil Thread sets its daemon status while it is created. If any Devil
Threads remain when we application are otherwise complete, the runtime system kills
them for us.


-the AWT thread is a daemon thread, so it doesn ' t
Exit automatically when other application threads has completed, and the developer
Must call System.exit () explicitly.

-applets is embeddable Java applications that is expected to start and stop themselves
On command, possibly many times in their lifetime.

-or example, suppose we implemented a SpeechSynthesizer class that contains a say ()
Method. We don ' t want multiple threads calling say () at the same time because we
Wouldn ' t is able to understand anything being said.


-if one thread were changing the values of the variables in
Setrow () at the same moment another thread is reading the values in Sumrow (). To
Prevent this and we have marked both methods as synchronized.


Java Notes-5

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.