Java Interview Guide

Source: Internet
Author: User

1. Java Basics

1) Java value type and Object Type

 boolean,int,float,double,char,byte,short,long

2) advantages and principles of garbage collection

Most garbage collection algorithms use the root set concept; the so-called root set refers to the collection of referenced variables (including local variables, parameters, and class variables) that can be accessed by Java programs that are being executed ), the program can use reference variables to access object attributes and call object methods. The first choice of garbage collection is to determine which are reachable and which are inaccessible from the root, and the objects reachable from the root set are all active objects, which cannot be recycled as garbage, this also includes objects indirectly accessible from the root set. Objects that cannot be reached through any path in the root SET meet the garbage collection conditions and should be recycled.

4) What is the difference between Error and Exception?

An Error indicates a system-level Error or an exception that the program does not need to handle. It is an internal Error or hardware problem in the java Runtime Environment, for example, insufficient memory resources. For this Error, the program is basically powerless and has no choice but to quit.
Exception (Violation) indicates an Exception that needs to be captured or processed by a program. It processes general problems caused by flaws in program design or external input, is required by the program.

5) in java, a class is declared as the final type. What does it mean?

Indicates that the class cannot be inherited. It is a top-level class.

6) differences between Overload and Override. Can the Overloaded method change the type of the returned value?

Overriding and Overloading are different manifestations of Java polymorphism. Overriding is a manifestation of the polymorphism between the parent class and the Child class, and Overloading is a manifestation of the polymorphism in a class. If a subclass defines a method with the same name and parameter as its parent class, we say this method is overwritten ). When a subclass object uses this method, it calls the definition in the subclass. For it, the definition in the parent class is "blocked. If multiple methods with the same name are defined in a class, they may have different numbers of parameters or different parameter types, it is called Overloading ). The Overloaded method can change the type of the returned value.

7) the elements in the Set cannot be repeated. How can we identify whether the elements are repeated or not? Is = or equals () used ()? What are their differences?

The elements in the Set cannot be repeated, so the iterator () method is used to identify whether the elements are repeated or not. Equals () is used to determine whether two sets are equal.

The equals () and = Methods Determine whether the reference value points to the same object equals () is overwritten in the class, in order to return the true value when the content and type of the two separated objects match.

8) What is the difference between abstract class and interface?

The class that declares a method rather than implementing it is called abstract class. It is used to create a class that reflects some basic behaviors and declare a method for this class, however, this class cannot be implemented in this class. You cannot create an abstract instance. However, you can create a variable whose type is an abstract class and point it to an instance of a specific subclass. Abstract constructors or abstract static methods are not allowed. The subclasses of Abstract classes provide implementation for all Abstract methods in their parent classes. Otherwise, they are also Abstract classes. Instead, implement this method in the subclass. Other classes that know their behavior can implement these methods in the class.

An interface is a variant of an abstract class. All methods in the interface are abstract. Multi-inheritance can be achieved by implementing such an interface. All methods in the interface are abstract, and none of them have a program body. The interface can only define static final member variables. The implementation of an interface is similar to that of a subclass, except that the implementation class cannot inherit behaviors from the interface definition. When a class implements a special interface, it defines (to be given by the program body) all the methods of this interface. Then, it can call the interface method on any object that implements the interface class. Because there is an abstract class, it allows the interface name as the type of the referenced variable. Normally, dynamic Association editing will take effect. The reference can be converted to the interface type or from the interface type. The instanceof operator can be used to determine whether the class of an object implements the interface.

9) How to Implement Multi-inheritance in Java?

Implemented through internal classes. The internal classes in the Child classes inherit the parent classes to be inherited, and the internal class methods are used in the child classes.

10) differences between Java 1.4, 1.5, and 1.6

11) What is the difference between ArrayList and Vector? What is the difference between HashMap and Hashtable?

ArrayList and Vector are mainly used in two aspects.

1. Synchronization: the Vector is thread-safe, that is, synchronous, while the ArrayList is not secure or synchronous

2. Data growth: When we need to increase, the Vector grows to the original training by default, while the ArrayList is half of the original growth.

HashMap and HashTable are mainly used in three aspects.

I. Historical Reasons: Hashtable is based on the obsolete Dictionary class, And HashMap is an implementation of the Map interface introduced by Java 1.2.

2. Synchronization: Hashtable is thread-safe, that is, synchronous, while HashMap is not secure or synchronous.

3. value: Only HashMap allows you to use a null value as the key or value of a table entry.

12) How does JVM load class files?

Class from loading to releasing: Loading, verification, preparation, parsing, initialization, use, and uninstallation. Verify, prepare, and parse the connection.

13) Check for Java memory overflow?

Java. lang. OutOfMemoryError: The PermGen space loads too many classes.

Java. lang. OutOfMemoryError: Java heap space

14) What is the size of each value type in bytes?

15) categories referenced in Java

Strong references, soft references (SoftReference implementation, secondary recovery before memory overflow), weak references (WeakReference implementation, associated objects survive until next garbage collection), and virtual references

2 Multithreading

1) Please state the thread synchronization method you know

2) sharing between threads

3) thread synchronization

3 memory problems

4. Spring framework

1) IOC usage principle

2) How AOP works

3) Use Cases of AOP

4) how to configure the IOC configuration?

5) IOC type

6) Transaction Level

To solve the three defects between transactions, an isolation relationship must be established between transactions to ensure transaction integrity.

ISOLATION_DEFAULT
Use the default database isolation level

ISOLATION_COMMITTED
Allows reading updates submitted by other concurrent transactions (against dirty reads)

ISOLATION_READ_UNCOMMITTED

When you allow reading updates not submitted by other concurrent transactions, three defects may occur between transactions. This is the fastest isolation level, but its isolation level is also the lowest.

ISOLATION_REPEATABLE_READ

Unless the transaction has modified the data, it is required that the transaction read data repeatedly multiple times must be the same (this dirty read is prevented and cannot be repeated)

ISOLATION_SERIALIZABLE

This is the highest isolation level. It can prevent such problems as dirty reads, non-repeated reads, and Phantom reads. However, because of its full locking of encroached data records, it affects the transaction performance, become the most slow in isolation.

5. Hibernate framework

1) Transaction type

2) lazy loading

3) entity status

Instantaneous: after a NEW object is created, it does not establish a relationship with the Hibernate Session, nor has it manually assigned a value to the persistence identifier of the object. This entity update does not affect the database.

Persistence: when an object creates a link with the Hibernate Session and obtains the persistence identifier, it exists within the Hibernate Session lifecycle. At this time, any attribute changes to the object will directly affect the update of the corresponding field of a record in the database.

Unmanageable: when an object creates a link with a Hibernate Session and obtains a persistent identifier, and the lifecycle of the Hibernate Session ends, the persistence identifier of the object is not changed. Any modification to any attribute of the object is not reflected in the database in a timely manner.

4) Session

Enable Session: Enable Session will not get the Connection immediately, but will get the Connection only when the database needs to be connected for update or query. If a Connection pool is set, the Connection is obtained from the Connection pool. When the Session is closed, if a Connection pool is set, the Connection is returned to the Connection pool, rather than directly closing the Connection.

Storage: through the Session, you can add, delete, and update databases. After saving (), the database is not updated immediately, but is stored in the commit () of Transaction () the database will be updated later.

Get: get () and load (). The get method first queries the session cache. If not, It queries the second-level cache and then the database. Instead, it first queries the session cache when the load method is created, if no proxy is created, the second-level cache and database are queried only when data is actually used. If the object is NULL, get () returns NULL, and load () returns a proxy object. When a specific attribute is used, ObjectNotFoundException is reported if it is not found in the query database.

Delete: delete ();

Update:

Merge: merge ();

5) status transition

Create an object with new. These objects have no relationship with the database and do not correspond to any data in the database. The Persistent object becomes Transient by calling the delete () method, converts a Detached object to a Transient (instantaneous)

When the object corresponds to the data in the database and is associated with the Session instance, and the Session instance has not been closed, it is in the Persistent state. For example, after an object in the Transient state is saved to the database using the save () method of the Session, the object becomes in the persistent state.

Objects in the Detached status correspond to specific data in the database but are not managed by the Session instance. For example, after data is queried and encapsulated as objects using the load () and get () methods, when the Session instance is closed, the object changes from Persistent to Detached.

6) Cache

The temporary container in the memory of the database. The data read from the database will have a temporary copy in the cache. When you query a data, the system first looks for the corresponding copy in the cache. If yes, the system returns data directly without connecting to the database for query. Only when no data is found in the cache, to query data from the database. By caching, the efficiency of Data Reading by applications can be improved.

7) Hibernate proxy object

Objects loaded using load () are proxy objects. The proxy object is a subclass of the query object. Data Query is performed only when specific attributes are used. Hibernate uses asm. jar and cglig. Modify the bytecode of A Class Object in the memory. If the modified bytecode complies with the Class rule, a proxy object can be generated.

8) the Hibernate Domain object cannot be fianl.

No. It is a proxy object.

6 Hadoop framework

7. Design Mode

8. Java WEB

1) What are request forwarding and redirection in JSP?

2) Servlet lifecycle?

9 database knowledge

1) database locks

Shared lock (S lock ):

If transaction T adds A shared lock to data A, other transactions can only add A shared lock to data A and cannot apply exclusive locks. Transactions authorized to share locks can only read data and cannot modify data.

Exclusive lock (X lock ):

If transaction T adds an exclusive lock to data a, other transactions cannot block aplus any type. Transactions authorized to exclusive locks can read and modify data.

2) data inconsistency types: Modify lost data, read "dirty" Data, do not read repeatedly, and generate Ghost data

2) temporary table

3) Transaction type

Read Uncommited)

Read Commited: Read committed data (repeated Read is not allowed, phantom Read)

Repeatable Read: Repeatable Read (phantom Read may occur)

Serializable: Serializable

 

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.