Java --- Java interview questions (1), java --- java interview questions

Source: Internet
Author: User

Java --- Java interview questions (1), java --- java interview questions

    • 1. What is a Java Virtual Machine? Why is Java called a platform-independent programming language "?
    • Java virtual machine is a virtual machine process that can execute Java bytecode. Java source files are compiled into bytecode files executed by Java virtual machines.
    • Java is designed to allow applications to run on any platform without the need for programmers to rewrite or recompile each platform separately. The Java virtual machine makes this possible because it knows the command length and other features of the underlying hardware platform.
    • 2. What does the "static" keyword mean? Can I overwrite a private or static method in Java?
    • The "static" keyword indicates that a member variable or member method can be accessed without an instance variable of the class.
    • The static method in Java cannot be overwritten, because it is dynamically bound at runtime, while the static method is statically bound at compilation. The static method is irrelevant to any instance of the class, so it is not applicable in concept.
    • 3. How can I create a thread? Which one do you like? Why?
    • There are three ways to create a thread:
    • Inherit Thread class
    • Implement the Runnable interface
    • Applications can use the Executor framework to create thread pools.
    • The Runnable interface is more popular because it does not need to inherit the Thread class. When other objects have been inherited in the application design, this requires multi-inheritance (but Java does not support multi-inheritance) and only interfaces can be implemented. At the same time, the thread pool is also very efficient and easy to implement and use.
    • 4. What are the basic interfaces of the Java Collection framework?
    • Java Collection classes provide a set of well-designed interfaces and classes that support operations on a group of objects. The most basic interfaces in the Java Collection class are:
    • Collection: represents a group of objects, each of which is its child element.
    • Set: a Collection that does not contain duplicate elements.
    • List: an ordered collection that can contain duplicate elements.
    • Map: You can Map a key to a value object. The key cannot be repeated.
    • 5. How can we weigh whether unordered arrays or ordered arrays are used?
    • The biggest benefit of an ordered array is that the time complexity of searching is O (log n), while that of an unordered array is O (n ). The disadvantage of an ordered array is that the time complexity of the insert operation is O (n), because elements with a large value need to be moved back to place new elements. On the contrary, the insertion time complexity of unordered arrays is constant O (1 ).
    • 6. What are the best practices of the Java Collection framework?
    • It is very important to select the type of the set to be used based on application requirements. For example, if the element size is fixed and can be known in advance, we should use Array instead of ArrayList.
    • Some collection classes allow you to specify the initial capacity. Therefore, if we can estimate the number of stored elements, we can set the initial capacity to avoid re-computing the hash value or resizing.
    • For type security, generics are always used for readability and robustness reasons. At the same time, the use of generics can also avoid the ClassCastException during runtime.
    • Using the immutable class provided by JDK as the Map key can avoid implementing the hashCode () and equals () methods for our own classes.
    • When programming, the interface is better than the implementation.
    • When the underlying set is actually null, the returned set with a length of 0 or an array does not return null.
    • 7. What is a Java Priority Queue )?
    • PriorityQueue is an unbounded Queue Based on the priority heap. Its elements are sorted by natural order. During creation, we can provide it with a comparator responsible for sorting elements.
    • PriorityQueue does not allow null values because they have no natural order, or they do not have any associated comparator. At last, PriorityQueue is NOT thread-safe. the time complexity of queuing and departure is O (log (n )).
    • 8. 30. Do you know big-O notation? Can you give examples of different data structures?
    • The Big O symbol describes how good the algorithm scale or performance is in the worst scenario when the elements in the data structure increase.
    • Large O symbols can also be used to describe other behaviors, such as memory consumption. Because the collection class is actually a data structure, we generally use the big O symbol to choose the best implementation based on time, memory and performance. The large O symbol can give a good description of the performance of a large amount of data.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

**************************************** **************************************** *********

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.