The most common 10-track questions in Java

Source: Internet
Author: User
Tags finally block

First, to talk about final, finally, finalize the difference.

Final modifier (keyword) If a class is declared final, it means that it can no longer derive a new subclass and cannot be inherited as a parent class. Therefore, a class cannot be declared abstract and declared final. Declaring variables or methods as final ensures that they are not changed in use. A variable declared as final must be given an initial value at the time of declaration, and can only be read in subsequent references and cannot be modified. The method that is declared final is also used only and cannot be overloaded.

Finally? Provides a finally block to perform any cleanup operations when the exception is processed. If an exception is thrown, the matching catch clause executes, and the control enters the finally block, if any.

Finalize? Method name. Java technology allows the use of the Finalize () method to do the necessary cleanup before the garbage collector clears objects from memory. This method is called by the garbage collector to this object when it determines that the object is not referenced. It is defined in the object class, so all classes inherit it. Subclasses override the Finalize () method to organize system resources or perform other cleanup work. The Finalize () method is called on the object before the object is deleted by the garbage collector.

Second, the difference between HashMap and Hashtable.

Are classes that are part of the map interface and implement a unique key mapping to a specific value.

HASHMAP classes are not categorized or sorted. It allows a null key and multiple null values.

Hashtable is similar to HASHMAP, but does not allow null keys and null values. It is also slower than HASHMAP, because it is synchronous.

Third, string s = new string ("XYZ"); several string Object created?

Two objects, one is "XyX", and the other is a reference object pointing to "XyX" s.

Four, what is the difference between sleep () and wait ()? Threading a Favorite

The sleep () method is the method that causes the thread to stop for a period of time. After the sleep interval expires, the thread does not necessarily resume execution immediately. This is because at that point the other threads may be running and not being dispatched to abort execution unless (a) the "Wake Up" thread has a higher priority.

(b) The running thread is blocked for other reasons.

When wait () is a thread interaction, if the thread makes a wait () call to a synchronization object x, the thread pauses execution, and the object goes into a wait state until it wakes up or waits until the time is up.

V, short s1 = 1; S1 = s1 + 1; what's wrong? Short S1 = 1; S1 + = 1; what's wrong?

Short S1 = 1; S1 = s1 + 1; error, S1 is a short type, s1+1 is an int type, cannot be converted to short type explicitly. Can be modified to S1 = (short) (S1 + 1). Short S1 = 1; S1 + = 1 correct.

Six, the difference between overload and override. Can the overloaded method change the type of the return value?

The overridden overriding and overloaded overloading of a method are different manifestations of Java polymorphism. Overriding overriding is a representation of polymorphism between a parent class and a subclass, and overloading overloading is a representation of polymorphism in a class. If you define a method in a subclass that has the same name and arguments as its parent class, we say that the method is overridden (overriding). When an object of a subclass uses this method, the definition in the subclass is called, and for it the definition in the parent class is "masked". If more than one method with the same name is defined in a class, they either have a different number of arguments or have different parameter types, which is called a method overload (overloading). The overloaded method is to change the type of the return value.

VII, the elements in set cannot be duplicated, so what is the method used to distinguish repetition? Are you using = = or equals ()? What is the difference between them?

The elements in the set cannot be duplicated, so use the iterator () method to distinguish between duplicates or not. Equals () is the interpretation of two sets for equality.

The Equals () and = = methods Determine whether the reference value points to the same object Equals () is overwritten in the class so that when the contents and types of the two detached objects match, the truth is returned.

What's the difference between error and exception?

Error indicates a serious problem in situations where recovery is not impossible but difficult. For example, memory overflow. It is impossible to expect the program to handle such situations.

Exception represents a design or implementation issue. That is, it means that if the program runs normally, it never happens.

Ninth, give me one of your most common runtime exception.

Cmmexception, Concurrentmodificationexception, Domexception, Emptystackexception, IllegalArgumentException, Illegalmonitorstateexception, Illegalpathstateexception, IllegalStateException, Imagingopexception, Indexoutofboundsexception, MissingResourceException, Negativearraysizeexception, NoSuchElementException, NullPointerException, Profiledataexception, ProviderException, Rasterformatexception, SecurityException, SystemException, Undeclaredthrowableexception, Unmodifiablesetexception, unsupportedoperationexception

Tenth, the elements in set cannot be duplicated, so what is the method used to distinguish between duplicates or not? Are you using = = or equals ()? What is the difference between them?

The elements in the set cannot be duplicated, so use the iterator () method to distinguish between duplicates or not. Equals () is the interpretation of two sets for equality.

The Equals () and = = methods Determine whether the reference value points to the same object Equals () is overwritten in the class so that when the contents and types of the two detached objects match, the truth is returned.

Java Learning Group 669823128

The most common 10-track questions in Java

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.