The difference between 1,break,continue,return
(1) Break jumps out of the current loop body
(2) Continue skip the code behind the current loop body continue and proceed to the next loop
(3) Return and loop do not matter, just jump out of the function
The native method of 2,java
The native method is called a local method. The keyword "native" is declared in the Java source program and does not provide a function body.
Its implementation is written in a separate file using the C + + language, and the rules are written in accordance with the Java Native Interface specification (JNI).
In the case of Jane, the callable method that is declared in Java is implemented by using C + +.
3,java the differences between abstract classes and interfaces
| Parameters |
Abstract class |
Interface |
| The default method implementation |
It can have the default method implementation |
The interface is completely abstract. There's no way to implement it at all. |
| Realize |
Subclasses use the extends keyword to inherit abstract classes. If the subclass is not an abstract class, it needs to provide an implementation of all the declared methods in the abstract class. |
Subclasses use the keyword implements to implement an interface. It needs to provide an implementation of all the declared methods in the interface |
| Constructors |
Abstract classes can have constructors |
Interfaces cannot have constructors |
| Differences from normal Java classes |
Except that you can't instantiate an abstract class, it's no different than a normal Java class. |
Interfaces are completely different types |
| Access modifiers |
Abstract methods can have public, protected, and default modifiers |
The interface method default modifier is public. You may not use other modifiers. |
| Main method |
The abstract method can have the main method and we can run it |
The interface does not have a main method, so we cannot run it. |
| Multiple inheritance |
An abstract method can inherit a class and implement multiple interfaces |
Interfaces can inherit only one or more other interfaces |
| Speed |
It's faster than the interface. |
The interface is a little bit slower because it takes time to look for methods implemented in the class. |
| Add a new method |
If you add a new method to an abstract class, you can give it a default implementation. So you don't need to change your current code. |
If you add a method to an interface, you must change the class that implements the interface.
|
4,java = =, the difference and connection between equals and Hashcode
(1) binding. when the Equals method is overridden, it is often necessary to override the Hashcode method to maintain the general contract of the hashcode method, which declares that the equality object must have an equal hash code.
(2) reason for binding. Hashtable implements a hash table, in order to successfully store and retrieve objects in the Hashtable, objects used as keys must implement hashCode methods and equals methods. Same as (1), the object must be guaranteed equal to equals, hashCode also equal. Because the hash table retrieves the object through Hashcode.
(3) Default.
= = Compares the address of the object in the JVM by default.
hashcode Default returns the storage address of the object in the JVM.
Equal compare objects, the default is to compare objects in the JVM address, with = =
5, four characteristics of database transaction
If a database claims to support transactional operations, then the database must have the following four features:
⑴ atomicity (atomicity)
Atomicity means that all the operations contained in a transaction are either all successful or fail back, which is the same concept as the previous two blogs about transactions, so the operation of a transaction must be fully applied to the database if it succeeds, and it cannot have any effect on the database if the operation fails.
⑵ Consistency (consistency)
Consistency means that a transaction must transform a database from one consistent state to another, meaning that a transaction must be in a consistent state before and after execution.
Take the transfer, assume that user A and User B both the sum of money together is 5000, then no matter how a and B transfer, transfer several times, after the end of the transaction two users of the sum should be 5000, this is the consistency of the transaction.
⑶ Isolation (Isolation)
Isolation is when multiple users concurrently access the database, such as when the same table operation, the database for each user-opened transactions, can not be disturbed by the operation of other transactions, multiple concurrent transactions to be isolated from each other.
To achieve this effect: for any two concurrent transactions T1 and T2, in the case of transaction T1, the T2 either ends before the T1 starts, or starts after the T1 ends, so that every transaction does not feel that another transaction is executing concurrently.
The isolated database on transactions provides a variety of isolation levels, which are described later.
⑷ Persistence (Durability)
Persistence refers to the fact that once a transaction is committed, changes to the data in the database are permanent, even if the database system encounters a failure, and the commit transaction is not lost.
For example, when we use the JDBC operation database, after committing the transaction method, prompt the user transaction operation completes, when our program execution completes until sees the prompt, can determine the transaction and the correct commit, even if this time the database has the problem, also must have our transaction complete execution, Doing so will cause us to see that the transaction is complete, but the database failed to perform a transaction because of a failure.
Java Interview Summary