Java frequently tested surface questions

Source: Internet
Author: User

  1. What are the basic interfaces of the Java Collection Class framework?
    Reference answer
    The collection class interface specifies a set of objects called elements. Each specific implementation class of the collection class interface can optionally save and sort the elements in its own way. Some collection classes allow duplicate keys, some are not allowed.
    The Java Collection class provides a set of well-designed interfaces and classes that support the manipulation of a set of objects. The most basic interfaces within the Java Collection class are:
    Collection: Represents a set of objects, each of which is its child element.
    Set: A collection that does not contain duplicate elements.
    List: A sequence of collection, and can contain repeating elements.
    Map: You can map a key (key) to an object with a value, and the key cannot be duplicated.

  2. What is the difference between iterator and listiterator?
    Reference answer
    Their differences are listed below:
    The iterator can be used to traverse the set and list collection, but Listiterator can only traverse the list.
    Iterator to a collection can only be forward traversal, listiterator can be either forward or back.
    Listiterator implements the iterator interface and includes other functions such as adding elements, replacing elements, getting the index of the previous and subsequent elements, and so on.

  3. What is the difference between fast failure (fail-fast) and security failure (fail-safe)?
    Reference answer
    Iterator's security failure is based on a copy of the underlying collection, so it is not affected by modifications on the source collection. All of the collection classes below the Java.util package are fast failures, and all classes under the Java.util.concurrent package fail safely. A fast-failing iterator throws an concurrentmodificationexception exception, and a security-failed iterator never throws such an exception.

  4. If the object's reference is set to NULL, will the garbage collector immediately release the memory occupied by the object?
    Reference answer
    No, in the next garbage collection cycle, this object will be recoverable.

  5. Will garbage collection occur in the JVM's permanent generation?
    Reference answer
    Garbage collection does not occur in a permanent generation, and if it is permanently full or exceeds the threshold, a full GC is triggered. If you look closely at the output of the garbage collector, you will find that the permanent generation is also recycled. This is why the correct permanent generation size is very important for avoiding full GC. Please refer to the following Java8: from the permanent generation to the Meta data area
    (Note: The permanent generation has been removed from the Java8 and a new native memory area called the metadata area has been added)

  6. What is JDBC?
    Reference answer
    JDBC is an abstraction layer that allows users to choose between different databases. JDBC allows developers to write database applications in Java without needing to be concerned with the specifics of a particular database at the bottom.

  7. Explain the life cycle of the servlet.
    Reference answer
    For each client request, the servlet engine loads the servlet and invokes its init () method to complete the initialization of the servlet. The Servlet object then processes all subsequent requests from the client by invoking the service () method separately for each request, and finally calls the servlet (translator Note: This should be the servlet instead of the server) destroy () method to remove the servlet.

  8. What are the advantages of object-oriented software development?
    Reference answer
    Code development is modular and easier to maintain and modify.
    Code reuse.
    Enhance the reliability and flexibility of your code.
    Increase the understandable nature of the code.
    Object-oriented programming has many important features, such as encapsulation, inheritance, polymorphism, and abstraction. We will analyze these features one by one in the following sections.

Java frequently tested surface questions

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.