Java Fundamentals problem Consolidation (1)

Source: Internet
Author: User

    1. Do you know about Java garbage collection? When do I need to use it?

A: The purpose of the garbage collector is to find and reclaim (clean) useless objects, allowing the JVM to use memory more efficiently. But running because garbage collection itself has overhead, too frequent use can cause performance degradation. For example, some programs need a lot of memory in the short term, it is necessary to force a garbage collection command, so that more available physical memory. The purpose of garbage collection is to identify and discard objects that the application is no longer using to free and reuse resources.

2. What does static understand? When do I need to use it?

A :static is a modifier, and a method / variable modified by the static keyword does not need to be accessed by a dependent object, that is, as long as the class is loaded, can be accessed through the class name. Static is required when a method or variable needs to be initialized for loading, or when it needs to be called frequently .

3. multithreading issues, how to guarantee deadlocks when multiple threads need access to multiple resources.

A: The way to avoid deadlocks in multiple threads is to specify the order in which locks are acquired, so that all threads acquire and release locks in the same order, thus avoiding deadlocks.

4. There are several ways of stitching between strings (str1 and str2) , and what is the difference?

answer : There are two ways,str1+str2 directly using + for splicing, or using StringBuilder the way

" StringBuilder sb= new StringBuilder ();

Sb.append (STR1);

Sb.append (STR2); " if through the loop 1000 number splicing test found that StringBuilder in the case of stitching, which time-consuming than the + splicing way less. if the concatenation of the string more than the memory can be the first test. Combining time-consuming we can draw the conclusion that StringBuilder is preferred when using a large number of string concatenation .

5. Do you know about the two-fork tree?

A : two fork tree each node has a maximum of two subtrees, the left and right subtree is in order, even if only one subtree to distinguish the binary tree. The traversal of the binary tree, starting from the root node, accesses all nodes of the binary tree in some order. (Pre-order sequential traversal)

6. variables A and B, need to exchange values, but no third variable, how to implement?

Answer: A=a+b; B=a-b; A=a-b; Final output A B

Java Fundamentals problem Consolidation (1)

Related Article

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.