Some interview questions (Java)

Source: Internet
Author: User

01. What parameters are used to allocate Java memory?
Java-xms128m-xmx512m

02. What is the difference between treemap and hashmap?
Treemap sorts keys, but hashmap does not. Hashmap uses hashcode to quickly search its content, while all elements in treemap maintain a fixed order, if you need to get an ordered result, you should use treemap (the arrangement order of elements in hashmap is not fixed ).

03. Why should I add: Private Static final long serialversionuid?
It can be generated using the serialver.exe tool in the binary directory of JDK.
To maintain version compatibility during serialization, that is, during version upgrade, deserialization still maintains the uniqueness of objects. In Java, serialversionuid is the only identifier that controls whether deserialization is successful. If the value is different, deserialization cannot be successful.

04. How does JSP compile and execute?
After compilation, the scriptlets of the JSP file will be included in the Service () method of the JSP servlet. When the JSP Engine processes client requests, JSP scriptlets is executed when requested. If scriptlet generates output, the output will be cached in the out (jspwriter) object and finally sent to the client.

05. How to solve Chinese garbled characters in JSP/servlet Web
Encoding, keep the same encoding in whole system.

6. What are the differences between statement, prepared statement and callable statement in JDBC?
The statement interface provides basic methods for executing statements and obtaining results. The preparedstatement interface adds a method to process in parameters, while the callablestatement interface adds a method to process out parameters.
Preparedstatement: for multiple executions of the same statement, statement sends the SQL statement to the data each time.
Database, the efficiency is obviously not high. If the database supports pre-compilation, preparedstatement can first send the statement to be executed to it, and then each execution does not have to send the same statement, of course, the efficiency is improved. If the database does not support pre-compilation,
Preparedstatement works like statement, but it is inefficient and does not require manual intervention.
In addition, preparedstatement also supports receiving parameters. After pre-compilation, you only need to transmit different parameters for execution.
Improved performance.
Callablestatement: a subclass of preparedstatement. It is only used to execute stored procedures.

07. Under what circumstances will an exception be thrown "opening the cursor exceeds the maximum number?
Maybe execute extends queries and keep them openning

08. What are the differences between Sax and Dom in XML parsing?
Differences between sequential parsing and overall loading, memory and speed

09. What is the difference between an abstract class and an interface?
Partially implemented or not implemented

10. What is middleware?
Black Box

What are the built-in JSP objects?
Out, request, response, application, session, exception, config, page, pagecontext

12. What methods can be used to prevent and resolve attacks on websites?
Put the JSP files into WEB-INF directory, use the prepare statement.
Use https, encrypt the paramenter or Uri, like Taobao.
... Firewall.

13. How can I speed up Website access?
Cache Strategy

14. What MVC Framework technologies can be used in Java? What are their features and applicable environments?
Struts, webwork, spring, JSF...

15. What are the advantages and disadvantages of MVC and what are their applicability?
The MVC development mode separates the data access layer and data presentation layer, and enables developers to develop a scalable and scalable controller to maintain the entire process.

16. What are the security settings in Tomcat configuration?
SSL etc...

17. What problems does Apach work with Tomcat to solve? How to implement it? How is the running process?
Balance, just like multi-instance, loading balance

18. Four interfaces of collection
Add ();
Addall ();
Isempty ();
Iterator ();
Contains ();

19. Cookie
20. Polymorphism
21. Transmission of Web Parameters
8 kinds

22. Differences between hashtable and hashmap
There are three important differences between the hashtable and hashmap classes. The first difference is mainly due to the historical reasons. Hashtable is based on the obsolete dictionary class, And hashmap is an implementation of the map interface introduced by Java 1.2.
Perhaps the most important difference is that the hashtable method is synchronous, while the hashmap method is not. This means that, although you can use a multi-threaded application without taking any special actionsProgramUse a hashtable, but you must also provide external synchronization for a hashmap. A convenient method is to use the static synchronizedmap () method of the collections class to create a thread-safe map object and return it as an encapsulated object. The method of this object allows you to access the potential hashmap synchronously. The result is that when you do not need synchronization, you cannot cut off the synchronization in hashtable (for example, in a single-threaded application), and synchronization increases a lot of processing costs.
The third difference is that only hashmap allows you to use a null value as the key or value of a table entry. Only one record in hashmap can be an empty key, but any number of entries can be empty values. That is to say, if no search key is found in the table, or if a search key is found but it is an empty value, get () returns NULL. If necessary, use the containkey () method to differentiate the two cases.

23. GC in the running environment
Auto running

24. Differences between final, finally, and finalzie
Final:
Final allows you to control whether your members, methods, or a class can be overwritten or inherited. These features make final an indispensable role in Java, it is also one of the keywords that must be known and mastered when learning Java.
Final member
When you define a variable in a class and add the final keyword before it, this variable cannot be changed once initialized, the unchangeable meaning here is that its value is immutable for the basic type, and its reference for the object variable cannot be changed. It can be initialized in two places, one is its definition, and the other is in the constructor, the two can only choose one.
Another method is to define the final parameter in the method. For variables of the basic type, this method has no practical significance, because the variables of the basic type are passed values when calling the method, that is to say, you can change this parameter variable in the method without affecting the call statement. However, it is very practical for the object variable because the object variable is passed with its reference during transmission, in this way, your modification to the object variable in the method will also affect the object variable in the call statement. When you do not need to change the object variable used as the parameter in the method, use final to declare it, it will prevent you from accidentally modifying the call method.
Final Method
There are two reasons to declare the method as final. The first is that you know that the function provided by this method has met your requirements and does not need to be extended, this method cannot be overwritten by any class inherited from this class, but inheritance can still inherit this method, that is, it can be used directly. The second is to allow the compiler to convert all calls to this method into an inline (in-line) Call mechanism, which will allow you to directly Insert the method subject to the call when calling the final method, instead of making routine method calls, such as saving breakpoints and pushing stacks, this may improve the efficiency of your program. However, when your method subject is very large, or if you call this method in multiple places, your caller Code It will expand rapidly, but may affect efficiency. Therefore, use final for method definition with caution.
Final class
When using final on a class, you need to consider it carefully. Because a final class cannot be inherited by anyone, it means that this class is a leaf class in an inheritance tree, in addition, such designs have been considered perfect without modification or expansion. For members in the final class, you can define it as final or not final. For methods, because the class is final, they naturally become final. You can also explicitly add a final to the methods in the final class, but this is obviously meaningless.

Finally:
The finally keyword is the best supplement to the Java Exception Handling Model. The finally structure enables code to always be executed, regardless of exceptions. Using Finally, you can maintain the internal status of an object and clear non-memory resources. Without finally, your code will be hard to understand. For example, the following code describes how to write code to release non-memory resources without using finally:

Finalize:
According to the Java language specification, the JVM ensures that the object is reachable before the finalize function is called, but the JVM does not guarantee that the function will be called. In addition, the finalize function can run at most once.
In general, finalize is used to release very important resources that are not easily controlled, such as I/O operations and data connections. The release of these resources is critical to the entire application. In this case, programmers should primarily manage (including release) these resources through the program itself, supplemented by the finalize function to release resources, to form a double-insurance management mechanism, instead of relying solely on finalize to release resources.

25. Session
Managed by Server

26. multi-thread programming: record their respective time.
Dull

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.