Summary of Baidu Java R & D questions and java R & D questions

Source: Internet
Author: User

Summary of Baidu Java R & D questions and java R & D questions

1. Analysis of Common application scenarios in singleton mode.

Among the 23 design modes, the singleton mode is the largest. It is easy to understand, but applicable to scenarios. Are you really familiar with this? The use of Singleton is because there is no need to create an object for each request, which wastes both CPU and memory. The use of multiple examples is to prevent concurrency problems; that is to say, a request changes the state of the object. At this time, the object processes another request, and the previous request changes the state of the object, causing the object to process another request incorrectly.

Let's talk about the singleton Application Scenario in Java web: the database connection pool is the singleton mode, with only one connection pool manager managing multiple connection pool objects. Objects in common service and dao layers are generally single-instance (because all requests are processed by one object), and actions in struts2 are multiple examples, because each request is processed with a new object (because action itself contains the value of the request parameter, the status can be changed ). Log4j logging is also a singleton mode, because only one object is maintained from the beginning. (Generally, the log application of an application is implemented in singleton mode. This is generally because the shared log file is always open, because only one instance can be operated, otherwise, the content cannot be appended ).

2. What is a balanced binary tree.

It is either an empty tree or a binary tree of the following nature: the absolute value of the depth difference between its left and right subtree cannot exceed 1, the left and right subtree are both a balanced binary tree.

3. What is a red/black tree.

The red and black trees are special balanced binary trees. Follow the red theorem and the black theorem. Red theorem: there cannot be two connected red nodes in one path; black theorem: the root node must be a black node, and all nodes are directed to the end of the tree, the number of black nodes must be equal.

4. What is B tree. (Binary Search Tree)

All nodes store one keyword. The left pointer of a non-leaf node points to a subtree smaller than its keyword, And the right Pointer Points to a subtree larger than its keyword. All non-leaf nodes have a maximum of two sons.

5. What is B-tree. (Multi-path Search Tree)

Root Node son tree [2, m]; non-root node non-leaf node son tree [m/2, m]; each node has a keyword number of [m/2-1, m-1

6. What is the B + tree.

The B + tree is a variant of the B-tree. Based on the B-tree definition, it is added that all keywords appear on the leaf node, and a chain pointer is added to all leaf nodes; the number of Subtrees and keywords for non-leaf nodes is the same.

Summary:A balanced binary tree is a binary search tree. It can ensure that the node is found in the log2 (n) time, while the performance of the common Binary Search Tree is similar to the linked list in the worst case. The time used is log (n).The red/black tree is used for internal sorting, that is, it is fully stored in the memory. The internal implementation of Microsoft STL map and set is the red/black tree.Tree B is usually stored in the memory, and most of the data is stored in the memory. Because the number of B-tree layers is small, you can ensure that each operation reads as few disks as possible. When the data is small and can be fully stored in the memory, the time complexity of the red/black tree is lower than that of the B tree.On the contrary, when the data volume is large and the external storage occupies the main part, the B-tree has a faster speed because it reads less disk times.    

Supplement the red-black tree: although the hash table is quickly searched, the hash table length will become longer and conflicts will increase as the data types increase, how can we achieve high performance in the case of large data volumes? At the same time, we know that the tree is a good data structure, which is used for insertion, deletion, and search. It is a very efficient data tree structure, but the problem is that in very bad circumstances, the operation is time-consuming and its performance is not guaranteed. For example, if the left and right subtree in the binary search tree are too far apart, it will be time-consuming to search. In this case, to ensure its efficiency, we must ensure that the Left and Right trees cannot be too far away. When inserting data into the tree, we should adjust the data according to certain rules to make it conform to the rules, this improves the overall and local search efficiency. This is the rule of the red and black trees.

7. Differences between final finally finalize.

Finalize is a method, and it is a method in the Object class. When the Garbage Collector determines that this object is not referenced, it calls the finalize method of the object. It is used to perform some necessary cleanup work before GC clears objects (for example, the finalize method of input/output connected objects can execute explicit I/O transactions, to interrupt the connection before permanently dropping the object ).

Finally is used in the try and catch exception mechanism and will be executed in any case.

The final modifier class indicates that the object cannot be inherited. It modifies the basic data type, that is, the constant is immutable. It modifies the reference type, and the object content pointing to is variable, and the object is immutable.

8. Error Exception RuntimeException

The inheritance structure of the Exception mechanism first, the base class is Throwable; Error and Exception inherit Throwable; RuntimeException and IOException inherit Exception (that is, the specific RuntimeException inherits RuntimeException ).

Error describes internal errors and resource depletion. Applications should not throw such objects (usually thrown by virtual machines ). The program level cannot be processed.

Exception includes RuntimeException and other non-RuntimeException. RuntimeException includes incorrect type conversion, out-of-bounds array access, and attempts to access null pointers. The principle for processing RuntimeException is: If RuntimeException occurs, it must be a programmer error. For example, you can check the array subscript and array boundary to avoid array out-of-bounds access exceptions. Non-RuntimeException (IOException, etc.): This type of exception is generally an external error, such as an attempt to read data from the end of the file. This is not a program error, an external error occurs in the application environment.

Summary: for example, 5/0 is a runtimeException. If this exception is not handled in the program, no error is reported and an exception is reported during running.A non-runtimeException exception is a try catch exception in the program. If it is not processed, an error is returned..

9. Differences Between TCP UDP HTTP HTTPS SFTP FTP

TCP reliable connection, three handshakes, four waves.

Unreliable UDP connection.

HTTPS

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.