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 is the difference between final, finally and finalize of Java

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

Share

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

This article mainly explains "what is the difference between final, finally and finalize of Java". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the difference between final, finally and finalize of Java".

Final is used to declare properties, methods, and classes, respectively, indicating that properties are immutable, methods are not overridden, and classes are not inheritable. Finally is part of the structure of the exception handling statement, which means that it is always executed. Finalize is a method of the Object class, which is called when the garbage collector executes, and can override other resource collection when this method provides garbage collection, such as closing files, and so on.

The second of the interview points for Java programmers is whether Anonymous Inner Class (anonymous inner class) can extends (inherit) other classes and whether it can implements (implement) interface (interface)?

You can inherit other classes or complete other interfaces, which is often used in swing programming.

The third of the interview points for Java programmers, the difference between Static Nested Class and Inner Class, the more you talk, the better (some of the interview questions are very general).

Static Nested Class is an inner class that is declared static (static) and can be instantiated without relying on external class instances. The usual inner class can only be instantiated after the external class is instantiated.

The fourth interview point for Java programmers is the difference between & and & &.

& is a bitwise operator for bitwise and operation, and & & is a logical operator for logic and (and).

The fifth interview point for Java programmers is the difference between HashMap and Hashtable.

HashMap is a lightweight implementation of Hashtable (non-thread-safe implementation). They all complete the Map interface. The main difference is that HashMap allows null (null) key value (key). Because of non-thread safety, it may be more efficient than Hashtable.

The sixth interview point for Java programmers is the difference between Collection and Collections.

Collection is the parent interface of the collection class, and the main interfaces inherited from it are Set and List.Collections, which is a helper class for the collection class. It provides a series of static methods to search, sort, thread-safe and other operations on various collections.

The seventh interview point for Java programmers is when to use assert.

1.4 added keywords (syntax) to test the state of boolean expressions and can be used to debug programs. Use the method assert to indicate that if the expression is true (true), the following statement executes, otherwise AssertionError is thrown. Another way to use assert

< boolean表达式>

:, which means that if the expression is true, the following expression is ignored, otherwise the value of the latter expression is used for the build parameters of AssertionError. Note that the-source 1.4 parameter should be added when compiling, otherwise an error will be reported.] Add the-ea parameter at run time, otherwise the assert line is ignored

The eighth interview point for Java programmers, what is GC? Why is there a GC?

GC means garbage collection (Gabage Collection). Memory processing is a place where programmers are prone to problems. Forgetting or incorrect memory collection will lead to instability or even collapse of the program or system. The GC function provided by Java can automatically monitor whether the object exceeds the scope so as to achieve the purpose of automatic memory collection. Java language does not provide a display operation method to release allocated memory.

The ninth interview point for Java programmers, String s = new String ("xyz"); how many String Object have you created?

Two.

Of the ten interview points for Java programmers, how much is Math.round equivalent? How much is Math.round (- 11.5)?

Math.round (11.5) = = 12Math.round (- 11.5) =-the 11round method returns the long integer closest to the parameter, and its floor is calculated after the parameter is added by 1 / 2.

The eleventh interview points for Java programmers, short S1 = 1; S1 = S1 + 1; what's wrong? Short S1 = 1; S1 + = 1; what's wrong with it?

Short S1 = 1; S1 = S1; (S1 = int, which requires a cast type) short S1 = 1; S1 + = 1; (can be compiled correctly)

The twelve interview points for Java programmers, what's the difference between sleep () and wait ()?

Sleep is a method of the thread class (Thread), which causes this thread to suspend execution for a specified time and give the execution opportunity to other threads, but the monitoring state is maintained and will be automatically restored later. Calling sleep does not release the object lock. Wait is a method of the Object class. Calling the wait method on this object causes the thread to abandon the object lock and enter the waiting lock pool waiting for the object. Only after the notify method (or notifyAll) is issued for this object, the thread enters the object lock pool and is ready to acquire the object lock and enter the running state.

One of the thirteenth interview points for Java programmers, does Java have goto?

There are no thirteen questions. If any interviewer asks this question, I advise you not to join this company.

One of the fourteenth interview points for Java programmers, is there a length () method in the array? Is there a length () method for String?

The array does not have the method length (), but has the property of length.

String has the method length ().

Fifteen interview points for Java programmers, the difference between Overload and Override. Can the method of Overloaded change the type of return value?

The rewriting Overriding and overloading Overloading of the method are different manifestations of Java polymorphism. Rewriting Overriding is a manifestation of polymorphism between parent and child classes, and overloading Overloading is a manifestation of polymorphism in a class. If a method is defined in a subclass with the same name and parameters as its parent class, we say that the method is 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 seems to be "masked". If multiple square methods of the same name are defined in a class, they either have different number of parameters or have different parameter types, it is called Overloading of the method. The method of Overloaded is that you can change the type of return value.

One of the sixteenth interview points for Java programmers, the elements in Set cannot be repeated, so what method can be used to distinguish repetition? Do you use = = or equals ()? What's the difference between them?

Elements in Set cannot be repeated, so use the iterator () method to distinguish whether they are repeated or not. Equals () determines whether two Set are equal.

The equals () and = = methods determine whether the reference value points to the same object equals () is overridden in the class in order to return a true value if the content and type of the two separate objects match.

Seventeen interview points for Java programmers. Give me the runtime exception you see most often.

References are as follows:

ArithmeticException

ArrayStoreException

BufferOverflowException

BufferUnderflowException

CannotRedoException

CannotUndoException

ClassCastException

CMMException

ConcurrentModificationException

DOMException

EmptyStackException

IllegalArgumentException

IllegalMonitorStateException

IllegalPathStateException

IllegalStateException

ImagingOpException

IndexOutOfBoundsException

MissingResourceException

NegativeArraySizeException

NoSuchElementException

NullPointerException

ProfileDataException

ProviderException

RasterFormatException

SecurityException

SystemException

UndeclaredThrowableException

UnmodifiableSetException

UnsupportedOperationException

Eighteen interview points for Java programmers. What's the difference between error and exception?

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

Exception represents a design or implementation problem. That is, it means that if the program works properly, it will never happen.

One of the nineteenth interview points for Java programmers, does List, Set, Map inherit from the Collection interface?

List,Set is

Map is not

20 interview points for Java programmers. What's the difference between abstract class and interface?

A class that declares the existence of a method without implementing it is called an abstract class, which is used to create a class that reflects some basic behavior and declare methods for the class, but cannot implement the class in the class. You cannot create an instance of the abstract class. However, you can create a variable whose type is an abstract class and point to an instance of a concrete subclass. There can be no abstract constructor or abstract static method. The subclasses of the Abstract class provide implementations for all abstract methods in their parent class, otherwise they are also abstract classes. Instead, implement the method in a subclass. Other classes that know their behavior can implement these methods in the class.

The interface (interface) is a variant of the abstract class. In an interface, all methods are abstract. Multiple inheritance can be achieved by implementing such an interface. All the methods in the interface are abstract, and none of them has a program body. Interfaces can only define static final member variables. The implementation of an interface is similar to a subclass, except that the implementation class cannot inherit behavior from the interface definition. When a class implements a particular interface, it defines (that is, given by the program body) the methods of all such interfaces. It can then call the methods of the interface on any object of the class that implements the interface. Because of the abstract class, it allows the interface name to be used as the type of the reference variable. The usual dynamic linking will take effect. References can be converted to or from interface types, and the instanceof operator can be used to determine whether an object's class implements an interface.

21 of the interview points for Java programmers, can the method of abstract be static, native or synchronized at the same time?

Can't even

22 of the interview points for Java programmers, can interfaces be inherited? Can abstract classes implement (implements) interfaces? Can abstract classes inherit entity classes (concrete class)?

An interface can inherit an interface. Abstract classes can implement (implements) interfaces, whether abstract classes can inherit entity classes, but only if the entity class has an explicit constructor.

23 of the interview points for Java programmers, do you start a thread with run () or start ()?

Starting a thread calls the start () method to make the virtual processor represented by the thread runnable, which means it can be scheduled and executed by JVM. This does not mean that the thread will run immediately. The run () method can stop a thread by generating a flag that must exit.

24 of the interview points for Java programmers, can the constructor Constructor be override?

Constructor Constructor cannot be inherited, so Overriding cannot be overridden, but Overloading can be overloaded.

Can you inherit the String class for 25 of the interview points for Java programmers?

The String class is a final class and cannot be inherited.

26 of the interview points for Java programmers, when a thread enters a synchronized method of an object, can other threads enter other methods of that object?

No, a synchronized method of an object can only be accessed by one thread.

27 of the interview points for Java programmers, there is a return statement in try {}, so will the code in the finally {} immediately after the try be executed, when will it be executed, before or after the return?

It will be executed, before return.

28 of the interview points for Java programmers, programming questions: how much is 2 times 8 in the most efficient way?

Programmers with a C background especially like to ask this kind of question.

two

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