Java daily exercises, make progress a little every day (44)


Thanks for your love, we make progress together every day! (check the blank space with the mouse to see the answer)

1. The class used to represent text boxes in AWT is ()

Correct answer: a





A. Textfield represents a text box
B. Menu represents a drop-down menu
C. Label represents a label
D. List represents a list box

2. What are the types and values of the following expressions? (note integer division) ()

-5 + 1/4 + 2*-3 + 5.0

Correct answer: D

int -3

int -4

double -5.5

double -6.0

In Java, 5.0 is a double type, so the data type of the result is double. Because 1 / 4 of the result is 0, the result is – 6.0

3. The output after the execution of the following code segment is

public class Test {

public static void main(String args[]) {

int x = -5;

int y = -12;

System.out.println(y % x);



Correct answer: D





Whether it is positive or negative, there is a divisor = quotient in the remainder operation × Divisor + remainder, so – 12 = 2 × (- 5) + – 2), – 12 is the divisor, – 5 is the divisor, 2 is the quotient, and the remainder is – 2.

4. The cross platform feature of Java means that its source code can run on multiple platforms. ()

Correct answer: B



Java’s cross platform feature is due to the existence of the JVM, which can execute Class bytecode file, not Java source code

5. Which area of the process () is the method usually stored in

Correct answer: D

Heap area

Stack area

Global area

Method area

The data area of Java runtime includes: (the first two are shared by threads)
1. The method area stores class information, constants, static variables, code compiled by the real-time compiler and other data that have been loaded by the virtual machine
2. The heap stores object instances, where almost all object instances allocate memory
3. Virtual machine stack (VM stack) describes the memory model of Java method execution: each method will create a stack frame (basic data structure of method runtime) to store local variable table, operand stack, dynamic connection, method exit and other information
4. The native method stack is similar to the virtual machine stack, but it serves the native methods used by the virtual machine. (some virtual machines, such as sun hotspot virtual machine, directly combine the local method stack and virtual machine stack)
5. The program counter register can be regarded as the identifier of the line number of the bytecode executed by the current thread

6. What communication protocol does the default RMI use?

Correct answer: C





RMI adopts TCP / IP protocol
RMI (remote method invocation) remote method invocation is a communication mechanism for computers to communicate with each other by using remote objects.
TCP / IP is the main means of remote communication

7. In J2EE, when the HTTP request from the client is delegated to the servlet, the () method of httpservlet will be called

Correct answer: a





First, the servlet encapsulates the HTTP request information through the httprequest object, and then the servlet container calls the service method of httpservlet, which will call the specific method according to the user’s request. If the request method is get, the doget method will be called. If the request method is post, the dopost method will be called. After execution, the corresponding data will be generated through the httpresponses object and the corresponding customer’s request. Generally, the doget method and dopost method will be rewritten

8. String STR = new string (“ABC”). How is “ABC” allocated in memory?

Correct answer: a C



String constant area


When you new string (“ABC”), you will first generate an ABC object in the string constant area, and then allocate space in the heap when you new string(), and then copy an ABC in the string constant area to a string in the heap. Therefore, ABC should be in the heap and the character string constant area

9. In the Java language, which of the following questions about character set encoding and internationalization (I18N) are correct?

Correct answer: C D

Each Chinese character occupies 2 bytes and each English character occupies 1 byte

Assuming that the characters in the database are encoded in GBK, the web page displaying the database data must also be encoded in GBK.

The char type of Java usually saves a character in the form of utf-16 big endian.

A common way to implement international applications is to use the resourcebundle class

A is obviously wrong. Java always adopts Unicode coding. Each character, whether Chinese or English, occupies 2 bytes.
B is also incorrect. Different codes can be converted. The general process is as follows:
Decompose the string s into a byte array in its own encoding mode, and then re encode the byte array into a string in the encoding mode you want to output.
Example: string newutf8str = new string (oldgbkstr. GetBytes (“GBK”), “utf8”);
C is correct. Utf-16 is usually used to save a character in Java virtual machine
D is also correct. Resourcebundle can selectively read the properties file with the suffix corresponding to local according to different local to achieve the purpose of internationalization.

10. About volatile keyword, the following description is incorrect?

Correct answer: B D

For variables decorated with volatile, each update is immediately visible to other threads.

Operations on volatile variables are atomic.

Operations on volatile variables do not cause blocking.

Without relying on other locking mechanisms, counters in multithreaded environment can be implemented by volatile.

The so-called volatile measure is
1. Every time you get a value from memory, you don’t get a value from the cache. This ensures that shared variables decorated with volatile are visible to other threads every time they are updated.
2. Volatile ensures the immediate visibility of other threads, so atomicity is not guaranteed.
3. Because sometimes the operation on volatile will not be saved, the description will not cause blocking. Not available with counters in multithreaded environments.
In addition, threads rarely cause blocking problems like volatile variables.

Answer summary:

1. Correct answer: a

2. Correct answer: D

3. Correct answer: D

4. Correct answer: B

5. Correct answer: D

6. Correct answer: C

7. Correct answer: a

8. Correct answer: a C

9. Correct answer: C D

10. Correct answer: B D


That’s all for this article. I hope it can help you and pay more attention to developeppaer!

Recommended Today

Vue2 technology finishing 3 – Advanced chapter – update completed

3. Advanced chapter preface Links to basic chapters: Link to component development: 3.1. Custom events of components 3.1.1. Binding custom events There are two implementation methods here: one is to use v-on with vuecomponent$ Emit implementation [PS: this method is a little similar to passing from child to parent]; The other is to use ref […]