java topic (4)

1. Assuming that class A has the following definition, let a be an instance of class A, which of the following statements is wrong? ( )
class A{
static int i;
String s;
static void method1() { }
void method2() { }

}

A. System.out.println(a.i);
B. a.method1();
C. A.method1();

D. A.method2()

Analysis : static properties and methods in a class can be accessed through the class name or object; non-static methods must be accessed through the object

2. What are the three basic characteristics of object-oriented programming languages? ( )

A. Encapsulation, Interfaces and Polymorphism
B. Inheritance, Interfaces and Dynamics
C. Cross-Platform, Interfaces and Dynamics

D. Encapsulation, Inheritance, and Polymorphism

3. Which keyword can add a mutex to an object? ( )

A. synchronized
B. volatile
C. serialize

D. static

Analysis :
synchronized keyword: Used to lock objects and methods or code blocks. When it locks a method or a code block, at most one thread executes this code at the same time.
volatile: used to ensure that the update operation of the variable is notified to other threads. When the variable is declared as volatile, the compiler and runtime will notice that the variable is shared, so the operation on the variable will not be shared with other Memory operations are reordered together. However, no locking operation is performed when accessing a volatile variable, so the thread of execution is not blocked, so volatile variables are a more lightweight synchronization mechanism than the synchronized keyword.
serialize: Java objects are serialized into binary files.
static keyword: The static keyword can modify variables, methods, and static code blocks.
                          Static variable:
                                          A variable modified by static is called a static variable
                                          . A static variable belongs to a class, not an object.
                                          Static variable has only one copy (only one static variable is loaded in a class)
                         Static method:
                                          can only be called in a static method Static variables and static methods
                                          In non-static methods, static methods or variables can be called.
                                          The this and super keywords cannot be used in static methods.
                        The role of static code blocks
                                          : used to initialize static member variables

4. In the java language, what tool is used to generate program documentation according to a certain format?

A. javac
B. javah
C. javadoc

D. jar

Parse :

jar combines many files into a jar file
javac compiles
javadoc It extracts annotations such as classes, methods, members and so on from the program source code to form an API help document that matches the source code.

javah converts JNI methods declared by java code into C\C++ header files. For JNI, please refer to Chapter 12 of Volume 2 of Java Core Technology

5丶When is the text “Hi there”displayed?

public class StaticTest
{
    static
    {
        System.out.println(“Hi there”);
    }
 
    public void print()
    {
        System.out.println(“Hello”);
    }
 
    public static void main(String args[])
    {
        StaticTest st1 = new StaticTest();
        st1.print();
        StaticTest st2 = new StaticTest();
        st2.print();
    }

}

A. Never.
B. Each time a new object of type StaticTest is created.
C. Once when the class is loaded into the Java virtual machine.

D. Only when the main() method is executed.

Resolution : Static code blocks are loaded as classes are loaded and executed only once

6. Which of the following descriptions about the java memory model is wrong?

A. JMM provides memory visibility guarantees for java programmers by controlling the interaction between main memory and each thread's local memory
B. "synchronized" - guarantees that the value of main memory is synchronized to working memory at the beginning of a block, At the end of the block, the variable is synchronized back to main memory
C. "volatile" - guarantees that the modified variable will be updated with the main memory before reading or writing to the variable.

D. If a thread constructs an immutable object (the object only contains final fields), it is guaranteed that the object is correctly viewed by other threads

Analysis : For volatile-modified variables, the jvm virtual machine only guarantees that the value loaded from the main memory to the thread's working memory is up-to-date

7. Which of the following statements about the transaction propagation characteristics of SPRING is wrong?

A. PROPAGATION_SUPPORTS: support the current transaction, if there is no current transaction, execute it in a non-transactional way
B. PROPAGATION_REQUIRED: support the current transaction, if there is no current transaction, throw an exception
C. PROPAGATION_REQUIRES_NEW: create a new transaction, if there is a current transaction, put the current transaction transaction pending

D. PROPAGATION_NESTED: Support the current transaction, add a Savepoint point, commit or roll back synchronously with the current transaction

Parse :


8. Which of the following situations can terminate the running of the current thread?

A. When a high-priority thread enters the ready state
B. When the thread calls the sleep() method
C. When a new thread is created

D. When an exception is thrown

Analysis : When an exception occurs in the program, the capture will not terminate; if an exception is not captured or an exception is thrown, it will terminate

9. Which of the following descriptions about JAVA swing is wrong?

A. Swing is a Java-based cross-platform MVC framework. Use single-threaded mode.
B. Swing is a newly developed package to solve the problems of AWT. It is based on AWT .
C. Swing optimizes AWT and runs faster than AWT

D. Swing is a component-based framework, all components are inherited from the javax.swing.JComponent class

Analysis : Swing is a new graphical interface system built on the basis of AWT. It provides all the functions that AWT can provide, and greatly expands the functions of AWT with pure Java code. AWT is a C/C++ program based on native methods, and its running speed is relatively fast; Swing is a Java program based on AWT, and its running speed is relatively slow.

10. Which of the following belongs to the java packaging class?

A. String
B. Long
C. Character

D. Short

Analysis : Java is object-oriented, but the basic data types in the Java language are not object-oriented. In order to solve this problem, a corresponding wrapper class is designed. Wrapper classes are for primitive types.


Note: The above questions are all from the java special exercise in Niuke.com: https://www.nowcoder.com/6418438

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324377662&siteId=291194637