Java interview question summary 2

Source: Internet
Author: User

Does the array contain the length () method? Does string have the length () method?

The array does not have the length () method. It has the Length attribute.
String has the length () method.

22 The difference between overload and override. Can the overloaded method change the type of the returned value?

Overriding and overloading are different manifestations of Java polymorphism. Overriding is a manifestation of the polymorphism between the parent class and the Child class, and overloading is a manifestation of the polymorphism in a class. If a subclass defines a method with the same name and parameter as its parent class, we say this method is overwritten ). When a subclass object uses this method, it calls the definition in the subclass. For it, the definition in the parent class is "blocked. If multiple methods with the same name are defined in a class, they may have different numbers of parameters or different parameter types, it is called overloading ).
The overloaded method can change the type of the returned value.

23. The elements in set cannot be repeated. How can we identify whether the elements are repeated or not? Is = or equals () used ()? What are their differences?

The elements in the set cannot be repeated, so the iterator () method is used to identify whether the elements are repeated or not. Equals () is used to determine whether two sets are equal. The equals () and = Methods Determine whether the reference value points to the same object equals () is overwritten in the class, in order to return the true value when the content and type of the two separated objects match.

24. The most common runtime exception.

Except, arraystoreexception, except, failed, cannotredoexception, cannotundoexception, classcastexception, cmcmexception, except, domexception, emptystackexception, except, failed, imagingopexception, failed, missingresourceexception, failed, failed, nullpointerexception, profiledataexception, providerexception, rasterformatexception, secur
Ityexception, systemexception, undeclaredthrowableexception, unmodifiablesetexception, unsupportedoperationexception

25 what is the difference between error and exception?

Error indicates that recovery is not a serious problem that is impossible but difficult. For example, memory overflow. Impossible to countProgramCan handle such a situation.
Exception indicates a design or implementation problem. That is to say, it indicates that if the program runs normally, it will never happen.

26 List, set, and map are inherited from the collection interface?

List, set is
Map is not

27 what is the difference between abstract class and interface?

The class that declares a method rather than implementing it is called abstract class. It is used to create a class that reflects some basic behaviors and declare a method for this class, however, this class cannot be implemented in this class. You cannot create an abstract instance. However, you can create a variable whose type is an abstract class and point it to an instance of a specific subclass. Abstract constructors or abstract static methods are not allowed. The subclasses of abstract classes provide implementation for all abstract methods in their parent classes. Otherwise, they are also abstract classes. Instead, implement this method in the subclass. Other classes that know their behavior can implement these methods in the class.
An interface is a variant of an abstract class. All methods in the interface are abstract. Multi-inheritance can be achieved by implementing such an interface. All methods in the interface are abstract, and none of them have a program body. The interface can only define static final member variables. The implementation of an interface is similar to that of a subclass, except that the implementation class cannot inherit behaviors from the interface definition. When a class implements a special interface, it defines (to be given by the program body) all the methods of this interface. Then, it can call the interface method on any object that implements the interface class. Because there is an abstract class, it allows the interface name as the type of the referenced variable. Normally, dynamic Association editing will take effect. The reference can be converted to the interface type or from the interface type. The instanceof operator can be used to determine whether the class of an object implements the interface.

28 can the abstract method be both static, native, and synchronized?

None

29 CAN interfaces be inherited? Can an abstract class implement the (implements) interface? Can an abstract class inherit a concrete class )?

Interfaces can inherit interfaces. Abstract classes can be implemented (implements) interfaces. abstract classes can inherit object classes, provided that the object classes must have clear constructors.

30 do I use run () or start () to start a thread ()?

When a thread is started, the START () method is called to make the virtual processor represented by the thread in a running state, which means that it can be scheduled and executed by JVM. This does not mean that the thread will run immediately. The run () method can generate the exit sign to stop a thread.

 

31 can constructor be overwritten?

Constructor cannot be inherited, so overriding cannot be overwritten, but overloading can be overloaded.

Can 32 inherit the string class?

The string class is a final class, so it cannot be inherited.

33 when a thread enters a synchronized method of an object, can other threads access other methods of this object?

No. One Synchronized Method of an object can only be accessed by one thread.

33 try {} has a return statement, so the code in finally {} following this try will not

Will be executed. When will it be executed, before or after return?
Will be executed, before return.

34 programming question: how many equals 2x8 in the most efficient way?

2 <3

35. The values of the two objects are the same (X. Equals (y) = true), but different hash codes are available, right?

No. It has the same hash code.

36 when an object is passed as a parameter to a method, this method can change the property of this object and return the changed result. Is it a value transfer or a reference transfer?

Is the value transfer. JavaProgramming LanguageParameters are passed only by values. When an object instance is passed as a parameter to a method, the parameter value is a reference to the object. The object content can be changed in the called method, but the object reference will never change.

37. Does swtich work on byte, long, and string?

In switch (expr1), expr1 is an integer expression. Therefore, the parameters passed to the switch and case statements should be int, short, Char, or byte. Long and string cannot apply to swtich.
38. hashtable and hashmap

Hashtable inherits from the dictionary class, while hashmap is an implementation of the map interface introduced by java1.2.
Hashmap allows null as the key or value of an entry, while hashtable does not.
In addition, hashmap removes the hashtable contains method and changes it to containsvalue and containskey. The contains method is easy to misunderstand.
The biggest difference is that the hashtable method is synchronize, but hashmap is not.
When multiple threads access hashtable, they do not need to implement synchronization for their methods, but hashmap must provide external synchronization for them.
Hash/rehash used by hashtable and hashmapAlgorithmSo the performance will not be significantly different.

Java interview questions:I II 3. Thu

 
 
  • Tags:Java Interview Questions
  • 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.