Java Interview Claim (2)

xiaoxiao2021-03-06  74

Tenth, the elements in the set cannot be repeated, then what method is used to distinguish whether it is repeated? Is it == or equals ()? What is the difference?

The elements in the set cannot be repeated, then use the iterator () method to distinguish whether you are repeated. Equals () is the judgment of whether two SETs are equal.

Equals () and == Method Decide whether the reference value points to the same object Equals () override in the class, which is the true value of the content and type of two separate objects.

Seventest, give me a Runtime Exception you most often.

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, unmodifiableseteexception, unsupportedopertyException

Eighteenth, what is the difference between ERROR and EXCEPTION?

Error indicates a serious problem that recovery is not impossible but difficult. For example, memory is overflow. It is impossible to expect the program to handle this situation.

Exception represents a design or implementation problem. That is, it means that if the program runs normally, it will never occur.

Near 10th, List, SET, MAP inherits from a Collection interface?

List, SET is

MAP is not

Ten, what is the difference between Abstract Class and Interface?

The presence of a declaration method does not implement its class called abstract class, which is used to create a class that reflects certain basic behavior and declares the class, but cannot implement this class in this class. Case. An instance of the Abstract class cannot be created. However, you can create a variable, which is an abstract class and let it point to an instance of the specific subclass. There is no abstract constructor or abstract static method. Subclasses of the Abstract class provide implementation for all abstraction methods in their parent class, otherwise they are also abstract classes. Instead, this method is implemented in the subclass. Other classes that know their behavior can be implemented in the class.

Interface is a variant of an abstract class. In the interface, all methods are abstract. Multiple inheritance can be obtained by achieving such an interface. All methods in the interface are abstract, no probabilities. The interface can only define the Static Final member variable. The implementation of the interface is similar to the subclass, except that the implementation class cannot inherit behavior from the interface definition. When the class implements a special interface, it defines the method of all such an interface (that is, the program body is given). Then, it can call the interface to call the interface on any object of the class of the interface. Because there is an abstract class, it allows the interface name as the type of reference variable. The usual dynamic cable will take effect. The reference can be converted to an interface type or a slave interface type, and the InstanceOf operator can be used to determine whether an object is implemented. Second Eleventh, whether the method of Abstract can be static at the same time, whether it can be native at the same time, is it simultaneous to be synchronized?

Typographic, whether the interface can inherit the interface? Does the abstract class implement (IMPLEMENTS) interface? Does the abstract class can inherit the physical class (Concrete Class)?

The interface can inherit the interface. Abstract classes can be implemented, whether abstract classes can inherit physical classes, but provided that the entity class must have a clear constructor.

On the thirteenth, starting a thread is Run () or start ()?

Starting a thread is to call the start () method so that the virtual process representing the thread is in operation, which means it can be scheduled and executed by the JVM. This doesn't mean that the thread will run immediately. The Run () method can generate a flag that must be exited to stop a thread.

24. Is the constructor CONSTRUCTOR can be Override?

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

The second fifteenth, can you inherit the String class?

The String class is that the final class cannot be inherited.

Twentydays, after a thread enters an SYNCHRONIZED method of an object, can other threads can enter other methods of this object?

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

27. There is a Return statement in try {}, then the code in finally {} in this try will not be executed, when is executed, before returnome or after?

Will be executed, execute before return.

Chapter 28. Program: 2 Multiply 8 equal to?

Programmers with C background especially like to ask this question.

2 << 3

The second nine, the two object values ​​are the same (x.equals (y) == true, but there can be different haveh codes, this sentence is wrong?

No, there is the same Hash Code.

Thirty, when an object is passed as a parameter to a method, this method can change the properties of this object and return the resulting result, then here is the value delivery or reference delivery?

It is a value transfer. The Java programming language is only passed by the value. When an object instance is transmitted to the method as a parameter, the value of the parameter is a reference to the object. The content of the object can be changed in the called method, but the reference to the object will never change.

Thirty-first, whether SWTICH can act on byte, whether it can act on long, can it work on String?

Switch (expr1), expr1 is an integer expression. Therefore, the parameters passing to the Switch and the CASE statement should be int, short, char or byte. Long, String can not work on SWTICH.

Article 32. Program: Write a Singleton. The main role of the Singleton mode is to ensure that only one example exists in a Java application.

General Singleton mode usually has several forms:

The first form: Define a class, its constructor is private, it has a type of PRIVATE for a Static, an instantimeter of the class initialization, get a reference to it through a public GetInstance method, then call it Methods.

Public class singleton {private singleton ()} // define one instance in itself, is it very strange? / Note This is private only for internal calling private static singleton instance = new singleton (); // here provides a static method for external access to this Class, you can directly access public static singleton getInstance () {return instance;}}

The second form:

Public class singleton {private static singleleton instance = null; public static synchronized singleton getInstance () {// This method has been improved above, and does not have to generate an object each time, it is only the first time // uses instances, improved effectiveness! IF (instance == null) instance = new singleleton (); return instance;}}

Other forms:

Define a class, its constructor is private, all methods are static.

It is generally considered that the first form is more secure.

Hashtable and havehmap

HashTable inherits from the Dictionary class, and HashMap is an implementation of Map Interface introduced by Java1.2.

Hashmap allows null as a key or value of Entry, and hashtable is not allowed

Also, Hashmap removes the HashTable's Contains method, changed to ContainsValue and Containskey. Because the Contains method is easy to cause misunderstandings.

The biggest difference is that the HashTable method is Synchronize, and HashMap is not, when accessed HashTable, does not need to be synchronized for its method, and HashMap must provide external synchronization.

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

New Post(0)