I. Differences and linkages between vectors and ArrayList, ArrayList and LinkedList
1) The difference and connection between vector and ArrayList
Implement the same principle, the same function, are variable length array structure, in many cases can be interoperable
- Vector is an early JDK interface, and ArrayList is a new interface for vector substitution.
- Vector thread safety, ArrayList heavy speed, light security, thread non-secure
- When the length grows, the vector grows by default by a factor of 50% ArrayList growth
2) Differences and links between ArrayList and LinkedList
- ArrayList and LinkedList are the implementation classes of the list, elements have an orderly, not unique characteristics.
- ArrayList implements a variable-length array that allocates contiguous space in memory. The efficiency of traversing elements and random access elements is high;
- The LinkedList uses the list storage method. High efficiency when inserting and deleting elements
Ii. what are the principles of object-oriented design?
Object-oriented design principle is the cornerstone of object-oriented design, the basis and guarantee of object-oriented design quality, design pattern is the classic application of object-oriented design principle.
- Single responsibility principle (SRP)
- Opening and closing principle (OCP)
- On the Richter principle of latent generation (LSP)
- Dependency Injection principle (DIP)
- Interface Classification principle (ISP)
- Dimitri Principles (LOD)
- Combination/Aggregation multiplexing principle (CARP)
The opening and closing principle has the idealistic color, it is the object-oriented design ultimate goal. Other design principles can be regarded as the means or methods of realizing the open and closed principle.
Thirdly, the HashSet uses the hash table as the storage structure, the hash table characteristic and the realization principle.
Hash table query speed is very fast, time complexity of 0
- HashMap, Hashtable, HashSet These collections use the hash table structure, need to use the Hashcode hash code, hashcode is an integer value.
- The system class already covers the Hashcode method, and you must override Hashcode if you want to put the hash class collection. If not overridden, the hashcode of object is called, and the hashcode of object is actually the address
- The principle of adding data to a hash table: When an object is added to a set set, the collection computes the Hashcode code of the object to be incremented, and according to that value a position is used to hold the current object, as if no object exists at that location, and the collection set considers that the object does not exist in the collection. Directly add in. If an object exists at that location, then the object that is to be added to the collection is compared with the Equals method of the object at that location, and if the Equals method returns False, the collection considers that the object does not exist in the collection, and once hashed, Place the object in the new address calculated after the hash. If the Equals method returns True, the collection considers that the object already exists in the collection and no longer adds the object to the collection.
- In the hash table, determine whether two elements are repeated to use to Hashcode () and Equals (). Hashcode determines where the data is stored in the table, and equals determines whether the same data exists.
Iv. the main classes and functions of implementing Java Reflection technology.
In the JDK, the Java reflection mechanism is implemented primarily by the following classes, all of which are in the Java.lang.reflect package
- Class: Represents a Class
- Field class: A member variable representing a class
- Method Class: Representing the member methods of a class
- Constructor class: A structural method that represents a class
- Array class: Provides a static method for dynamically creating an array, and for accessing the elements of an array
V. The difference between sleep () and wait ()
Sleep is a method of threading class (thread).
- The function is to cause the secondary thread to pause execution of the specified time to the execution opportunity to other threads, but the monitoring State remains, and will automatically recover after that time;
- The object lock is not freed with sleep ().
Wait is a method of the object class.
- Calling the wait method on this object causes the field to discard the object lock and enters the waiting lock pool waiting for this object.
- This thread only enters the object lock pool after the Notfiy method (or Notifyall) is emitted for this object, and prepares for an object lock to run.
Vi. linkages and differences between HashMap and Hashtable
Common:
- Both implement the map interface, which maps the unique key to a specific value
- At the bottom, hash tables are used as storage structures, and the query speed is fast and can be used in many cases.
Main differences:
- Hashtable inherits the Dictionary class, HashMap is the java1.2 introduced map implementation.
- Hashtable is thread-safe, while HashMap is not. When multiple threads access Hashtable, they do not need to synchronize their methods, and HashMap must provide external synchronization.
- HashMap does not have a sort, allowing a null key and multiple null values, and two hashtable are not allowed.
- HashMap hashtable contains () removed, changed to Containsvalue and ContainsKey, because the contains method is easy to cause misunderstanding.
Vii. the connection and difference between TCP protocol and UDP protocol in TCP/IP protocol stack
Contact:
TCP and UDP are the two protocols for the transport layer in the TCP/IP stack, which use the network layer capabilities to send packets to the destination to provide network services to the application layer.
Difference:
- TCP is a connection-oriented transport. UDP is a non-connected transport.
- TCP guarantees that the data will arrive in accordance with the send, UDP cannot guarantee.
- TCP is a transmission of reliability, while UDP is unreliable.
- UDP is faster than TCP data because it has a lot less control information
- TCP is suitable for transmitting large amounts of data, and UDP is suitable for transmitting small amounts of data.
Metaphor:
The communication between the server and client of TCP is like two people calling.
The communication between the client in the UDP server is like a two-person telegram texting the latter.
Eight, List, Set, Collection, map of the difference and contact.
- List and set are two sub-interfaces of the collection interface
- Collection interface stores a set of non-unique, unordered objects
- The list interface stores a set of objects that are not unique, ordered (in order of insertion)
- The set interface stores a unique, unordered set of objects
- The map interface stores a set of key-value objects that provide a key-to-value mapping. Key is unordered, unique. Value does not require ordering and allows repetition.
IX. connections and differences between processes and threads
Process and thread Contact:
- A thread is an execution unit within a process and a scheduler entity within a process.
- A thread can belong to only one process, a process can have multiple threads, at least one thread
- Both processes and threads can and do
The difference between a thread and a process:
- The fundamental difference: a thread is the basic unit of dispatch and execution, which allocates resources when the process executes.
- Overhead: High inter-process switching overhead, small switching overhead between threads
- Environment: Multiple tasks (processes) can be run concurrently in the operating system with multiple sequential streams (threads) executing simultaneously in the same application
X. The main steps of TCP socket programming
Server-side programming steps:
- Build a ServerSocket instance that specifies the local port
- Call the Accept () method to obtain a connection request from the client. A new connection to the client is established through the socket instance returned by the Accept () method
- Using this returned socket instance to get InputStream and Outputstram, you can use these two streams to separate and write the data.
- At the end, call the Close () method of the socket instance to close the socket connection
Client Programming Steps:
- Build the socket instance to establish the connection through the specified remote server address and port.
- The data is read and written using the InputStream and OutputStream contained in the socket instance.
- Call the Close method of the socket instance after the operation is finished, close.
Xi. common byte input stream and output stream
- FileInputStream and FileOutputStream node streams take files as data sources and destinations to improve read and write efficiency
- Bufferedinputstream and Bufferedoutputstream processing streams provide buffering capabilities to improve read and write efficiency
- The DataInputStream and DataOutputStream processing streams provide a convenient way to read and write basic data types and string data.
- The ObjectInputStream and ObjectOutputStream processing streams not only provide a convenient way to read and write basic data types and string data, but also provide methods for reading and writing reference type data.
- Bytearrayinputstream and Bytearrayoutputstream node streams with byte arrays as data sources and destinations
12. Two ways to create threads and their advantages and disadvantages.
Way one: Inherit the Java.lang.Thread class and overwrite the run () method.
- Advantage: Write Simple
- Disadvantage: Unable to inherit other parent classes
Mode two: Implement the Java.lang.Runnable interface and implement the run () method.
- Advantage: can inherit other classes, multithreading can share the same thread object
- Disadvantage: The writing method is slightly more complicated, so accessing the current thread requires calling the Thread.CurrentThread () method
13, the UDP socket programming main steps
Server-side (servers):
- Constructs a Datagramsocket instance.
- Create packet Datagrampacket to access the data, IP, and ports that are sent and received.
- Receives client data through the Receive method of the Datagramsocket instance.
- Send feedback to the client via the Send method of Datagramsocket.
- Close the Datagramsocket.
Client:
- Constructs a Datagramsocket instance.
- Create packet Datagrampacket to access the data, IP, and ports that are sent and received.
- Receives client data through the Receive method of the Datagramsocket instance.
- Send information to the server via the Send method of Datagramsocket.
- Close the Datagramsocket.
java--phased Arrangement (iii) set, thread, network programming