Java pen question brush question error Note

Source: Internet
Author: User

Which of the following is not an assignment symbol?

A, + = B, <<= C, <<<= D, >>>=

Note: + = is the first plus post-assignment symbol

<<= is left shift

>>> shows unsigned right shift, no <<< symbol

Second, ArrayList list=new ArrayList (20); How many times has the list been expanded? Answer: 0 times

Note: ArrayList has three constructors

&a:arraylist () Constructs an empty list with an initial capacity of 10;

&b:arraylist (Collection c) Constructs a list that contains the specified Collection elements, arranged in the order in which they are returned by the Collection iterator.

&c:arraylist (int initialcapacity) constructs an empty list with the specified initial capacity.

The third constructor is called, and the list with size 20 is initialized directly without an extension.

Three, the following about the difference between struts1 and struts2, describe the error is?

A:STRUTS1 requires the action class to inherit an abstract base class. Struts 2 Action class can implement an action interface

The B:struts1 Action object generates an instance for each request. Struts2 Action is a singleton mode and must be thread-safe

C:struts1 action relies on the Servlet api,struts 2 action to not rely on the container, allowing the action to be tested separately from the container

D:STRUTS1 integrates jstl,struts2 can use JSTL, but also supports OGNL

Remark: Correct answer: B

From the action class, analyze:

1.STRUTS1 requires the action class to inherit an abstract base class. A common problem with Struts1 is the use of abstract class programming instead of interfaces.
2. The Struts 2 action class can implement either an action interface or other interfaces to make the optional and custom service possible. STRUTS2 provides a actionsupport base class to implement commonly used interfaces. The action interface is not required, and any Pojo object that has an execute identity can be used as the Struts2 action object.

From servlet dependency Analysis:

3. Struts1 action relies on the servlet API because HttpServletRequest and HttpServletResponse are passed to the Execute method when an action is invoked.
4. Struts 2 Action does not depend on the container, allowing the action to be tested separately from the container. If required, the STRUTS2 action can still access the initial request and response. However, other elements reduce or eliminate the need for direct access to Httpservetrequest and HttpServletResponse.

Analysis from the action threading pattern:

5. Struts1 action is a singleton pattern and must be thread-safe because only one instance of the action handles all requests. The singleton strategy limits what Struts1 action can do, and is especially careful when developing. The action resource must be thread-safe or synchronous.
6. The Struts2 action object generates an instance for each request, so there is no thread safety issue. (In fact, the servlet container produces many objects that can be discarded for each request and does not cause performance and garbage collection issues)

Four

static String str0= "0123456789" ; static String str1= "0123456789" ; String str2=str1.substring( 5 ); String str3= new String(str2); String str4= new String(str3.toCharArray()); str0= null ;

Assume that Str0,..., STR4 post-code is read-only reference.
Java 7, based on the code above, after a FULLGC has occurred, the above code in the heap space (excluding PermGen) the number of characters reserved is (15)

Note: This is a question about the Java garbage collection mechanism

Java's garbage collection mechanism garbage collection, referred to as GC. The Java language does not require programmers to control garbage collection directly, the program's memory allocation and collection are automatically performed by the JRE in the background, and the JRE reclaims unused memory, a mechanism known as garbage collection.

Garbage collection is primarily for garbage collection, because the memory in the stack is released along with the thread. The heap area is divided into three districts: young Generation, older Generation, and permanent (Permanent Generation, which is the method area).

Young generation: Objects that are created (new) are usually placed on young (except for some objects that occupy a larger memory size), and the objects that are alive after a certain minor GC (for the memory of the younger generation) are moved to the older generation (some specific moving details are omitted).

Old generation: The younger generation moved over and some of the larger objects. Minor GC (FULLGC) is a recovery for older generations

Permanent generation: Stores the final constant, static variable, and constant pool.

SUBSTRING is actually a new,5 character; Str3 and 4 are all new, each 5 characters, and each creates an object, and the constant pool is permgen; so it should be 15 characters.

Java pen question brush question error Note

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.