Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the confusing problems in java?

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will introduce to you what are the easy-to-mix problems in java. The content of the article is good. Now I would like to share it with you. Friends who feel in need can understand it. I hope it will be helpful to you. Let's read it along with the editor's ideas.

First, the difference between final, finally and finalize.

Final? Modifier (keyword) if a class is declared as final, it means that it cannot derive a new subclass and cannot be inherited as a parent class. Therefore, a class cannot be declared both abstract and final. Declaring variables or methods as final ensures that they will not be changed in use. Variables 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. Methods declared as final can only be used and cannot be overloaded

Finally? A finally block is provided to perform any cleanup operation when the exception is handled again. If an exception is thrown, the matching catch clause is executed and the control goes into the finally block, if any.

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

Second, can Anonymous Inner Class (anonymous inner class) extends (inherit) other classes and implements (implement) interface (interface)?

An anonymous inner class is an inner class without a name. You cannot extends (inherit) other classes, but an inner class can be implemented as an interface by another inner class.

Third, the difference between Static Nested Class and Inner Class, the more you say, the better.

Nested Class (usually C++), Inner Class (usually JAVA). The biggest difference between Java inner classes and C++ nested classes is whether they have references to the outside. For more information, see http: / / www.frontfree.net/articles/services/view.asp?id=704&page=1

Note: static inner class (Inner Class) means that 1 creates an object of a static inner class without the need for an external class object, and 2 cannot access an external class object from an object of an static inner class

Fourth, the difference between & and &.

& is a bit operator. & & is a Boolean logical operator.

Fifth, the difference between HashMap and Hashtable.

Are classes that belong to the Map interface and implement mapping unique keys to specific values.

The HashMap class has no classification or sorting. It allows a null key and multiple null values.

Hashtable is similar to HashMap, but the null key and null value are not allowed. It is also slower than HashMap because it is synchronized.

Sixth, the difference between Collection and Collections.

Collections is a class under java.util that contains a variety of static methods about collection operations.

Collection is an interface under java.util, which is the parent interface of various collection structures.

Seventh, when to use assert.

An assertion is a statement that contains a Boolean expression that is assumed to be true when executed. If the expression evaluates to false, an Assertionerror is reported. It is used for debugging purposes:

Assert (a > 0); / / throws an Assertionerror if a

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report