Java interview finishing (1)

xiaoxiao2021-03-06  74

First, talk about the difference between Final, Finally, Finalize.

Final? Modifier (keyword) If a class is declared as Final, it means that it cannot be derived from new subclasses and cannot be inherited as a parent class. Therefore, a class cannot be declared as Abstract, and it is declared as final. Declaring variables or methods to Final, ensuring that they are not changed in use. Variables that are declared for final must give initial values ​​at the time of declaration, and only read in future references, cannot be modified. The method that is declared for Final is also available, and it is not overloaded.

Finally? Provides a FINALLY block when re-processing any clearance operation. If you throw an exception, then the matching catch clause will execute, and then the control will enter the Finally block (if any).

Finalize? method name. Java technology allows the use of the Finalize () method to make the object to clear the object from the memory before making the necessary cleanup work. This method is called by the garbage collector when it is determined that this object is not referenced. It is defined in the Object class, so all classes have inherited it. Subclasses override the Finalize () method to organize system resources or perform other cleanup work. The Finalize () method is called by this object before the garbage collector deletes the object.

Second, anonymous inner class (anonymous internal class) can be extends other classes, can IMPLEMENTS INTERFACE (interface)?

The anonymous internal class is an internal class without a name. You cannot extends other classes, but an internal class can be implemented as an interface, and is implemented by another internal class.

Third, Static Nested Class and Inner Class are different, the more you say, the better (the interview question is very general).

NESTED CLASS (generally C statement), Inner Class (typically Java said). The maximum difference between Java internal classes and C nested classes is whether there is a reference to the outside. Specific visible http://www.frontfree.net/articles/services/view.asp?id=704&page=1

Note: Static Inner Class means 1 creation of an object of a Static internal class, does not require an external class object, 2 cannot access an external class object from an object of a Static internal class

The difference between fourth, & and &&.

& Is a bit operator. && is the Boolean logic operator.

Fifth, the difference between HashMap and HashTable.

Both of the MAP interface, implement the unique key to a specific value.

The HashMap class is not classified or sorted. It allows a NULL key and multiple NULL values.

Hashtable is similar to HashMap, but NULL keys and NULL values ​​are not allowed. It is also slower than HashMap because it is synchronized.

Sixth, the difference between Collection and Collectes.

Collections is a class under java.util that contains a variety of static methods related to the collection.

Collection is an interface under java.util, which is a parent interface of a variety of collections.

Seventh, when do you use Assert.

As an assertion, a statement containing Boolean expression, assuming that the expression is TRUE when this statement is executed. If the expression is calculated as false, then the system will report an AssertionError. It is used to debug purposes:

Assert (a> 0); // throws an assertioner IF a <= 0 assertion can have two forms:

Assert Expression1; Assert Expression1: Expression2;

Expression1 should always produce a Boolean value.

Expression2 can be any expression that draws a value. This value is used to generate a String message displaying more debugging information.

As default, it is disabled by default. To enable assertions while compiling, you need to use Source 1.4 tags:

Javac -Source 1.4 Test.java

To enable assertion at runtime, you can use the -enableassertions or the -ea tag.

To disable assertion at runtime, you can use the -DA or the -disableAssertions tag.

To enable assertion in the system class, you can use the -esa or -dsa tag. You can also enable or disable assertions on the basis of the package.

An assertion can be placed at any position that is not reached in normal conditions. As an assertation can be used to verify the parameters passing to the private method. However, assertions should not be used to verify parameters passing to the public method, as there is no matter whether it is enabled, the public method must check its parameters. However, it can be used in public methods or in a non-public method to use asserts to test the post condition. In addition, the assertion should not change the status of the program in any way.

Eighth, what is GC? Why have a GC? (Foundation).

GC is a garbage collector. Java programmers don't have to worry about memory management because the garbage collector will automatically manage. To request garbage collection, you can call one of the following methods:

System.gc () Runtime.Getruntime (). Gc () ninth, string s = new string ("xyz"); create a few String Object?

Two objects, one is "XYX", one is a reference object S pointing to "XYX".

Tenth, Math.Round (11.5) is equal to how much? Math.Round (-11.5) is equal?

Math.Round (11.5) Returns (long) 12, Math.Round (-11.5) Returns (long) -11;

Eleventh, short s1 = 1; S1 = S1 1; What is wrong? SHORT S1 = 1; S1 = 1; What is wrong?

Short S1 = 1; S1 = S1 1; error, S1 is the short type, S1 1 is INT type, cannot explicitly convert to a SHORT type. Can be modified to S1 = (Short) (S1 1). Short S1 = 1; S1 = 1 is correct.

Chapter 12, Sleep () and Wait () What is the difference? What is the favorite of thread?

The SLEEP () method is to stop the thread to stop a period of time. After the SLEEP time interval is full, the thread does not necessarily resume it immediately. This is because at that moment, other threads may be running and are not scheduled to give up execution, unless (a) "wake up" thread has higher priority (b) that is running because of other reasons.

Wait () is a thread interaction if the thread issues a wait () call, the thread is suspended, the object is adjusted to the waiting state until it is awake or waiting time.

Thirteenth, have Java goto?

The reserved word in Goto? Java is not used in Java.

Fourteenth, there is a length () method for arrays? String has a length () method?

The array does not have Length () method, with the properties of the length.

String has a length () method.

Fifteenth, the difference between overload and override. Can OVERLOADED methods change the type of return value?

The method of rewriting Overriding and overloading overloading is a different manifestation of Java polymorphism. Overriding Overriding is a manifestation of polymorphism between parent class and subclasses, and overloading overloading is a manifestation in a class. If a method is defined in the subclass with the same name and parameters as its parent class, we say that this method is overriddled. When the subject of subclass uses this method, the definition of the subclass will be called. For it, the definition in the parent class is like "shielded". If a plurality of the same names are defined in a class, they or have different parameters or different parameter types, called overloading. The way OVERLOADED is to change the type of return value.

转载请注明原文地址:https://www.9cbs.com/read-93187.html

New Post(0)