duang,duang!! Duang.java.mustReadTips

Source: Internet
Author: User
Tags comparable throwable

The definition of a member variable is absolutely secure, the object is created automatically, the Boolean value is initialized to False, the base data type is initialized to 0, and the object type (including string) is initialized to null.
With the Clone method, you can create an object directly without calling the constructor, although the Clone method is defined in the object class, but invoking the Clone method in one of the objects results in an exception, unless the object implements the Cloneable interface, and when the cost of creating an object is high, The Clone method can be called a useful optimization method. It is easier to copy constructors (with existing instances as their only parameters) and the costs are negligible.
If a single type of object has a different behavior, the language is considered polymorphic, and if a subclass of a class can be assigned to a variable of its underlying type, then the class is considered polymorphic. Do not convert too many types and follow the static type guidelines. Subtypes can replace a parent type as an important feature of polymorphism.
In Java, parameters are passed by value, and the parameters of the function are the values that are passed when the call is made. In addition, in Java, in most cases, a variable is a reference to an object, and Java is simply a copy of the reference, not the entire object, and the application is the value passed.

Throwable includes error errors and exception
Exception including Checked exceptions
and runtime exception namely unchecked exceptions

The error class and its subclasses are reserved classes that are only used to dalvik the runtime environment itself. Although you can write code to capture error or throwable, you cannot actually catch these errors. may not be possible, trying to capture Throwable or error code is absolutely futile.

A list is an ordered collection of objects and integers in the list from 0 to length-1 one by one, and there may be duplicate elements in the list.
Like map and list, the list maps a set of integers to a set of objects, and map maps a set of key objects to a set of value objects.
Iterator returns the element in the collection, which returns an element each time through the next method,
Iterator is a good way to manipulate all elements in a collection, and it is generally not recommended to use the following traversal method:

for0;i<list.size;i++){String s = list.get(i);//...}

The following methods are recommended:

for(Iterator<String>i = list.iterator();i.hasNext();){String s = list.get(i);//...}

The latter is simplified as follows:

for(String s :list){//...}

ArrayList is a list that supports array features, which is very fast when performing an index lookup operation, but is slow to change the size of the operation.
Linklist can quickly change the size, but the search speed is slow.
HashSet is a hash implementation of the set, in HashSet, adding and removing elements, to determine whether to include an element and to obtain the size of hashset these operations can be done in a constant number of times, hashset can be empty.
HashMap is the use of hash table as an index, which implements the map interface, in HashMap, adding and removing elements, to determine whether to include an element and to obtain the size of hashset these operations can be done in a constant number of times. He can only contain an empty key value at most, but it can have any element with an empty value.
Treemap,treemap is an ordered map, if the comparable interface is implemented, then the objects in TreeMap are sorted by natural number, if the comparable interface is not implemented, is sorted according to the comparable class passed to the TreeMap constructor.

The object lock in Java is a reentrant reentrant, and the following code is very safe and does not cause any deadlocks:

class SafeSeizure{privatelocknew Object();publicvoid method1(){synchronized(lock){//do stuffmethod2();}}publicvoid method2(){synchronized(lock){//do stuff}}}

duang,duang!! Duang.java.mustReadTips

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.