Java Face question 02

Source: Internet
Author: User
Tags finally block

First, the choice question

The encoding format used internally by 1.java is C, Unicode, which is used uniformly within the JVM, using Unicode representation.

2.

Public class Threads2 Implements runnable{
Public void run () {
System. Out.println ("run.");
throw New RuntimeException ("problem");
}
Public static void Main (String[] args) {
thread t = new thread (new Threads2 ());
T.start ();
System. Out.println ("End of Method.");
}
}

The running result is (D, E)

D, End of Method.run.java.lang.RuntimeException:Problem

E, Run.java.lang.RuntimeException:Problem End of method

3.

Public class SimpleCalc {
public int value;
Public void Calculate () {
Value + = 7;
}
}

Public classMultiCalcextendsSimpleCalc{
Public voidCalculate () {
Value-= 3;
}
Public voidCalculateintMultiplier) {
Calculate ();
Super. Calculate ();
Value *= multiplier;
}
Public static voidMainString[] args) {
MultiCalcCalculator =NewMultiCalc ();
Calculator.calculate (2);
System. OUT.PRINTLN ("Value is:" +calculator.value);
}
}

The result of the operation is (A)

A, Value Is:8

4. In MVC, the role of JavaBean is the encapsulation of business data, MVC is the abbreviation of Model View controller, JSP corresponds to the view layer, mainly for the display of the page, The servlet corresponds to the controller layer: the middle tier is responsible for data access (invoking the service Interface) and the page jumps (jumps to the JSP page you want to display), the JavaBean corresponds to the model layer, is the data encapsulation, processing data

5. Description of the configuration meaning of the following spring declaration of Things is wrong (c)

abstract= "true"class= " Org.springframework.transaction.interceptor.TransactionProxyFactoryBean ">    <property name=" TransactionManager "ref=" Mytransactionmanager "/><property name=" transactionattributes ">       <props >        <prop key= "get*" >PROPAGATION_REQUIRED,readOnly</prop>         <prop key= "*" >propagation_ required</prop>     </props></property> </bean>

A. Define a configuration template for declaring things

B. Use read-only things for Get methods

C, lack of sessionfactory attribute injection

D. Configure the agent for the bean that needs to be managed, referencing this configuration template through the parent. The code is as follows:

<bean id= "petbiz" parent= "Txproxytemplate" >

<property name= "target" ref= "Pettarget"/>

</bean>

This has been injected into the factory <property name= "TransactionManager" ref= "Mytransactionmanager"/>

The interfaces in the 6.Hibernate API can be divided into the following categories:

A, the interface that provides the operation to access the database, including session, transaction, query interface

B, the interface for configuring hibernate, Configuration

C, the indirect interface, allows the application to accept Hibernate internal events will be, and make relevant responses, including interceptor, lifecycle, validatable

D. Interfaces for extending hibernate functions, such as usertype, Compositeusertype, Identifiergenerator interfaces

Answer: ABCD

7. The atomicity of things means:

A, all the actions included in the thing are either done or not done

B. Once a thing is submitted, the change to the database is permanent (persistent)

C, the operation of a thing inside and the data used are isolated from other things (isolation)

D, things must be the database from one consistent state to another consistency state (consistency)

Answer: A

Second, simple answer

1.List, MAP, set three interfaces, access elements are, what are the characteristics of each?

A: Both list and set are collections of single-column elements, and they have a common parent interface collection

Duplicate elements are not allowed in the set: The Add method has a Boolean return value, and when the collection does not have an element, the Add method can successfully join the element, and returns True when the collection contains an element equal to the equals of an element, at which point the Add method cannot join the element , which returns false.

Take the element: no specific to take the first few, can only take the iterator interface to get all the elements, in each of the elements traversed

The list represents a sequential collection of elements: When the Add (object) method is called multiple times, each object that is added is sorted in first served order, or in the queue, that is, by calling the Add (int index,object) method, you can specify where the current object is stored in the collection.

Take element: Method 1:iterator interface Get all, traverse each element individually

Method 2: Call Get (index i) to explicitly say take the first few.

Map is a two-column collection, stored with the Put method: put (obj key,obj value), each time you store, to save a pair of Key/value, cannot store duplicate key, this repeating rule is equal to equals.

Take element: Use the Get (Object key) method to obtain the corresponding value according to key, you can also get all the key collection, you can also get all the value of the collection, you can also get a combination of key and value of the Map.entry object collection.

Lists hold elements in a particular order and can repeat elements. Set cannot have duplicate elements, internal ordering. Map holds the Key-value value, and value can be multivalued.

2. List the sorting methods you know, and write out the pseudo-code for quick sorting.

A: Sort by: Insert sort (direct insert sort, hill sort), swap sort (bubble sort, quick sort), select sort (Direct select sort, heap sort), merge sort, assign sort (box sort, base sort)

Quick Sort Pseudo-code:

Sort a[0:n-1 by using the Quick Sort method

Select an element from a[0:n-1] as the middle, the element is the Fulcrum

Divide the remaining elements into two segments left and right, so that the elements are less than or equal to the fulcrum, and the elements in right are greater than or equal to the fulcrum

Recursively sort left by using the Quick Sort method

Recursively sort right by using the Quick Sort method

The resulting result is left+middle+right

Pseudo code:

Quicksort (A, Lo,hi)

If Lo

P=partition (A,lo,hi)

Quicksort (a,lo,p-1)

Quicksort (A,p+1,hi)

Partition (A,lo,hi)

Pivot=a[hi]

I=lo//place for swapping

For j = Lo to Hi-1

If A[j]<=pivot

Swap a[i] with A[J]

I=i+1

Swap a[i] with A[hi]

return I

3. Talk about the difference between final,finally,finalize?

Answer: (1) Final: modifier (keyword), if a class is declared final, it means that he can no longer derive a new subclass and cannot be inherited as a parent class. Therefore, a class cannot be declared as abstract and final. Declaring variables or methods as final ensures that they are changed in the middle of use. A variable declared as final must be given an initial value at the time of declaration, and can only be read in subsequent references and cannot be modified. A method that is declared final can also be used only and cannot be overloaded.

(2) Finally: Provides a finally fast to perform any cleanup operations during exception handling. If an exception is thrown, the matching catch clause executes, and the control enters the finally block, if any.

(3) Finalize: Method name. Java technology allows the use of the Finalize () method to do the necessary cleanup before the garbage collector clears objects from memory. This method is called by the garbage collector to make sure that the object is not referenced by this object. He is defined in the object class, so all classes inherit from him, and the subclass overrides the Finalize () method to organize system resources or perform other cleanup work. The Finalize () method is called on the object before the object is deleted by the garbage collector.

One, the nature of different

1, final as the key word

2, Finalize () as a method

3, finally is the block flag. Used in a try statement

Second, the role

1. Final is the keyword used to represent a constant, and the final identified keyword is stored in a constant pool (here final

The specific usage of the constants will be described below)

2. The Finalize () method is defined in object to be invoked by the JVM when the object "disappears" for garbage collection of objects, similar to a destructor in C + +, which frees up resources used by objects (such as i/0 operations) when the user is customized;
3, finally{} is used to identify the code block, with try{}, regardless of whether the code in the try is executed or not finished (this means that there is an exception), the code block of the program must be done.

Java Face question 02

Related Article

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.