Tips for Java programmers during an interview

Source: Internet
Author: User
Tags finally block

The difference between 1.HashMap and Hashtable

Often asked. Both are classes of the map interface, which implements the mapping of unique keys to specific values.

HashMap class is not sorted, can be a null key and multiple null values

Hashtable, there can be no null key and null value. Slower than hash, because he is in sync.

What is the difference between 2.abstract class and interface?

Often asked. A class that declares the existence of a method and does not implement it is called an abstract class, which is used to create a class that embodies some basic behavior, declares a method for that class, but does not implement the class in that class. An instance of the abstract class cannot be created. However, you can create a variable whose type is an abstract class that points to an instance of a specific subclass. Cannot have abstract constructors or abstract static methods. 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 the subclass. Other classes that know their behavior can implement these methods in the class.

An interface (interface) is a variant of an abstract class. In an interface, all methods are abstract. Multiple inheritance can be obtained by implementing such an interface. All the methods in the interface are abstract, without a program body. An interface can only define static final member variables. The implementation of an interface is similar to a subclass, except that the implementation class cannot inherit the behavior from the interface definition. When a class implements a special interface, it defines the method (which is given by the program body) to all such interfaces. It can then invoke the interface's method on any object that implements the interface's class. Because of an abstract class, it allows you to use the interface name as the type of the reference variable. The usual dynamic binder will take effect. A reference can be converted to an interface type or converted from an interface type, and the instanceof operator can be used to determine whether the class of an object implements an interface.

The elements in 3.Set cannot be duplicated, so what is the way to distinguish between repetition or not? Is it the same as or equals ()? What's the difference?

A very basic problem.

The elements in the set cannot be duplicated, so use the iterator () method to distinguish between duplicates or not. Equals () is the interpretation of two sets for equality.

The Equals () and = = methods Determine whether the reference value points to the same object

Equals () is overridden in a class to return a true value when the contents and type of the two detached objects match.

The difference between 4.Overload and override. Can the overloaded method change the type of the return value?

Often asked. The overridden overriding and overloaded overloading of a method are different manifestations of Java polymorphism. Overriding overriding is a representation of polymorphism between a parent class and a subclass, and overloading overloading is a representation of polymorphism in a class. If you define a method in a subclass that has the same name and arguments as its parent class, we say that the method is overridden (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 is "masked". If more than one method with the same name is defined in a class, they either have a different number of arguments or have different parameter types, which is called a method overload (overloading). The overloaded method is to change the type of the return value.

5. Talk about final, finally, finalize the difference

Most frequently asked.

Final modifier (keyword) If a class is declared final, it means that it can no longer derive a new subclass and cannot be inherited as a parent class. Therefore, a class cannot be declared abstract and declared final. Declaring variables or methods as final ensures that they are not changed in use. A variable 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. The method that is declared final is also used only and cannot be overloaded.

Finally provides a finally block to perform any cleanup operations when the exception is handled. If an exception is thrown, the matching catch clause executes, and the control enters the finally block, if any.

The Finalize method name. Java technology allows the use of the Finalize () method to do the necessary cleanup before the garbage collector clears objects from memory. This method is called by the garbage collector to this object when it determines that the object is not referenced. It is defined in the Object class, so all classes inherit it. Subclasses override the Finalize () method to organize system resources or perform other cleanup work. The Finalize () method is called on the object before the object is deleted by the garbage collector.

6. Frequently seen runtime exception

This is a test of your experience in programming.

ClassCastException class conversion exception, at the time of type conversion.

Nosuchelementexception can't find a way

NullPointerException most common, null-value needles

Profiledataexception, ProviderException, Rasterformatexception, SecurityException, SystemException, Undeclaredthrowableexception, Unmodifiablesetexception, et cetera.

Related Courses recommended:

In-depth Java Program Performance tuning (Amdahl law, cache component, parallel development, thread pool, JVM tuning)
Http://www.dwz.cn/rRxV6

Article Source: Http://www.dwz.cn/rRxYY

Tips for Java programmers during an interview

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.