Ali JAVA Development Interview Frequently asked questions summary __java

Source: Internet
Author: User
Tags addall serialization switches mysql view

My blog: Code encyclopedia: www.codedq.net; amateur grass: www.xttblog.com; love to share: www.ndislwf.com or ifxvn.com.

Threads and processes
A process is a calculated activity of a program that can be executed concurrently on a data set, and is also the basic unit of resource allocation and scheduling for the operating system.
A thread is an entity that can execute concurrently in the operating system process and is the basic unit of the processor scheduling and dispatching.
Within each process, you can include multiple threads that can be executed concurrently.
Thread itself basically does not own system resources, only a small number of essential resources: program counters, a set of registers, stacks.
Threads shared by one process share the main memory space and resources owned by the process.
In traditional OS, the basic unit of owning resource, independent dispatch and dispatch is process, in the system of threading, thread is the basic unit of dispatch and dispatch, and process is the basic unit of owning resource.
The process switch occurs when a thread switch in the same process does not produce a process switch, and is switched from one process thread to another within a process.
Thread switching
The cost of context switching
When the CPU switches from executing a thread to executing another thread, it needs to store the current thread's local data, the program pointer, and so on, and then load the local data of another thread, the program pointer, and so on, and finally start executing. This switch is referred to as "context switching" ("contextual switch"). The CPU executes a thread in one context and then switches to another context to execute another thread.
Single Thread and multithreading
Multithreading can improve the parallelism of the program, the task can be divided into orderly implementation, efficient use of CPU resources, improve response speed. But it does not mean that it is faster than single-threaded processing, while in intensive computing, the single-threaded speed is faster than multithreading.
Disadvantages of Multithreading:
1) Increase resource consumption
Threads need to get some resources out of the computer while they are running. In addition to the CPU, the thread needs some memory to maintain its local stack. It also needs to occupy some resources in the operating system to manage threads.
Multiple threads consume more time and resources when creating and switching
2 Multiple threads share 1 CPUs, requiring the CPU to continuously switch execution threads.
Java Some classes why to implement the Serializable interface.
When a class implements the Serializable interface (the interface is only a markup interface and does not contain any method definitions), it means that the class can be serialized. The purpose of serialization is to convert an object that implements the serializable interface into a sequence of bytes that can be saved (for example: Saved in a file), you can revert the byte sequence to its original object at any time.
Serialization can write a class in memory to a file or database. For example, a class is serialized and saved as a file, and the original class can be restored to memory by simply deserializing the data in the file the next time it is read. You can also serialize a class to stream data for transmission. In general, a class that has already been instantiated is converted to a file store, and the next time you need to instantiate it, you can instantiate the class into memory and retain all the variables and states in the class as long as you deserialize it. You can even place the byte sequence on another computer or over the network to recover from another computer, as long as the corresponding class exists on the computer platform to revert to the original object as expected.
Serialization implementation: The Serializable interface that will need to be serialized implements the interface, which has no method to implement, implements serializable just to annotate that the object is serializable, and then use an output stream ( such as: FileOutputStream) to construct a ObjectOutputStream (object stream) object, and then use the writeobject of the ObjectOutputStream object. Object obj Method can write out (that is, save its state) an object whose parameter is obj, and then use the input stream to recover.
The difference between HashMap and Hashtable. And how to use it, as well as some of his methods.
1, HashMap is not thread-safe
HashMap is an interface, a sub-interface of the map interface, an object that maps keys to values, where keys and values are objects, and cannot contain duplicate keys, but can contain duplicate values. HashMap allows null key and null value, while Hashtable is not allowed.
2, Hashtable is a collection of thread safety.
HashMap is a lightweight implementation of Hashtable (not thread-safe implementations), and they all complete the map interface, with the main difference being that hashmap allows null (NULL) key values (key), which may be more efficient than hashtable due to non thread-safe. HashMap allows NULL to be used as a entry key or value, and Hashtable is not allowed. HashMap the Hashtable contains method removed, changed to Containsvalue and ContainsKey. Because the contains method is easy to cause misunderstanding. 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 an external synchronization. Hashtable and HashMap adopt the Hash/rehash algorithm are probably the same, so there is no significant difference in performance.
Summarize:
HashMap thread is unsafe to allow null keys and value efficiency is a bit higher, the method is not synchronize, to provide external synchronization has Containsvalue and ContainsKey method
Hashtable thread security does not allow null keys and values with a slightly lower efficiency, the method is synchronize contains method
Hashtable inherited from Dictionary class Hashtable older than HashMap
HashMap is an implementation of the map interface introduced by Java1.2, and HashMap is a lightweight implementation of Hashtable.
Using HashMap to sort the weight of apples
One, sorted by key value
Assuming that the key-value pairs stored by HashMap are (String,integer), the JDK function sort can be invoked by key (default by dictionary ascending):

Set keyset = Map.keyset (); 
Collections.sort (keyset); 
for (Iterator ite = Keyset.iterator (); Ite.hasnext ();) { 
String temp = Ite.next (); 
System.out.println ("Key-value:" +temp+ "," +map.getvalue (temp); 
} 

If you want to sort by the dictionary in descending order, you need to overwrite the comparer comparator in the Sort method:

Collections.sort (Keyset, new Comparator () {public 
int Compare (object O1, Object O2) { 
if (Integer.parseint ( O1.tostring ()) >integer.parseint (o2.tostring ()) return 
1; 
if (Integer.parseint (o1.tostring ()) ==integer.parseint (o2.tostring ()) return 
0; 
else 
return-1; 
} 
}); 

Second, by the value of the order
1) Method One: Use two list linked list to realize

List keylist = new LinkedList (); 
Keylist.addall (Map.keyset ()); 
List valuelist = new LinkedList (); 
Valuelist.addall (Map.values ()); 
for (int i=0; i

Struts2 Interceptor
Most of the time, the Interceptor method is invoked by proxy. The interceptors for Struts 2 are relatively simple to implement. When the request arrives at the servletdispatcher of Struts 2, struts 2 looks for the configuration file, instantiates the relative interceptor object according to its configuration, and then strings it into a list (list) and calls the interceptor in the list one at a time. In fact, our ability to use interceptors so flexibly is entirely attributable to the use of dynamic proxies. Dynamic agent is the agent object according to customer needs to make different processing. For the customer, just know a proxy object on the line. In that Struts2, how the interceptor is invoked through a dynamic proxy. When the action request arrives, the agent of the system generates an action proxy object that invokes execute () or the specified method of the action, and finds the interceptor corresponding to the action in the Struts.xml. If there is a corresponding interceptor, the Interceptor is invoked before (after) the action's method is executed, and the action method is executed if there is no corresponding interceptor. The system's call to interceptor is realized by Actioninvocation.

Struts2 Accept Parameters
1. The properties of the action:
define the parameters to receive in the action and provide the corresponding setter,getter, consistent with the name of the submit parameter, and are not used as a conversion of the data type.
The corresponding submission can be made with get and post, such as: Testaction name=admin
2. Use Domainmodel:
in the action without a lot of attributes, but with the model layer used to save one of its objects. The corresponding submission method can be used with Get and post,
such as: Testaction resbananrc.name=admin
3. Using the dto– data Transfer Object
Its function is to receive parameters, pass parameters, not entity classes in the project. If the user registers, will use the confirmation password, therefore must first take the parameter to receive
, does the processing, then passes to the corresponding method to create the user object. Submit parameters in the same way as the domain Model method.
4. Using Modeldriven:
When creating an action, the action implements the Modeldriven interface, calls the interface's Getmodel () method, and takes the associated object.
The corresponding submission can be made with get and post, such as: Testaction? name=admin
5. Use the Request object:
This method is the same as using the request. GetParameter, as with the traditional JSP, such as passing parameters "") method
Java exception, error, and exception
exception classification map

1.Error: All inherited from the error, indicating fatal errors, such as insufficient memory, byte code and so on. Error is a program can not handle errors, such as OutOfMemoryError, Threaddeath and so on. When these exceptions occur, the Java Virtual machine (JVM) typically chooses to terminate the thread. 2.Exception: This exception that belongs to the application level must be caught. Exception is an exception that can be handled by the program itself, which is divided into two classes of run-time and non-runtime exceptions.
MySQL View run status
1, with the command line show statement directly under the command line login MySQL, run show status. 2, with MySQL from the Mysqladmin tool to view status, use the following command: mysqladmin-uroot-p password status
A method of collection

Collection Interface method diagram

Servlet's Dopost, Doget method, and some built-in objects

The Serlvet interface defines only one service method that is serviced, and the HttpServlet class implements the method and requires one of the following methods to be invoked:
Doget: Handling Get Requests
DoPost: Processing Post requests
When a client request is made, the service method is invoked and a request and response object is passed. The servlet first determines whether the request is a get operation or a post operation. It then calls one of the following methods: Doget or DoPost. Call the Doget method if the request is get, and call the Dopost method if the request is post. Both Doget and Dopost accept requests (HttpServletRequest) and Responses (HttpServletResponse). Doget is a doPost that receives a Web page with a Get method is used to receive a POST method just as you can see in the address bar of a bunch of garbled, that is, the URL behind a parameter post is to use the table conveys the past, as if the data have been the same as the packet sent past
1.request objects:
The client's request information is encapsulated in a request object to understand the customer's needs and then respond. It is an instance of the HttpServletRequest class.
2.response objects:
The Response object contains information about the response to a customer request, but it is rarely used directly in the JSP. It is an instance of the HttpServletResponse class.
3.session objects:
The session object refers to a client-server conversation that starts with a webapplication from the client to the server until the client disconnects from the server. It is an instance of the HttpSession class.
4.out objects:
An Out object is an instance of the JspWriter class and is a commonly used object to output content to the client
5.page objects:
The Page object is pointing to the current JSP page itself, somewhat like the this pointer in the class, which is an instance of the Java.lang.Object class
6.application objects:
The Application object enables the sharing of data among users and holds global variables. It starts at the start of the server, this object will always exist until the server is shut down, so that the same property of the object can be manipulated between the user's front and rear connections or between different users, and any action on this object's properties anywhere will affect access by other users. The startup and shutdown of the server determines the life of the Application object. It is an instance of the ServletContext class.
7.exception objects:
The exception object is an exception object that is generated when a page is in the process of running an exception. If you want to apply this object to a JSP page, you must set the Iserrorpage to True, or you will not be able to compile it. He's actually a java.lang.Throwable object.
8.pageContext objects:
The PageContext object provides access to all the objects and namespaces within the JSP page, which means that he can access the session where the page is located, as well as a property value of the application in the page, which is the epitome of all the features in the pages, The name of this class is also called PageContext.
9.config objects:
The Config object is used by the JSP engine to pass information to a servlet when it is initialized, including the parameters that the servlet uses to initialize (by property name and attribute value), and information about the server (by passing a ServletContext object)
1, with 1-5 working experience, in the face of the current popular technology do not know where to start, the need to break through the technical bottlenecks can add group.
2, in the company for a long time, live very comfortable, but job-hopping when the interview hit the Wall. Need to study in a short time, job-hopping to get high salaries can add group.
3, if there is no work experience, but the foundation is very solid, the Java working mechanism, common design ideas, Common Java Development Framework Master Skilled, can add group.
4, feel that they are very cow B, the general needs can be done. But the knowledge that has been learned is not systematized, it is difficult to continue to break through in the technical field can add group.
6. Ali Java senior Daniel Live to explain the knowledge, share knowledge, years of work experience of carding and summing up, with everyone to establish their own technical system and technical awareness.

My Blog: Code Encyclopedia: www.codedq.net, amateur grass: www.xttblog.com; love to share: www.ndislwf.com or ifxvn.com.

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.