Java exercises and java exercises

Source: Internet
Author: User

Java exercises and java exercises
Java exercise

1,

Dependency injection and control inversion are the same concept:

Dependency injection and control inversion are different descriptions of the same thing. In one aspect, they are described differently. Dependency injection is described from the application perspective. Dependency injection can be described as a complete point: the application depends on the container to create and inject the external resources required by it; the control inversion is described from the container perspective. The complete description is: The container controls the application, and the container reversely injects the external resources required by the application to the application.

 

2,

C
When the load method is used to obtain an object, hibernate will use the delayed loading mechanism to load this object, that is, when we use session. when the load () method is used to load an object, no SQL statement is issued. The current object is actually a proxy object, this proxy object only saves the id value of the object. Only when we want to use this object to obtain other attributes will the SQL statement be issued, query our objects from the database.
Compared with the load delay loading method, get is much more direct, when we use session. when the get () method is used to obtain an object, no matter whether this object is used, an SQL statement is issued to query the object from the database.

 

1. Implementation of Hibernate2 delayed loading: a) object B) Collection)
2. Hibernate3 provides the property's delayed Loading Function
When Hibernate queries data, the data does not exist in the memory. When the program actually operates on the data, the object exists in the memory, and the loading is delayed, it saves the server memory overhead and improves the server performance.

An> is a mainstream persistence framework based on JDBC and an excellent ORM implementation. He greatly simplifies the coding of the DAO layer.
3. hibernate uses the Java reflection mechanism instead of the bytecode enhancement program to achieve transparency.
4. hibernate has excellent performance because it is a lightweight framework. The flexibility of ing is excellent. It supports various relational databases, from one-to-one to many-to-many complex relationships.

 

 

3,

It is recommended that you take a look at this blog to get started easily: http://blog.csdn.net/sivyer123/article/details/17139443simply put, java heap memory is divided into two parts: permantspace (persistent band. Persistent tapes are mainly used to store static data, such as Java Class and Method. They have little to do with Java objects to be collected by the garbage collector. Heapspace is divided into the Young and the old with the Young generation of garbage collection called Young GC, the old generation of garbage collection called Full GC. Objects that are still alive after N (configurable) garbage collection in the young generation will be copied to the old generation. Therefore, it can be considered that the old generation stores some objects with long lifecycles due to the overflow of the old generation, including string processing for tens of thousands of times, creating tens of millions of objects, and applying for hundreds of M in a piece of code. even G memory, both the persistent overflow cause of option a B D dynamically loads A large number of Java classes, leading to overflow 4. The above methods are policies to solve the hash fill conflict, but in java. util. in HashMap, the link address method is used to resolve conflicts. Of course, using the link address method will reduce the get efficiency from o (1) to o (n). Therefore, in Java 8, the Balance Tree is used to improve the efficiency. Reference: two common methods for http://blog.csdn.net/cpcpcp123/article/details/52744331 to solve hash conflicts are: open address method and link address method.
Open site method: when a conflict occurs, a probe (or probe) technique is used to form a probe (TEST) sequence in the scattered list. Search by unit along the sequence until a given keyword is found or an open address is reached (that is, the address unit is empty, when exploring an open address, you can save the address unit of the new node to be inserted ). When an open address is found, no keyword is found in the table, that is, the search fails. Link address method: link all nodes with synonyms in the same single-link table. If the length of the selected hash is m, you can define the hash as a number group of pointers consisting of m head pointers T [M-1]. All nodes with the hash address I are inserted into a single-chain table with the T [I] As the header pointer. The initial values of each component in T should be null pointers. 5. Answer: The class name declared as public by B must be the same as the file name. The default permission can be different and the class name of the internal class is generally different from the file name: A file can have multiple classes. If there is no public class, it can be the same as any class name. If there is a public class, the file name must be the same as this class name, because a file can only have one public class. If there is only one class in the file, the file name must be the same as the class name. 6,

 

 

Ceil: the nearest integer between x and x. Floor: the nearest integer between floor and x.

 

 

7,

 

When an object is assigned A value, for example, A = B, it just points the address of object A to the address of object B. In fact, the object has only one 8. Answer: form parameters can be considered as local variable. Parameters are the same as local variables. It only works in the method, and is only used in the method. It is not visible outside the method. B: Only final modifiers can be used for formal parameters. Any other modifiers will cause compiler errors. However, this modifier also has certain limitations, that is, the parameter cannot be modified in the method. However, in general, the final parameter is not required for a method. Only in special cases is the internal class of the method. If the internal class in a method uses the parameters or local variables of this method, the parameter or local variable should be final. C: the value of the form parameter is changed according to the caller during the call. The real parameter uses its own value to change the value of the form parameter (the pointer and reference are all in this column), that is, the real parameter is passed. D: The parameter list of the method specifies the information to be passed to the method, in the form of objects. Therefore, you must specify the type and name of each object in the parameter list. If you want to transfer any object in JAVA, what is passed here is actually a reference, and the reference type must be correct. -- Thinking in JAVA
A
Formal parameters are the parameters set during function definition. For example, in the int min (int x, int y, int z) of the function header, x, y, and z are the form parameters. The actual parameter is the actual parameter used to call the function.
C: What is actually passed is the real parameter D: The parameter can be an object, and the reference is passed when the object is passed. b: Only final modifiers can be used for formal parameters. Any other modifiers will cause compiler errors. However, this modifier also has certain limitations, that is, the parameter cannot be modified in the method. However, in general, the final parameter is not required for a method. Only in special cases is the internal class of the method.

If the internal class in a method uses the parameters or local variables of this method, the parameter or local variable should be final.

 

9,

Answer: B a, CopyOnWriteArrayList is suitable for concurrent scenarios where less reads and more are written. B. ReadWriteLock is the read/write lock. It requires that the write and write operations be mutually exclusive, and the read and write operations are mutually exclusive, concurrent execution can be performed between read and read. The efficiency can be improved when reading and writing less data. C. ConcurrentHashMap is a synchronized HashMap, which locks read and write data. volatile only ensures the visibility of multi-thread operations and does not guarantee atomicity.

 

 

10,

 

The factory has been injected here

<! -- Configure the Transaction Manager --> <property name = "transactionManager"> <! -- Configure transaction properties --> <property name = "transactionAttributes"> <props> declarative transaction management is built on AOP. The essence is to intercept the methods before and after, and then create or add a transaction before the target method starts, submit or roll back the transaction according to the execution situation after the target method is executed. The biggest advantage of declarative transactions is that you do not need to manage transactions by programming, so that you do not need to add the transaction management code in the business logic code, you only need to declare the relevant transaction rules in the configuration file (or by using the @ Transactional annotation) to apply the transaction rules to the business logic.

 

11,

 

The control expression after a Dswitch statement can only be short, char, int, long integer, or enumeration type. It cannot be float, double, or boolean. The String type is supported at the beginning of Java 7..

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.