In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the Java autumn interview test questions". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the Java autumn interview test questions"?
1. The difference between the start () and run () methods of the hread class.
Answer: the start () method creates a new thread and starts it, so the method calls other native methods, and the run () method is a normal Java method call, which executes java code in the original thread.
2. The difference between Runnable and Callable in Java.
Answer: both Runnable and Callable represent tasks to be executed in the thread. Runnable was joined by JDK1.0, and Callable was actually joined at JDK1.5. The difference: the call () method of Callable can return a value and throw an exception, while the run () method of Runnable cannot return a value or throw an exception. The Callable needs to be submitted using the java.util.concurrent.ExecutorService.submit (Callable) method, so that you can get the Future object, which can load the results returned by the call () method of the Callable interface.
3. Briefly describe the Java memory model.
Answer: the Java memory model contains a series of rules and guidelines. Java language is cross-platform, and Java's memory model ensures that Java has definite behavior on different operating systems, CPU, and memory architecture, especially in the case of multithreading, the changes made by one thread are important to whether other threads are visible or not, which is called antecedent relationship.
4. The benefits of posture
Answer: allow different objects to respond to the same message, that is, the same message can adopt many different behaviors according to the different sending objects (sending messages is function calls). The main advantages are as follows:
Replaceability: polymorphism is replaceable for existing code
Extensibility: adding new subclasses does not affect the existing class structure
Interfaceability: polymorphism is achieved by a superclass that provides a public interface to a subclass through a method signature, which is perfected or overridden by the subclass.
5. Do you want to create an immutable object that contains mutable objects?
Answer: of course, you can create an immutable object that contains mutable objects, you just need to be careful not to share references to mutable objects, and if you need to change, return a copy of the original object. The most common example is that an object contains a reference to a date object.
6. What are the public methods in bject?
Answer:
Equals ()
Clone ()
GetClass ()
Notify (), notifyAll (), wait ()
ToString
7. Four quotes in Java:
Answer: strong reference, soft reference, weak reference, virtual reference. Different reference types are mainly reflected in GC.
(1) strong reference: if an object has a strong reference, it will not be reclaimed by the garbage collector. Even if the current memory space is insufficient, JVM does not reclaim it, but instead throws an OutOfMemoryError error, causing the program to terminate abnormally. If you want to break the association between a strong reference and an object, you can explicitly assign the reference to null so that JVM will recycle the object at the appropriate time.
(2) soft reference: when using a soft reference, if there is enough memory space, the soft reference can continue to be used without being reclaimed by the garbage collector, and only when there is insufficient memory will the soft reference be reclaimed by the garbage collector.
(3) weak references: objects with weak references have a shorter life cycle. Because when JVM performs garbage collection, weak references will be reclaimed once weak reference objects are found, regardless of whether the current memory space is sufficient or not. However, because the garbage collector is a low-priority thread, weak reference objects may not be found quickly.
(4) false reference: as the name implies, it is nonexistent. If an object only holds a virtual reference, it is equivalent to no reference and can be reclaimed by the garbage collector at any time.
What is a compiler constant? What are the risks of using it?
Answer: public static immutable (public static final) variables are what we call compile-time constants, where public is optional. In fact, these variables are replaced at compile time because the compiler knows the values of these variables and that they cannot be changed at run time. One problem with this approach is that you use a public compile-time constant in an internal or third-party library, but this value is later changed by someone else, but your client is still using the old value, and you have even deployed a new jar. To avoid this, be sure to recompile your program when you update dependent JAR files.
9. How to determine whether an object should be recycled?
Answer: this is the so-called object viability judgment. There are two common methods: citation counting and object accessibility analysis. Because the reference counting method has the problem that GC can not be carried out due to mutual reference, object reachability analysis algorithms are often used in JVM virtual machines at present.
10. What guarantees do volatile type variables provide?
Answer: volatile has two main functions: avoiding instruction rearrangement and ensuring visibility. For example, JVM or JIT will reorder statements for better performance, but volatile type variables will not be reordered with other statements even without synchronous blocks. Volatile provides happens-before guarantees to ensure that changes made by one thread are visible to other threads. In some cases, volatile can also provide atomicity, such as reading 64-bit data types, such as long and double are not atomic (low 32-bit and high 32-bit), but double and long of volatile type are atomic.
Thank you for your reading, the above is the content of "what are the Java Autumn greeting Test questions". After the study of this article, I believe you have a deeper understanding of what the Java Autumn greeting examination questions have, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.