1. The mistake about the Spring argument is ()
A. Spring is a framework collection of lightweight Java EE
B. Spring is the implementation of "Dependency injection" mode
c. using spring to implement declarative transactions
D. Spring provides an AOP-style journaling system
Solution: D,spring does not have its own log system, only with the log system log4j implementation of our own log system.
Development:
AOP is the abbreviation of Aspect oriented programming, which means that it is a kind of technology to implement the unified maintenance of program function by precompilation and runtime dynamic agent. AOP is a continuation of OOP, a hotspot in software development, an important content in spring framework, and a derivative paradigm of functional programming.
Spring through the support of AOP, with the help of log4j and other Apache open source components to implement the logging system.
2. The following code will print out
public static void Main (string[] args) {
String classfile = "com. JD.". ReplaceA11 (".", "/") + "Myclass.class";
System.out.println (Classfile);
}
A. com. JD
B. Com/jd/myclass.class
C. ///////myclass.class
D. Com.jd.MyClass
solution: C, because the first parameter of the ReplaceAll method is a regular expression, and "." Any character is represented in the regular expression, so all the character characters of the preceding string are replaced with "/". If you want to replace just ".", then write "\. "
3.Given the following code:
public class Enclosingone
{public class
Insideone {}
} public
class Inertest
{public
static void Main (String[]args)
{
Enclosingone eo = new Enclosingone ();
Insert code here
}
}
Which statement at line 7 constructs a instance of the inner class?
A. insideone ei=eo.new insideone ();
B. EO. Insideone ei=eo.new Insideone ();
C. insideone ei=enclosingone.new insideone ();
D. enclosingone.insideone ei=eo.new insideone ();
solution: D,
public class Enclosingone {
//non-static Internal classes public class
Insideone {}
//Static internal classes public
static class insidetwo{}< c4/>}
class mytest{public
static void main (String args []) {
Enclosingone.insideone obj1 = new Enclosingone ( ). New Insideone ()//Non-static Internal class object, Non-static, Enclosingone object before attribute
enclosingone.insidetwo obj2 = new Enclosingone.insidetwo ();//Static internal class object
}
}
4. The following is a description of the Java memory model, which is the wrong statement.
A. JMM provides memory visibility guarantees for Java programmers by controlling the interaction between primary memory and the local memory of each thread
B. "Synchronized"-ensures that the primary memory value is synchronized to the working memory at the beginning of the block, and the variable is synchronized back to the main memory at the end of the block
C. "volatile"-ensures that modifications are updated with the main memory before reading the variable.
D. If after a thread constructs an immutable object (the object contains only the final field), you can guarantee that the object is viewed correctly by another thread
solution: D,
Communication between Java threads is controlled by the Java Memory Model (JMM), JMM determines when a thread's write to a shared variable is visible to another thread. From an abstract point of view, JMM defines the abstract relationship between threads and main memory: Shared variables between threads are stored in main memory (main memory), each of which has a private local memory (native memory) that is stored in local memory to read/write copies of shared variables. Local memory is an abstract concept of JMM and is not real. It covers caching, write buffers, registers, and other hardware and compiler optimizations
The write-read of volatile variables enables communication between threads.
From the memory semantics point of view, volatile has the same effect as the monitor lock: volatile write and monitor release have the same memory semantics; volatile read has the same memory semantics as the monitor's acquisition.
5. Suppose the following code, if the T1 thread has finished starting before the T2 thread starts. The output of the Code is ()
public static void Main (String[]args) throws Exception {
final Object obj = new Object ();
thread T1 = new Thread () {public
void run () {
synchronized (obj) {
try {
obj.wait ();
System.out.println ("Thread 1 Wake Up.");
catch (Interruptedexception e) {}}}}
;
T1.start ();
Thread.Sleep (1000);//we assume thread 1 must start up within 1 sec.
Thread t2 = new Thread () {public
void run () {
synchronized (obj) {
obj.notifyall ();
System.out.println ("Thread 2 sent notify.");}}
;
T2.start ();
}
A. Thread 1 Wake Up
Thread 2 sent notify.
B. Thread 2 sent notify.
Thread 1 Wake Up
C. A, B is possible
D. procedure no output card dead
Solution: B, the lock is released when the obj.wait () is executed, so T2 can get the lock again, and then send a message to notify the T1 to execute, but T2 has not released the lock, so it must be T2 and then release the lock, then T1 will have a chance to execute.
Development:
Notify () is the wake-up action on an object lock. But one thing to note is that after the Notify () call, instead of releasing the object lock immediately, but after the corresponding synchronized () {} statement block executes, and the lock is automatically released, the JVM randomly picks a thread in the threads of the Wait () object lock, gives its object lock, wakes the thread, Continue execution. This provides a synchronized, wake-up operation between threads.
6.
public class Test
{
static boolean foo (char c)
{
System.out.print (c);
return true;
}
public static void Main (string[] argv)
{
int i = 0;
For (foo (' A '); foo (' B ') && (I < 2); foo (' C '))
{
i++;
Foo (' D ');}}}
What is the result?
A. ABDCBDCB
B. ABCDABCD
C. compilation fails.
D. An exception are thrown at runtime.
solution: A,
for (condition 1; condition 2; condition 3) {
Statement
}
The order of execution is conditional 1-> condition 2-> statement-> condition 3-> condition 2-> conditional-> Condition 2 ...
If condition 2 is true, it is executed all the time. The For loop ends if the condition is 2-bit false
7. Consider the following simple example, let's see how reflection works.
Import java.lang.reflect.*;
public class dumpmethods{public
static void Main (string[] args) {
try {
class C=class.forname (Args[0]);
Method M[]=c.getdeclaredmethods ();
for (int i = 0; i < m.length i++) {
System.out.println (m[i].tostring ());
}
catch (Throwable e) {
Sy Stem.err.println (e);
}
}
The function of "C.getdeclaredmethods" is:
A. obtaining a public method object for a class
B. obtaining all public method names for a class
C. getting all method objects of a class
D. None of the above options are correct
solution: C,
Public method[] Getdeclaredmethods () returns all methods declared by a class or interface, including public, protected, default (package) Access, and method objects of private methods. But does not include inherited methods. Of course, it also includes the way it implements the interface.
Public method[] GetMethods () returns all the methods of a class, including the common method of its inheriting class, and, of course, the methods of the interface it implements.
8. Which of the following ways can be used to implement notifications and wakes between threads: ()
A. Object.wait/notify/notifyall
B. Reentrantlock.wait/notify/notifyall
C. Condition.await/signal/signalall
D. Thread.wait/notify/notifyall
solution: AC,
Wait (), notify (), and Notifyall () are methods in the object class;
Condition is present in Java 1.5, which replaces the traditional wait (), notify () of the object to implement the collaboration between threads, compared to the Wait (), notify () using object, await (), Signal () This approach enables more secure and efficient threading collaboration.
Development:
Wait (), notify (), and Notifyall () are methods in the object class
From the textual description of these three methods, you can know the following information:
1 the Wait (), notify (), and Notifyall () methods are local methods and cannot be overridden for the final method.
2 The Wait () method that invokes an object can block the current thread and the current thread must own the monitor (that is, the lock) of the object.
3 The Notify () method that invokes an object wakes up a thread that is waiting for the monitor for the object, and wakes only one of the threads if multiple threads are waiting for the object's monitor;
4 Call the Notifyall () method to wake up all the threads that are waiting for monitor on this object;
A friend might have questions: Why are these three not methods in the thread class declaration, but methods declared in the object class
(Of course, because the thread class inherits the object class, thread can also invoke three methods). In fact, this question
The problem is simple, because each object has a monitor (that is, locks), so let the current thread wait for the lock of an object, of course
It should be done through this object. Instead of working with the current thread, because the current thread may wait for multiple threads
Locks, if manipulated through threads, are very complicated.
As mentioned above, if you invoke the Wait () method for an object, the current thread must have a monitor for the object (that is,
Lock), so invoking the wait () method must be done in either the synchronization block or the synchronization method (synchronized block or
Synchronized method).
Calling the Wait () method of an object is equivalent to having the current thread hand over the monitor for this object and then into the waiting state.
Wait for subsequent locks on this object again (the Sleep method in the thread class causes the current thread to suspend execution for a period of time, from
And let other threads have the opportunity to continue to execute, but it does not release object lock);
The Notify () method wakes up a thread that is waiting for the monitor for the object, and when multiple threads are waiting for the object
Monitor, you can only wake one of the threads, and it is not known exactly which thread to wake.
Similarly, invoking the Notify () method of an object, the current thread must also have the monitor for the object, so call
The Notify () method must be performed either in a synchronized block or in a synchronization method (synchronized block or Synchronized method).
The Nofityall () method is able to wake up all threads that are waiting for monitor for the object, unlike the Notify () method.
Condition is present in Java 1.5, which replaces the traditional wait (), notify () of the object for the collaboration between threads, compared to the Wait (), notify () using object, await using Condition1 () , signal () is a more secure and efficient way to collaborate between threads. Therefore, it is generally recommended that condition be used, and blocking queues actually use condition to simulate the collaboration between threads.
Condition is an interface, the basic method is await () and signal () method;
Condition relies on the lock interface, generating a condition base code is lock.newcondition ()
Calls to condition's await () and signal () methods must be within lock protection, which means that lock.unlock () in Conditon () must be used between Lock.lock () and await to use the object's wait (); signal () in condition () corresponds to the Notify () of object, Signalall () in condition corresponds to the Notifyall () of object.
9.java String str = "Hello World" The following statement is wrong.
A. str+= ' a '
B. int strlen = Str.length
C. str=100
D. str=str+100
Solution: ABC
A. ' A ' is a character, ' a ' which is a space and a, must use ' a ' to be able;
B.string has length () method
C.int cannot be directly converted to a string type
D. Tail add string "100"
10. The following classes of definitions are known:
Class Base {public
base () {
//...
}
Public Base (int m) {
//...
}
public void Fun (int n) {
//...
}
}
public class Child extends base{
//member Methods
}
Which of the following sentences can be added to the subclass correctly.
A. private void Fun (int n) {//...}
B. void Fun (int n) {//...}
C. protected void Fun (int n) {//...}
D. public void Fun (int n) {//...}
Solution: the override (override) of the D
method is the same as the two smaller principles: the
Method name, the same parameter type
subclass return type less than or equal to the parent class method return type. The
subclass throws an exception that is less than or equal to the parent class method throws an exception, and the
Subclass access permission is greater than or equal to the parent class method access.