1. The difference between overload and override
Overload:
Overloading of methods
Occurs only between methods
Method names are the same and case sensitive
Parameter list is different, specific refers to the type of parameters, the number of different order
Return value types are not required, can be the same, or can be different
Override
Override of Method
Occurs between the parent and child classes
Method names, parameter tables, return values are the same
Modifiers are the same or wider
Static methods can only be overridden by static methods, not polymorphic
Subclasses cannot throw more exceptions than parent classes < refers to ranges >
2. Differences between interfaces and abstract classes
Abstract class (Abstract-class):
1). Abstract classes cannot create objects, only can declare references
2). Abstract class has constructors
3). Abstract classes can have abstract methods, or there can be no
4). If there is an abstract method inside a class, the class is abstract
5). If a class inherits an abstract class and the class does not want to be an abstract class, then all the abstract methods inside the abstract class must be implemented
Interface (interface):
is a special abstract class.
Modifier Properties:
3. The difference between string and StringBuffer StringBuilder
The length of the string is immutable, and the length of the StringBuffer is variable, and if you are working on the contents of the string frequently, especially if the content is to be modified, then use StringBuffer, if you need a string at the end, Then use the ToString () method of StringBuffer, thread safety;
StringBuilder is starting with JDK 5, which complements the equivalence class used by a single thread for the StringBuffer class;
The StringBuilder class should usually be preferred because it supports all the same operations, but it is faster because it does not perform synchronization.
4. The difference between arrayList linkedlist vectors
Both ArrayList and vectors use arrays to store data, which is larger than the actual stored data in order to add and insert elements, both of which allow to be indexed directly by ordinal
elements, but the insertion element involves memory operations such as array element movement, so the index data is fast and the data is inserted slowly, Vector because of the use of the Synchronized method (thread safety),
The performance is usually less ArrayList, while LinkedList uses a doubly linked list for storage, index data by ordinal need to be forward or back traversal, but when inserting data only need to remember
The entry can be recorded before and after the item, so the insertion speed is faster.
LinkedList is also thread insecure, LinkedList provides some ways to make
LinkedList can be used as stacks and queues.
5. The difference between list and set
List: Ordered, there are subscript, repeatable, the implementation of the class has three kinds: ArrayList, Vector, LinkedList, there are three ways to traverse: For loop traversal, iterator traversal, foreach Loop traversal
ArrayList, Vector bottom is implemented by the array, the default array length is 0
Set: unordered, no subscript, non-repeatable, implementation class is HashSet, there are two ways to traverse: iterator traversal, foreach Loop traversal
6, write a singleton class.
Singleton mode A class can have only one instance object
A A hungry man type
B Lazy Type
Package entity;
public class Test {
public static void Main (string[] args) {
Student s= new Student ();
Student S1 = student.getstudent ();
Student s2 = student.getstudent ();
System.out.println (S1==S2);
}
}
The object is created when the A Hungry man class is loaded
Class student{
private static Student s = new Student ();
Private Student () {}
public static Student Getstudent () {
return s;
// }
//}
Lazy Lock Type Object
Class student{
private static Student s;
Private Student () {}
Public synchronized static Student Getstudent () {
if (s==null) {
s = new Student ();
}
return s;
}
}
7. Working mechanism of database connection pool
The Java EE server starts with a certain number of pooled connections and maintains not less than this number of pooled connections. When a client program needs to connect, the pool driver returns an unused pooled connection and memento it as busy. If there is currently no idle connection, the pool driver creates a new number of connections, and the number of new connections is determined by the configuration parameters. When the pool connection call is completed, the pool driver will use this connection table
As idle, other calls can use this connection. Implementation way, the returned connection is the original connection proxy, and the proxy connection's Close method is not really connected, but it
The agent's Connection object is also returned to the connection pool.
8, say the life cycle of the servlet
Servlet is a singleton, and the servlet instantiates a servlet when the request is made for the first time. The
Servlet has a good lifetime definition, including loading and instantiation, initialization, processing requests, and end of service. The
This lifetime is expressed by the init,service and destroy methods of the Javax.servlet.Servlet interface. After the Servlet is instantiated by the server, the container runs its Init method, the service method is run when the request arrives, and it automatically dispatches the Doxxx method (Doget,dopost) corresponding to the request, and when the server decides to destroy the instance, it calls its Destroy method. The Web container loads the servlet, beginning with the life cycle. The servlet is initialized by calling the servlet's init () method. By invoking the service () method implementation, different do*** () methods are called depending on the request. To end the service, the Web container invokes the servlet's Destroy () method.
10, the introduction of struts MVC
The M (model) layer, equivalent to the background, V (View), equivalent to the foreground, C (Controller) layer, equivalent to the control page jump; The MVC pattern is designed to achieve the functional division of the WEB system.
The model layer implements the business logic in the system, which can often be implemented with JavaBean or EJBS.
The View layer is used for interaction with the user and is usually implemented with JSP. The controller layer is a bridge between model and view that can dispatch a user's request and select the appropriate view for display, and it also interprets the user's input and maps them to the actions that the model layer can perform.
Examples of implementation techniques for each layer:
M (model) JavaBean Dao+service constitute the model layer is generally implemented by Hibernate/mybatis technology. The model is the body part of the application. Models represent business data, or business logic.
C (servlet/struts action/spring Action) STRUTS/SPRINGMVC and other technologies. Controller work is to control user interface data display and update model object state according to the user's input.
V (view) Jsp/freemarker and other technologies, views are part of the user interface in the application and are the interfaces that users see and interact with.
The benefits of MVC: Tiered development for easy system upgrades
For a new framework, how to learn?
The first thing to know is what the framework does and what it solves.
11. Introduction Hibernate
1), Hibernate is an open source, the use of object-oriented ideas to implement the ORM mapping framework, it is a layer of JDBC encapsulation, the database connection, shutdown, data persistence (pruning), transaction management are encapsulated, This makes it possible to manipulate the database with object-oriented thinking when developing programs.
2), hibernate can be used for JDBC applications in any situation. The advantage is that the database is manipulated using object-oriented thought, and the encapsulation of JDBC makes it not necessary to write a large number of SQL statements in the development, which greatly improves the development efficiency, and makes the database migration very convenient by using the database dialect and so on, which makes it not necessary to consider the differences between the data in the development; provide a caching mechanism. Improve query efficiency and more.
3), the disadvantage is that hibernate does not support bulk operations. The encapsulation of JDBC loses the control of SQL, and the advantage of hibernate portability is lost if local SQL is executed. Consumes large memory.
12, Spring's main role.
The process of the SSH framework: JSP page--struts--service (Business logic processing Class)--hibernate (left to right) struts is responsible for controlling the Service declaration cycle, so that the dependencies between layers are strong and are coupled. At this point, the use of the spring framework to control the action and service class, because the upper layer no longer control the lower life cycle, layers and layers to achieve a complete decoupling, so that the program run more efficient, maintenance is also convenient.
In general, Spring's role is to decouple (ioc-rollover control or di-dependency injection) and transaction processing (i.e., AOP applications)
Spring's IOC (control inversion and dependency injection)
Control reversal: Is the (dependency) relationship between the container control program, not the traditional implementation, directly manipulated by the programmer code (generated by the new keyword)
Dependency Injection: Dependencies between components are determined by the container at run time, and the container dynamically injects some kind of dependency into the component.
Transaction handling: Transaction commit succeeds in previous JdbcTemplate, exception handling is done through Try/catch, and in spring, the container integrates transactiontemplate, which encapsulates all the functionality of transaction processing. Complex business functions including transaction rollback at the time of exception, data submission when the operation succeeds. Hibernate also has the management of transactions, hibernate in the transaction management through Sessionfactory creation and maintenance session to complete, and spring to Sessionfactory is also integrated, You do not need to configure the Hibernate.cfg.xml to set the sessionfactory. This makes good use of spring's powerful capabilities for transaction management. Avoids the need to get session instances to start transactions/commit/rollback transactions and cumbersome try/catch operations for each data operation. These are good applications of the AOP mechanism in spring. On the one hand, the business development logic clearer, professional division of labor easier to carry out. On the other hand, the application of SPRING-AOP isolation reduces the coupling of the program so that we can combine the various facets in different applications, greatly improving the code reuse degree.
The difference between
13, Hashtable, and HashMap.
HashMap is a lightweight implementation of Hashtable (non-thread-safe implementation), they all complete the Map interface, the main difference is that the HASHMAP allows null (NULL) key value (key), because of non-thread-safe, in the case of only one thread access, More efficient than Hashtable. The
HashMap allows NULL to be used as a entry key or value, and Hashtable is not allowed. The
HashMap the Hashtable contains method and changed it to Containsvalue and ContainsKey. Because the contains method is easy to cause misunderstanding. The
Hashtable inherits from the dictionary class, and HashMap is an implementation of the map interface introduced by Java1.2.
The biggest difference is that the Hashtable method is Synchronize, and HashMap is not, when multiple threads access Hashtable, they do not need to synchronize their methods, and HASHMAP must provide them with external synchronization.
Hashtable and HashMap use the same hash/rehash algorithms, so there is no big difference in performance.
on HashMap and HashTable mainly from three aspects:
I. Historical reasons: HashTable is based on the old Dictionary class, HashMap is an implementation of the MAP interface introduced by Java 1.2
two. Synchronization: Ha Shtable is thread-safe, that is, synchronous, and HashMap is not a secure line program, not a synchronous
three. Value: Only HASHMAP can let you use NULL as a key or value for the entry of a table
What is the difference between forward () and redirect () in 14.SERVLETAPI?
Forward: Request Forwarding
Redirect: request redirection
The former is only the steering of the control in the container, in the client browser address bar will not show the post-turn address, the latter is a full jump, the browser will get the address of the jump, and resend the request link. This way, you can see the link address after the jump from the address bar of the browser. Therefore, the former is more efficient, when the former can meet the needs, try to use the forward () method, and this also helps to hide
Hide the actual link. In some cases, for example, you need to jump to a resource on a different server, you must use the Sendredirect () method.
15. Polymorphic: Compile-time polymorphic, run-time polymorphic
The overloads of a method are not polymorphic, which means that the runtime polymorphism
16. What is hibernate lazy loading? Why should I use lazy loading?
The so-called lazy loading, is delayed loading or delayed loading.
When the amount of data we access is too large, obviously the cache is inappropriate, because the content capacity is limited, in order to reduce the concurrency, reduce the consumption of system resources, we let the data when needed to load, then we use lazy loading.
Hibernate provides lazy loading of properties
A. Lazy loading of entity objects
If you want to use lazy loading on an entity object, you must configure it in the entity's mapping configuration file as follows:
<class name= "Com.neusoft.entity.User" table= "User" lazy= "true" >
......
</class>
Turn on the lazy-load attribute of the entity by setting the class's Lazy property to true. If you run the following code: User user = (user) session.load ();(1)
17. How do I understand hibernate?
belongs to the DAO layer, called the persistence layer, encapsulates the JDBC
Use the HQL statement to mask the differences in the underlying database
Hibernate's own lazy loading mechanism
Hibernate three states: Transient (Transient) <>, persistent (persistent), off-state (Detached)
Java face question 002