The following is my collection of Java programming in a variety of differences, for Java learning enthusiasts reference, these differences are every Java interview often test, we have a good grasp, if there is a mistake, please leave a message pointed out. For a full set of Java learning materials please go toShanghai Fashion School official websiteTo obtain.



1. Differences between HashMap and Hashtable.

HashMap is a lightweight implementation of Hashtable (non-thread-safe implementation). They both implement the Map interface. The main difference is that HashMap allows null keys, which can be more efficient than Hashtable because it is not thread-safe.

A HashMap allows NULL as an entry key or value, whereas a Hashtable does not.

HashMap contains containsValue and containsKey. Because the CONTAINS method is misleading.

Hashtable inherits from the Dictionary class, and HashMap is an implementation of the Map interface introduced in Java1.2.

The main difference is that Hashtable’s method is Synchronize, whereas HashMap does not. Instead of synchronizing its method for multiple threads accessing Hashtable, HashMap must provide external synchronization for it.

A Hashtable and a HashMap use roughly the same hash/ Rehash algorithm, so there won’t be much difference in performance.


2. Differences between final, finally, Finalize

Final is used to declare properties, methods, and classes, indicating that properties are immutable, methods are not overridden, and classes are not inherited, respectively.

Finally is part of the exception handling statement structure and means always execute.

Finalize is a method of Object class. When garbage collector executes, Finalize will call the method of the Object to be collected, and can overwrite the method to provide other resource collection during garbage collection, such as closing files.


3. What is the difference between sleep() and wait()?

Sleep is a Thread class method that causes the Thread to pause execution for a specified time, giving execution to another Thread, but the monitoring state remains, at which point it is automatically restored. Calling sleep does not release the object lock.

Wait is a method of the Object class. Invoking the wait method on an Object causes the thread to waive the Object lock and enter the lock pool. Only after notifyAll (or Notify) is issued on the Object, the thread enters the lock pool to obtain the Object lock.


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

Overriding and Overloading methods are different manifestations of Java polymorphism. Overriding Overriding is a manifestation of polymorphism between superclasses and subclasses, and Overloading is a manifestation of polymorphism within a class. If we define a method in a subclass that has the same name and parameters as its parent, we say that method is Overriding. When an object in a subclass uses this method, it calls the definition in the subclass, as if the definition in the parent class were “masked”. If multiple methods with the same name are defined in a class with different numbers of arguments or different parameter types, they are called Overloading. The Overloaded method is the type of the returned value that can be changed.


5. What is the difference between Error and exception?

Error represents a serious problem in cases where recovery is not impossible but difficult. Let’s say memory runs out. It is impossible to expect the program to handle such a situation.

Exception represents a design or implementation problem. That is, it represents a situation that would never happen if the program worked properly.


6. What are the similarities and differences between synchronous and asynchronous, and when are they used respectively? For example

If the data will be shared between threads. For example, data being written may later be read by another thread, or data being read may have already been written by another thread. Then the data is shared and must be accessed synchronously.

When your application calls a method on an object that takes a long time to execute, and you don’t want to leave your program waiting for the method to return, you should use asynchronous programming, which in many cases is more efficient.


7. What is the difference between class and interface?

A class that declares the existence of a method but does not implement it is called an abstract class. It is used when you want to create a class that embodies some basic behavior and declare methods for that class, but cannot implement the class in that class. Cannot create an instance of the Abstract class. However, you can create a variable whose type is an abstract class and have it point to an instance of a concrete subclass. There can be no abstract constructors or abstract static methods. Subclasses of the Abstract class provide implementations for all Abstract methods in their parent class, otherwise they are Abstract classes. Que?????? Mi Yongdi di refers to plum pepper āV? Lang qiushui form? Sodium green? While planting aidi di end bill pepper ā? /br /> Interface is a variant of abstract classes. In an interface, all methods are abstract. Multiple inheritance can be achieved by implementing such an interface. All methods in the interface are abstract, and none has a body. Interfaces 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 behavior from the interface definition. When a class implements a particular interface, it defines (that is, the body of the program gives) all the methods of that interface. It can then call the interface’s methods 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 cast to or from an interface type, and the instanceof operator can be used to determine whether an object’s class implements an interface.


What’s the difference between heap and stack

A stack is a linear collection where adding and removing elements should be done in the same segment. Stacks are handled on a last-in, first-out basis. The heap is a component of the stack


9. The difference between forward and redirect

Forward is when the server requests the resource. The server accesses the URL of the destination address, reads the response from that URL, and sends it back to the browser. The browser doesn’t know where the message came from, so it has the same address in the address bar.

Redirect means that the server sends a status code to the browser to rerequest the address. The browser rerequests the address using all the parameters that were previously requested. However, only the items before and after the item need to be recorded when inserting data, so the insertion speed is fast.


What is the difference between EJBs and JAVA beans?

Java beans are reusable components. There is no strict specification for Java beans. In theory, any Java class can be a Bean. Typically, however, since Java beans are created by containers (such as Tomcat), Java beans should have a constructor with no arguments, and Java beans also typically implement the Serializable interface for Bean persistence. Java beans are essentially equivalent to local in-process COM components in the Microsoft COM model and are not accessible across processes. Enterprise Java Beans are the equivalent of DCOM, or distributed components. It is based on Java’s remote method invocation (RMI) technology, so EJBs can be accessed remotely (across processes, across computers). But EJBs must be deployed in containers such as Webspere and WebLogic, and EJB customers never access the real EJB components directly, but through their containers. The EJB container is a proxy for EJB components, which are created and managed by the container. The customer accesses the real EJB components through the container.


The difference between Inner Class and Static Nested Class

Static Nested classes are internal classes that are declared Static and can be instantiated independent of external Class instances. A normal inner class needs to be instantiated by an external class.


12, JSP dynamic INCLUDE and static INCLUDE difference?

Dynamic INCLUDE is implemented with the JSP: INCLUDE action < JSP: INCLUDE page=”included. JSP “flush=”true” /> which always checks for changes in the contained file, is suitable for including dynamic pages, and can take arguments.

<%@ INCLUDE file=”included. HTM “%>