the elements in Set cannot be duplicated , So what is the way to distinguish between duplicates or not? is to use == or is equals ()? What difference do they have ? ? with contains to distinguish whether there are duplicate objects. Or not.
The Hashcode method is called first when comparing, and if it is not the same, the proof is not equal.
If the same, then call the Equals method, if the Equals method is the same, proving equal, not identical, proving unequal.
= =: Mainly used in basic data types and references
Equals: is primarily a comparison of object or object references.
Whether a collection contains an element is judged by the contains.
What is the difference between & and &&?
&: With: Left if False to the right is also executed.
&&: Short circuit with, left if false to right not executed.
final, finally, finalize the difference?
Final is used to declare properties, methods, and classes, respectively, that the property is immutable, that the method is not overridden, and that the class is not inheritable.
Finally is part of the exception-handling statement structure, which indicates that it is always executed.
Finalize is a method of the object class that, when executed by the garbage collector, calls this method of the reclaimed object, and can override this method to provide garbage collection of other resource recycles, such as closing the file.
when do you use assert?
Assertion (assertion) is a common debugging method in software development, which is supported in many development languages. In the implementation, assertion is a statement in the program, which checks a Boolean expression, a correct program must ensure that the value of the Boolean expression is true, if the value is False, the program is already in an incorrect state, The system will give a warning or exit. In general, assertion is used to ensure the most basic and critical correctness of the program. Assertion inspection is usually turned on during development and testing. To improve performance, the assertion check is usually turned off after the software is released.
There is a return statement in the try {} , then immediately following the try the code in the finally {} will not be executed , when executed , in before or after the return ?
Executes before the return.
There are several types of streams in Java? The JDK provides some abstract classes for inheritance for each type of stream, tell me what classes they are.
Byte stream, character stream. The byte stream inherits from the InputStream OutputStream, and the character stream inherits from reader Writer. There are many other flows in the java.io package, low-level flows and laminar flow, high-rise flow is mainly to improve performance and ease of use.
start a thread with run () or start ()?
Starting a thread is calling the start () method, starting the thread and calling the Run method.
There are several ways to implement multithreading, what is it? How are there several implementations of synchronization ? What keyword modifies the synchronization method? How are the Stop () and suspend () methods not recommended?
There are two ways to implement multithreading, namely, inheriting the thread class and implementing the Runnable interface.
There are two implementations of synchronization, namely Synchronized,wait and notify
Against the use of Stop () is because it is unsafe. It unlocks all locks acquired by the thread, and if the object is in an incoherent state, then other threads can examine and modify them in that state. The result is hard to check out the real problem. The suspend () method is prone to deadlocks. When calling suspend (), the target line routines stops, but still holds the lock that was acquired before. At this point, no other thread can access the locked resource unless the thread that is "suspended" resumes running. For any thread, if they want to restore the target thread while trying to use any of the locked resources, it will cause a deadlock. So instead of using suspend (), you should place a flag in your own thread class that indicates whether the thread should be active or suspended. If the flag indicates that the thread should hang, use wait () to enter the wait state. If the flag indicates that the thread should be resumed, restart the thread with a notify ().
What is the difference between sleep () and wait ()?
-Have different objects
-wait can release object locks, sleep preserves object locks
-wait can be any object to invoke, and sleep can only be called when the thread
-wait can be awakened by notify at any time, sleep can only wait for a set time to wake up naturally, otherwise an exception will be thrown
-wait must be called in a synchronous method or in a synchronous block, and sleep can be called at any location
describe your understanding of statement,preparedstatement,callablestatement
The statement is used to execute a static SQL statement and return the object it produces, determining SQL at execution time.
P reparedstatement An object that represents a precompiled SQL statement. The SQL statements are precompiled and stored in the PreparedStatement object. You can then use this object to efficiently execute the statement multiple times, and you can pass arguments to determine SQL when you get the PreparedStatement object.
callablestatement The interface used to execute SQL stored procedures. If there is an output parameter to register the description is the output parameter.
JDBC Access to Oracle Database
Class.forName ("Oracle.jdbc.driver.OracleDriver");
Connection con=drivermanager.openconnection ("Jdbc:oracle:thin: @localhost: 1521:database", "UserName", "Password")
Review of Java Knowledge (III.)