Typical Java Problems

Source: Internet
Author: User

First, let's talk about the differences between final, finally, and finalize.

Final? Modifier (keyword) If a class is declared as final, it means that it cannot generate a new subclass and cannot be inherited as a parent class. Therefore, a class cannot be declared both abstract and final. Declare variables or methods as final to ensure that they are not changed during use. Variables declared as final must be declared with an initial value, which can only be read and cannot be modified in future references. Methods declared as final can only be used and cannot be overloaded.

Finally? Finally blocks are provided for troubleshooting. If an exception is thrown, the matched catch clause is executed, and the control enters the finally block (if any ).

Finalize? Method Name. Java technology allows you to use the finalize () method to clear objects from the memory before the Garbage Collector clears them. This method is called by the garbage collector when it determines that this object is not referenced. It is defined in the Object class, so all classes inherit it. Subclass overwrites the finalize () method to sort system resources or perform other cleanup tasks. The finalize () method is called before the Garbage Collector deletes an object. 

Second, can Anonymous Inner Class (Anonymous internal Class) be extends (inherited) other classes, or implements (implemented) interface (interface )?

An anonymous internal class is an internal class without a name. It cannot be extends (inherited) other classes, but an internal class can be used as an interface and implemented by another internal class. 

Third, the difference between Static Nested Class and Inner Class is that the more you say, the better (the more general the interview questions are ).

Nested Class (generally C ++) and Inner Class (generally JAVA ). The biggest difference between Java internal classes and C ++ Nested classes is whether there are external references. See asp? Id = 704 & page = 1 "> http: // www.frontfree.net/articles/services/view.asp? Id = 704 & page = 1

Note: The static internal Class (Inner Class) means that 1 creates an object of the static internal Class and does not need an external Class object, 2. You cannot access an external class object from an object of a static internal class. 

Fourth, the difference between & and.

& Is a bitwise operator. & Is a Boolean logical operator.

Fifth, the difference between HashMap and Hashtable.

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.