Java Level 2 Exam Questions-T4

11 second-level exam questions

1. Compared with C++ language, the most prominent feature of Java language is ____

A, object-oriented
B, high-performance
C, cross-platform
D, classy library

This question examines the comparison between Java and C++.
On different platforms, Java has different JVMs, so that Java bytecode can run on different platforms across platform limitations. But C++ programs do not have platform independence.
Therefore, the answer to this question is C.

2. In the following description, the error is ___

A, Java provides a rich class library
B, Java maximizes the use of network resources
C, Java supports multi-threading
D, Java does not support TCP/IP protocol

This question examines the characteristics of the Java language.
The class library provided by Java supports the TCP/IP protocol, and applications can access objects anywhere on the network through URL addresses as simple as accessing local files.
So the answer to this question is D.

3. In the following Java language packages, the package that provides graphical interface components is ___

A、java.io
B、javax.swing
c、java.net
D、java.rmi

This question examines the API structure of Java.
java.io package: provides classes for program input/output file operations.
javax.swing package: provides lightweight components for building and managing application graphical interfaces.
java.net package: Provides classes for programs to perform network communication applications and URL processing.
java.rmi package: Provides classes required for remote method invocation.
Therefore, the answer to this question is B.
Click to learn javax.swing

4. In the following description, what is wrong is ____

A, javac.exe is the Java compiler
B, javadoc.exe is the Java document generator
c, javaprof.exe is the analysis tool of the Java interpreter
D, javap.exe is the Java interpreter

This question is about JDK tools.
java c .exe: Java compiler that can compile source code into bytecode and save it in the java working directory with a .class extension.
java doc .exe: Java document generator, which generates AP documents in MML format for Java source files and packages.
java prof.exe : Java profiling tool, providing interpreter profiling information.
java p .exe: Java class decomposer, which provides byte code disassembly for .class files and prints them .
So the answer to this question is D.

5. When executing a Java program, the option to connect the application to the debugger is ___

A、-D
B、-debug
C、-verbosegc
D、-mx

This question is about JDK tools.

  • D: Define the attribute name;
  • debug: connect the program to the debugger;
  • verbosegc: Every time the garbage collector releases memory, it prints a message;
  • mx: allocate the maximum memory value.
    Therefore, the answer to this question is B.

6. The synchronization mechanism provided by Java for I/O access is ____

A, byte stream
B, filtered stream
C, character stream
D, compressed file stream

This question is about filtering flow .
The synchronization mechanism provided by Java for I/O access is the filtering flow . Generally, using a filter stream requires that the filter stream be connected to a certain I/O stream first, and then the connected I/O stream is specified through the parameters of the construction method.
Therefore, the answer to this question is B.

7. Java provides many operation methods for file classes. The method to get the parent path name of the file object is _

A、getAbsolutePath()
B、getParentFile()
C、getAbsoluteFile()
D、getName()

This question examines the methods provided by the File class.
getAbsolutePath(): get the absolute path name of a file;
getParentFile(): get the parent path name of the file object;
getAbsoluteFile(): equivalent to new File(this.getAbsolutePath());
getName(): get a file that does not contain a path file name.
Therefore, the answer to this question is B.

8. In the following description, the error is ___

A. There is no special mechanism for detecting and avoiding deadlocks in Java.
B. Multiple threads in the program wait for each other's locks, which may cause deadlocks.
C. To avoid deadlocks, the order of obtaining locks can be defined in the Java program. Unlocking is to release
D in the reverse order of locking. In order to avoid deadlock, the order of acquiring locks can be defined in the Java program. Unlocking is to release in the positive order of locking.

This question examines the prevention and treatment of deadlock .

  • If multiple threads in the program wait for each other's locks, and they will not release their own locks before getting the other's locks, both parties cannot get the desired resources and the threads cannot continue to run. This is a deadlock.
  • There is no special mechanism for detecting and avoiding deadlocks in Java. In order to avoid deadlocks, the general approach that an application can use is: if the program wants to access multiple shared data, it must first consider defining a lock order from the global perspective, and in This sequence is followed throughout the program. When unlocking, release in the reverse order of locking .
    So the answer to this question is D.

9. Please read the procedure below

public class ThreadTest {
    
    
	public static void main(String args[]) throws Exception {
    
    
		int i=0;
		Hello t=new Hello();
		_____;
		while(true){
    
    
			System.out.println("Good Morning"+i++);
		if(i ==2&&t.isAlive()) {
    
    
			System.out.println("Main waiting for Hello!");
				t.join(;//等待t运行结束
}
		if  (i == 5) break;}
	}
}

class Hello extends Thread {
    
    
	int i;

	public void run() {
    
    
		while (true) {
    
    
			System.out.println("Hello" + i++);
			if (i == 5)
				break;
		}
	}
}

In order to make the program execute correctly, the underlined statement should be ___

A、t.sleep()
B、t.yield()
C、t.interrupt()
D、t.start()

This question examines thread scheduling and control.

  • sleep() : This method makes a thread suspend running for a fixed period of time, during its sleep time, let the thread with a lower priority run;
  • yield() : This method gives a thread with the same priority as the current thread a chance to run;
  • interrupt() : If a thread is blocked when calling sleep(), join(), wait(), etc., the
    interrupt() method will interrupt its blocking state, and the thread will receive an InterruptException;
  • start() : The newly created thread will not run automatically, this method must be called. Calling this method puts the virtual CPU embedded in the thread into a runnable state, which means it can be scheduled, but it does not mean that the thread will execute immediately.
    According to the program, in the ThreadTest class, when i=2 and thread t has been started, the current thread will be suspended after the output "Main waiting for Hello!" and thread t will be executed. If thread t is not started by the "t.start();" statement, thread t will not be executed when i=2, so the line should be filled with the statement to start thread t, and thread t will start running. When t runs 5 After the end, continue to call the i thread to end the remaining loop calls 3 times. Therefore, after creating an object t of the Hello class, you should call the start() method to make it runnable and wait to be called.
    So the answer to this question is D.

10. The default layout manager of the Panel class is

A、BorderLayout
B、CardLayout
C、FlowLayout
D、GridBagLayout

This question is about the layout manager.
FlowLayout is the default layout manager for Panel and Applet.
Therefore, the answer to this question is C.

11. In the following description, the error is ___

A, JButton class and label class can display icons and text
B, Button class and label class can display icons and text
C, AWT components can be directly added to the top-level container
D, Swing components cannot be directly added to the top-level container

This question examines components and containers.
Button is a common component. Swing buttons (JButton) and labels can display icons and text, while AWT buttons (Button) and labels can only display text. In terms of components, unlike AWT components, Swing components cannot be added directly to the top-level container, it must be added to a content panel associated with the top-level Swing container.
Therefore, the answer to this question is B.

Guess you like

Origin blog.csdn.net/m0_49095721/article/details/109131395