Sort out typical Java Authentication interview questions

Source: Internet
Author: User

1.JavaThe simple and application of the exception handling mechanism in.

WhenJavaProgramWhen Java's Semantic Rules are violated, the Java Virtual Machine will indicate an error as an exception. There are two types of violation of Semantic Rules. One is the built-in semantics of the Java class library. For example, if the array subscript is out of the range, indexoutofboundsexception is triggered. When a null object is accessed, nullpointerexception is thrown. Another scenario is that Java allows programmers to extend this semantic check. programmers can create their own exceptions and choose when to use the throw keyword to cause exceptions. All exceptions are subclasses of Java. Lang. thowable.

2. the similarities and differences between Java interfaces and C ++ virtual classes.

Because Java does not support multi-inheritance, it is possible that a class or object must use methods or attributes in several classes or objects respectively. The existing single Inheritance Mechanism cannot meet the requirements. Compared with inheritance, interfaces are more flexible because they do not have any implementations.Code. After a class implements an interface, it must implement all the methods and attributes in the interface. The attributes in the interface are public static under the default state, and all methods are public by default. A class can implement multiple interfaces.

3. Advantages and principles of garbage collection. Two recovery mechanisms are also considered.

A notable feature of Java is the introduction of the garbage collection mechanism, which helps C ++ programmers solve the most troublesome memory problems, it makes memory management unnecessary for Java programmers when writing programs. Because of the garbage collection mechanism, objects in Java do not have the concept of "Scope", and only objects can be referenced with "Scope ". Garbage collection can effectively prevent memory leakage and effectively use available memory. The garbage collector is usually used as a separate low-level thread to clear and recycle objects that have died or are not used in the memory heap for a long time, programmers cannot call the Garbage Collector to recycle an object or all objects in real time. The collection mechanism involves generational replication, garbage collection, marking, and incremental garbage collection.

4. thread synchronization method.

Wait (): puts a thread in the waiting state and releases the lock of the object it holds.

Sleep (): It is a static method that calls a running thread to capture interruptedexception exceptions.

Y (): Wake up a thread in the waiting state. Note that when calling this method, it cannot exactly wake up a thread in the waiting state, instead, the JVM determines which thread to wake up, not by priority.

Allnotity (): Wake up all threads in the wait state. Note that it is not a lock for all wake-up threads but a lock for them to compete.

5. What is the difference between error and exception?

Error indicates system-level errors and exceptions that the program does not need to handle,

Exception indicates the exceptions that need to be captured or processed by the program.

6. in Java, a class is declared as the final type. What does it mean?

Indicates that the class cannot be inherited. It is a top-level class.

7. What is the difference between heap and stack.

A stack is a linear set. Operations on adding and deleting elements must be completed in the same segment. The stack is processed as follows. Heap is an element of stack.

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.