Java development problem common basis Daquan

1. & and && difference?
&: Logical AND (and), both sides of the operator when the operator expressions are true, the result was a whole is true.
&&: short circuit and, if the first expression is false, the second expression will not be calculated.

2. "==" and equals method is what is the difference?
==: it represents the two variables are equal, for comparing the two basic types of data or data reference variable.
equals: the content of two independent objects for comparison is the same. Also used to compare strings equals.
== basic types, for comparing the value for the reference type is the comparison reference; equals the default case is a reference comparison, but many types of re equals method, such as String, Integer, etc. it becomes a value comparison, it generally equals the value of the comparison is equality.

With equals and == when comparing strings difference is equal to 3.
String object, if the number is == to compare two String objects memory address is the same, equals () String comparison is the same as the contents of the time, but in different programming languages the two are not the same

The difference 4.Int and integer?
Int Java is one of the basic data types 8, integer is int wrapper classes. Int type default value 0, integer default value is null, so that the difference, integer can distinguish the difference between a null value and zero.

5. overloaded and rewrite the difference?
Overload (Overload): the same function name, different parameters. Return type can be changed, the number and type of parameters.
Rewriting (Override): parent class and method names and parameters are identical.

6. The object-oriented features?
Package: The code object properties and methods into a module package, a class, i.e., to ensure excellent internal software of the base module, to achieve "high cohesion and low coupling."
Abstract: find some similarities and common place things, then classified as a class at only consider the similarities and commonalities of things. Including abstract behavior and abstract state of abstraction.
Inheritance: class conducted on the basis of already existing on the contents defined as its content, and can add new content or modify the original method is suitable for special needs.
Polymorphism: the same operation applied to different objects can have different interpretations, produce different execution result, is polymorphic, simple point that: the parent class is to use an object reference pointing to subclass. Objective: To improve the reusability of the code, solve the problem of tight coupling projects, improve scalability.
Polymorphic mechanisms: by the parent or reference variable interface or may be directed to a subclass of object class instance of the specific implementation.

7.JDK and JRE What is the difference?
JDK: Java Development Kit for short, Java Development Kit, provides a Java development environment and runtime environment.
JRE: Java Runtime Environment for short, Java runtime environment, provides the necessary environment for the Java runtime.
Specifically JDK actually contains the JRE, also contains a compiled Java source code compiler Javac, also it contains many Java program debugging and analysis tools. In short: if you need to run Java programs, simply install the JRE on it, if you need to write Java programs, you need to install JDK.

What is the role 8.final in Java?
final modified class called final class, which can not be inherited.
The final modification method can not be overridden.
final modified variable called, const must be initialized, after initialization value can not be modified.

9.String s = new String ( "syx "); created several String Object?
If common sense String pool (constant buffer) has been created "syx", it does not continue to create, at this time only creates an object new String ( "syx");
if common sense String pool, not created "syx", two objects is created, the value of an object is "syx", an object new String ( "syx").

10.JDBC operation of the seven steps of the database?
1. Load JDBC drivers:
2 provides the URL JDBC connection;
3. Create a connection to the database;
4. Create a Statement (the operation performed to create a sql);
5. SQL statement is executed;
6. The process execution result;
7. Close JDBC objects, free memory.

Common method 11.String class have those?
indexOf (): Returns the index of the specified character.
charAt (): Returns the character at the specified index.
replace (): replacement string.
trim (): removing a blank string ends.
split (): Split string, returns an array of strings after the division.
getBytes (): returns a string type byte array.
length (): returns the length of the string.
toLowerCase (): turn into lowercase string.
toUpperCase (): turn a string to uppercase characters.
substring (): string taken.
equals (): comparison string.

12. The ordinary classes and abstract classes What are the differences?
Common classes can not contain abstract methods, abstract class may contain abstract methods.
An abstract class can not be directly instantiated general class can be instantiated directly.

13. interfaces and abstract classes What is the difference?
Abstract classes: modified with abstract, abstract class can not create an instance of an object. Abstract methods must be implemented in a subclass, the method is not abstract or abstract static configuration method.
Interface: a special case, the abstract class interface method must be abstract.
The difference is:
1. An abstract class can have a constructor, no interface constructor
2. abstract class member variables can have a common interface is not common member variables.
3. An abstract class can have non-abstract common methods, the interface method must be abstract.
4. The type of abstract methods for the abstract class may be public, protected, free interface method must be public pumping type.
5. An abstract class may contain static methods, static methods can not contain an interface.
6. A class can implement multiple interfaces, but can only inherit an abstract class.
7. The interface members basic data type, default to static and final, abstract classes are not.
8. subclass of use extends to the abstract class inheritance; implements the interface must be used to implement the interface.

14.BIO, NIO, AIO What is the difference?
BIO: Block IO synchronous blocking IO, is what we usually use the traditional IO, which is characterized by simple and easy to use mode, low concurrent processing capability.
NIO: Non IO synchronous non-blocking IO, IO is the traditional upgrade, the client and the server through Channel (channel) communication, to achieve multiplexing.
AIO: Asynchronous IO is upgraded NIO, also known as NIO2, implements asynchronous non-blocking IO, event-based asynchronous IO operation and callback mechanism.

What are the common methods 15.Files?
. Files exists (): detects file path exists.
. Files createFile (): create the file.
. Files createDirectory (): Create a folder.
. Files delete (): Delete a file or directory.
. Files copy (): Copy the file.
. Files move (): move the file.
. Files size (): View the number of files.
. Files read (): read the file.
. Files write (): write to the file.

16. Compare the similarities and differences synchronized with java.util.concurrent.locks.Lock of?
The main similarities: Lock to complete all the functions synchronized achieved
major differences: Lock more accurate than synchronized thread semantics and better performance. synchronized automatically release the lock, and Lock requires the programmer must manually released and must be released in the finally clause.

17.List, the difference between Set, and Map?
List: is a collection of data stored in single, sequential storage, allowing repeat. Inherit the Collection interface.
Set: a collection of separate data storage. Inherit the Collection interface. Not allowed to repeat.
Map: storing a set of key values and a double row of such data, no data is stored sequentially, key (key) is not repeated, the value (value). It can be repeated.

18.java way to create objects What?
1. Use the new keyword
2. Create objects using reflection mechanisms:
(1) Using the newInstance method of class Class
(2) java.lang.reflect.Constructor newInstance class has a method to create the object.
3. clone: first implement Cloneable interface and implement a clone method is defined in
4. Use deserialization.

  1. In Java IO streams divided into several?
    Divided by function: input stream (input), the output stream (output).
    Divided by type: byte stream and character stream.
    The difference between a byte stream and character stream are: 8-bit byte stream transmitted at a data input and output bytes, 16-bit transmission character stream in units of characters input and output data.

20. What are the similarities and differences with the general exception runtime exception?
Java provides two main types of anomalies: abnormal runtime exception and general exceptions checked exception runtime. For the latter exception to this general, JAVA requires the programmer its catch process. So, faced with this anomaly regardless of whether we are willing, only themselves to write a lot of catch block to handle possible exceptions.
We can not deal with abnormal operation. Such abnormal taken over by the virtual machine. After a runtime exception occurs, the system will throw an exception has been to the top, has encountered handling code. After the deal with exceptions if not running, the run-time exception occurs, either thread suspend or terminate the main program.
JAVA knowledge container

  1. What are Java container?
    Java and Map Collection containers are divided into two categories, under which there are many sub-categories as follows:
    Collection
    List
    ArrayList
    LinkedList
    the Vector
    Stack
    the Set
    HashSet
    LinkedHashSet
    TreeSet
    Map
    HashMap
    LinkedHashMap
    TreeMap
    ConcurrentHashMap
    Hashtable
    difference 2.List, Set, and Map?
    List: is a collection of data stored in single, sequential storage, allowing repeat. Inherit the Collection interface.
    Set :: is stored in a separate set of data. Inherit the Collection interface. Not allowed to repeat.
    Map: storing a set of key values and a double row of such data, no data is stored sequentially, key (key) is not repeated, the value (value). It can be repeated.
    3.HashMap and Hashtable What is the difference?
    Storage: HashMap run key and value is null, and Hashtable are not allowed.
    Thread safety: Hashtable is thread-safe, while HashMap is not thread safe.
    Recommended use: you can see the class comment Hashtable, Hashtable class is reserved not recommended, recommended HashMap alternative in single-threaded environment, if you need to use multiple threads with ConcurrentHashMap instead.
  2. How do you decide to use HashMap or TreeMap?
    Map to insert, delete, locate an element such operations, HashMap is the best choice, because it is relatively HashMap insert will be faster, but if you want a key to the orderly collection of traversal, that is TreeMap better choice.
  3. HashMap talk about the realization of the principle?
    HashMap Hash-based algorithm, we store through put (key, value), get (key) to get. When an incoming key, HashMap will be calculated according to key. HashCode () the hash value, the hash value in accordance with the value stored in the bucket. When the calculated hash values are the same, we call hash conflicts, the HashMap value approach is the same hash value is stored as a linked list and red-black tree. When the number of hash conflict is relatively low, the use of a linked list or use the red-black tree.
  4. HashSet talk about the realization of the principle?
    HashSet HashMap based implementation, the underlying HashSet HashMap used to hold all the elements, so HashSet is easy to implement, HashSet related operations are basically related to directly call a method to accomplish the underlying HashMap, HashSet duplicate values are not allowed.
  5. What is the difference between ArrayList and LinkedList?
    Data structure to achieve: ArrayList dynamic array is a data structure implementation, and LinkedList is a doubly linked list data structure to achieve.
    Random access efficiency: ArrayList LinkedList than random access when higher efficiency, because LinkedList linear data storage, it is necessary to move the pointer from front to back order lookup.
    Additions and deletions efficiency: increase in non-inclusive and delete operations, LinkedList ArrayList higher efficiency, because ArrayList index additions and deletions to affect the operation of other data within the array than others.
    ArrayList data structure is implemented based on dynamic array, LinkedList based linked list data structure.
    For random access get and set, ArrayList feel better than LinkedList, because LinkedList to move the pointer.
    For new and delete operations add and remove, LinedList comparative advantage, because ArrayList to move data, and query and modify the ArrayList dominant.
    In summary, when the elements in the collection need to frequently read, but recommended ArrayList, and in the many insert and delete operations, it is recommended to use LinkedList.
    Java Advanced knowledge
    1. three rounding methods associated with:
    Math.ceil (): indicates rounding up; Math.ceil (11.3) = 12; Math.ceil (-11.3) = - 12.
    Math.floor (): indicates rounding down; Math.floor (11.6) = 12; Math.floor (-11.6) = - 12.
    Math.round (): indicates rounding; Math.round (11.5) = 12 is; Math.round (-11.5) = -. 11;
    Marh.round (11.3) =. 11; Math.round (-11.3) = -. 11;
    2 .String and StringBuffuer, the StringBuilder
    string: string value immutable;
    the StringBuffer: editable string, character data may be dynamically configured. StringBuffer class can be modified by the value of Append (). Thread safety.
    StringBuilder: thread safe.
    In common: they can be stored and operating string while using all three final modification, all belong to the class can not be subclassed termination, related method of operation is similar, for example, to get the string length.
    Different:
    1. String which is read-only string, which means the contents of the string String references can not be changed every time a new generation of String objects String operations will, resulting in wasted memory. StringBuffer StringBuilder string object and the class represents may be modified directly, the address value does not change at the same time changes.
    2.StringBuilder JDK 1.5 is introduced, and it is exactly StringBuffer method, except that it is used in a single-threaded environment (not synchronous access), because it is not synchronized all respects modified, so its efficiency slightly higher than StringBuffer.
    Comparison of three in terms of execution speed: StringBuilder> StringBuffer> String
    for use three summarized:
    1. If the amount of data to be operated with String  
    2. The single-threaded operating string buffer StringBuilder operation with large amounts of data
    at 3. multithreading operating string buffer large amounts of data with the StringBuffer
    3. Comparative several different simple singleton singleton
    -fed mode: End Class Loading initialization, whether used or not, create.
    // well-fed mode: load time, initialize, create an instance of an object (whether used or not, create).
    class Singleton {public
    // instantiate an object placed in a static code block, you can improve the efficiency, but may be more space
    Private Final static Singleton instence = new new Singleton ();
    Private Singleton () {}; // private constructor
    // get method
    public static Singleton getInstance () {
    return instence;
    };
    starving mode: create objects when first used, there is a security thread.
    // hungry Han modes: lazy loading, when the object was to create the first time, there is a thread-safety issues.
    class Singleton {public
    Private static Singleton instence = null;
    Private Singleton () {}; // private constructors
    // Get method
    public static synchronized SingleTon getinstance () {
    IF (instence == null) {
    // first time used to create the object
    instence = new new Singleton ();
    }
    return instence;
    };
    }
    4.hashCode differences and relations with equals?
    First, the role of the equals method of
    1, default (no override equals) the methods are invoked equals equals method of Object class, the equals method of Object The main object for determining a reference memory address is not the same address (which is not the same object).
    2, if covering a class equals method, it is necessary to determine the effect of the equals method according to the specific code, if the rear cover is generally judged by the content of the object are equal objects are equal.
    Two, Hashcode () method:
    1, we did not cover Hunter rebate equals method only covers the hashCode method, although the two objects hashCode the same, but when stu1 and stu2 into the set collection due compare two equals method the object is false, so there is no hashcode value in comparing two objects.
    2, covering about equals and hashCode methods, and stu2 STU1 by the equals method to compare match, and returned hashCode the same value, only when put into the set of a set of objects.
    3, we let the equals method compares two objects are equal, but try hashCode values are not equal, though stu1 and stu2 by the equals method compare equal, but hashcode value of the two objects are not equal, and in the stu1 into stu2 set considered to be two different objects in the collection.
    Summary:
    . 1, equals method for comparing the contents of the object are equal (hereinafter coverage)
    2, hashCode method used only in the set
    3, when the cover equals method, the comparison object to be compared for equality after covering by the equals method (the content of the object is determined whether or not equal).
    4, the objects into collections, first determines the set value hashcode any object to be placed in a hashcode value of the element is equal, if not equal the objects directly into the collection. Hashcode If the values are equal, then by determining whether the object equals method to be placed with any of a set of objects is equal to, if not equal equals determination, into the element directly to the collection, or not placed.
    Original link: blog.csdn.net/qq_35980218/article/details/102481247

Guess you like

Origin blog.51cto.com/14511863/2450371