Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the test questions for Java?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what are the written test questions in Java". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the written test questions in Java"?

The following statement is wrong about JVM memory?

A, the program counter is a relatively small memory area, which is used to indicate which line the bytecode executed by the current thread has been executed and is thread isolated.

B, virtual machine stack describes the memory model of Java method execution, which is used to store local variables, Operand stack, dynamic link, method exit and other information, and is thread isolated.

C, method area is used to store JVM loaded class information, constants, static variables, and compiler compiled code and other data, is thread isolated.

D. in principle, all objects allocate memory on the heap and are shared between threads.

Click on the blank area below to view the answer analysis!

Correct answer: C

The method zone is also a very important area in JVM. Like the heap, it is an area shared by threads. In the method area, the information of each class (including class name, method information, field information), static variables, constants, and compiled code of the compiler are stored.

The following incorrect constructions are: ()

A. the constructor of the class has the same name as the class

B. A class can have multiple constructors

C. the constructor of the class must be called when the object is instantiated

D. The constructor can be called by this class object like other methods of this class.

Click on the blank area below to view the answer analysis!

Correct answer: d

Answer analysis: constructors are used to construct object instances. The member method is used to perform a function and needs to be called by an object instance. So the order is: the constructor executes to get the object instance, and the object instance calls the member method. It is impossible to call the instance object before it is constructed.

[multiple selection] the one that implements or inherits the Collection interface is ()

A 、 Map

B 、 List

C 、 Vector

D 、 Iterator

E 、 Set

Click on the blank area below to view the answer analysis!

Correct answer: BCE

Answer analysis:

1. The Map interface in A stores objects in the form of key-value pairs (key-value), where key (key) objects cannot be repeated, value (value) objects can be repeated, and are sorted according to their own internal rules.

2. The List interface in B inherits the Collection interface, and the List interface allows duplicate objects to be stored and sorted according to the insertion order of the objects.

3. Vector in C implements the List interface, that is, the Collection interface indirectly.

4. Iterator in D, all collection classes, implement the Iterator interface, which is an interface for traversing the elements in the collection, but does not implement the Collection interface.

5. The Set interface in E inherits the Collection interface. Set API does not allow duplicate objects to be stored, and is sorted according to its own internal sorting rules.

All right, I still need to say a few more words about a little extension of the above three questions.

I. on thread isolation and thread sharing

Thread isolation in JVM includes:

Program counter:

A small piece of memory space, a bytecode line number indicator executed by a single front thread. When the bytecode interpreter works, by changing the value of this counter to select the next bytecode instruction to be executed, branch, loop, jump, exception handling, thread recovery and other basic functions need to rely on this counter to complete.

JVM virtual machine stack:

The Java method executes the memory model, which is used to store local variables, Operand stacks, dynamic links, method exits, and other information. Is thread private.

Local method stack:

To serve the Native methods used by JVM, the SunHotSpot virtual machine combines the local method stack and the JVM virtual machine stack into one. Is thread private.

Thread sharing in JVM includes:

Method area:

Used to store JVM-loaded class information, constants, static variables, even code compiled by the compiler, and other data.

Run time Pool:

Is part of the method area that stores various literals and symbolic references generated by the compiler, which will be stored in the method get runtime pool after the class is loaded. Because of its dynamic nature, the intern () method of the String class is often used.

JVM heap:

A place where all instances of objects are stored.

Cenozoic, composed of Eden Space and two pieces of Survivor of the same size

In the old generation, objects that survived multiple garbage collection were stored.

II. Reflection and Construction methods in Java

An and B have no doubt, C's words because of the reflection, there may be friends here will dig the pit. Reflection does not have a New object, but it also depends on the constructor of the class. Get the java.lang.Class object for which you want to manipulate the class. After each class is loaded, a corresponding Class object is generated for the class, and the class object can access the class in the java virtual machine.

There are three ways to get Class:

1. Call the getclass () method of an object.

For example: person person=new person (); Class cla=person.getclass () call / 2, use the class attribute of a class to get the corresponding class object of that class

For example: Class cla=Person.class

3. Use the forName () static method example of the class class

For example, class cla=Class.ForName ("com.amuxia.person")

Call its constructor. Here are several examples:

1. GetConstructor (class [] params) function:

Returns the specified public constructor of the class represented by this class object.

For example: Constructorc=cla.getConstructor (string.class,String.class,Integer.class)

2. GetConstructors function:

Returns all public constructors of the class represented by this class object.

For example: Constructor [] arrc=cla.getConstructors ()

3. GetDeclaredConstructor (class [] params) function:

Returns the specified constructor of the class represented by this class object, regardless of the access level of the constructor.

For example: Consteuctorc=cla.getDeclaredconstructor (string.class,string.class,Integer.class)

4. GetDeclaredConstructors () function:

Returns all constructors of the class represented by this class object.

For example: Constructor [] arrc=cla.getDeclaredConsteructors ()

Thank you for your reading, the above is the content of "what are the written test questions for Java". After the study of this article, I believe you have a deeper understanding of what the written test questions are for Java, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report