Agent or combination – occurs at run time because it is more dynamic and flexible.
5. Can you differentiate between compile-time inheritance and runtime inheritance by using an instance, and what kind of Java support is indicated?
Inheritance represents the scene in which actions and attributes are passed from one object to another. The Java language itself only supports compile-time inheritance, which is implemented by means of the "extends" keyword to produce subclasses, as follows:
public class Parent { public String saysomething () { return "pare NT is called "; }} public class child extends Parent {@Override public String saysomething () { return super . saysomething () +
The call to the SaySomething () method of the
Child class returns "Parent is Called,child is called" because the call to the subclass inherits the "Parenet is called" of the parent class. The keyword "Super" is the method used to invoke the "Parent" class. Run-time inheritance represents building a parent/child class relationship at run time. The Java language itself does not support run-time inheritance, but there is an alternative scenario called "proxy" or "combination", which represents a subclass of a hierarchical object at run time. This simulates the implementation of run-time inheritance. In Java, the typical implementation of an agent is as follows:
Public class Parent { public String saysomething () { return ' parent is called '; Publicclass child { public String saysomething () { return New Parent (). saysomething () + ", child is called"; }}
The child class proxies the invocation of the parent class. Combinations can be implemented in the following ways:
Public class Child { privatenull; Public Child () { thisnew Parent (); } Public String saysomething () { returnthis. parent.saysomething () + ", Child is called "; }}
What are the volatile variables in 6.Java?
Volatile is a special modifier that can only be used by member variables. Multithreaded operations on member variables are transparent to other threads in the absence of a synchronization class for Java concurrency programs. The volatile variable guarantees that the next read operation will occur after the previous write operation.
7. What is Futuretask?
In a Java concurrency program, Futuretask represents an asynchronous operation that can be canceled. It has the methods of starting and canceling operation, whether the query operation is complete and retrieving the result of operation. The result can be retrieved only when the operation is complete, and the Get method will block if the operation has not been completed. A Futuretask object can be wrapped on an object that calls callable and runnable, because Futuretask also calls the Runnable interface so it can be submitted to executor for execution.
What is the difference between interrupted and isinterrupted methods in 8.Java?
The main difference between interrupted () and isinterrupted () is that the former clears the interrupt state and the latter does not. The Java Multi-threading interrupt mechanism is implemented with an internal identity, and calling Thread.Interrupt () to break a thread sets the interrupt ID to true. The interrupt state is zeroed when the interrupt thread calls the static method thread.interrupted () to check the break state. The non-static method, isinterrupted (), is used to query the interrupt state of other threads without changing the interrupt status identifier. Simply put, any method that throws a Interruptedexception exception will clear the interrupt state. In any case, the interrupt state of a thread can be changed by other threads calling interrupts.
9. If you submit a task, the thread pool queue is full. What will happen when the meeting is made?
This question is tricky to ask, and many programmers think the task will block until the thread pool queue is empty. In fact, if a task cannot be scheduled to execute, then the Threadpoolexecutor's submit () method throws a Rejectedexecutionexception exception.
What is the difference between the submit () and execute () methods in a 10.Java thread pool?
Two methods can submit a task to the thread pool, the return type of the Execute () method is void, it is defined in the executor interface, and the Submit () method can return a future object holding the result of the calculation, which is defined in the Executorservice interface. It extends the executor interface, and other thread pool classes like Threadpoolexecutor and Scheduledthreadpoolexecutor have these methods.
What is the difference between a 11.volatile variable and a atomic variable?
First, the volatile variable and the atomic variable look alike, but the function is different. Volatile variables ensure that the antecedent relationship, that is, the write operation occurs before subsequent reads, but it does not guarantee atomicity. For example, if you modify the count variable with volatile, then the count++ operation is not atomic. The atomic method provided by the Atomicinteger class allows this operation to be atomic, such as the Getandincrement () method, which atomically increments the current value by one, and other data types and reference variables can be similarly manipulated.
12. What happens if a thread inside a synchronization block throws an exception?
This problem is a lot of Java programmers, if you can think of whether the lock release this clue to answer still a little hope to correct. Regardless of whether your synchronization block is normal or abnormal exit, the thread inside will release the lock, so the contrast lock interface I prefer the synchronization block, because it does not need me to expend the effort to release the lock, this function can release the lock implementation in the finally block.
I'm the dividing line of the king of the land Tiger.