Java Interview 14th Day

Source: Internet
Author: User

Package names, class names, and attributes can be serialized, and methods and constructors are not serialized.

Static properties are not serialized.

A property is recursively serialized, which is a property of a reference type in a class, and if the class that corresponds to that property implements the serializable interface, the object is also serialized on the object in the class, and an exception is thrown if the serializable interface is not implemented.

All attributes must be serializable, especially when some properties are themselves objects. ".

Transitive objects in the network must be serialized.

NiO non-blocking I/O (optimized I/O)

Java.nio Defining blocks

Buffer class: A container for specific basic types of data

Buffer: A block that is used to store content.

Capacity: The size of the memory opening, depending on the type, there are different spaces.

Bounds: The available part, that is, the index of the first element that should not be read or written.

Position: The position of the current pointer, starting at 0.

Capacity >= limit >= position

Related methods:

int capacity ()

Returns the capacity of this buffer.

int limit ()

Returns the bounds of this buffer.

int position ()

Returns the position of this buffer.

Buffer Flip ()

The equivalent of truncating unused space and then moving the pointer to the beginning so that the limit=position,position=0

Buffer position (int newposition)

Sets the position of this buffer.

When there are large files to be processed, a direct buffer is used in order not to affect performance recommendations.

Buffer has both direct and indirect buffering.

Only the Bytebuffer class provides direct buffering. Use direct buffering without affecting the program. Other classes want to use direct buffering to convert.

Java.nio.channels a channel to read and write to a block, similar to a previous stream

Channel interface: Connection for I/O operation

Programming Steps:

A. Create an I/O stream First,

B. Use the I/O stream. Getchannel () method to obtain the channel,

C. Create a bytebuffer of the right size,

D. The object of the channel. Read (buffer)/write (buffer) to read and write,

E. Close all streams and channels,

F. If you have multi-threaded concurrency, you can use channel. Lock () to get the Filelock object and release the lock with Filelock.release ().

G. When encountering coding problems, use CharSet, Charsetdecoder, charsetencoder three classes to solve

Attention:

You need to call the clear () method before reading to help the read operation clean up the buffer; you need to call the flip () method before writing to help the write cleanup buffer.

Java.nio.charset character set for encoding and decoding

CharSet class: Coded class, encoded information

forname (String charsetname)

Generates a CharSet instance.

Decode (Bytebuffer BB)

A convenient way to decode the bytes in this charset into Unicode characters.

Encode (Charbuffer CB)

A convenient way to encode Unicode characters in this charset into bytes.

Charsetdecoder class: Decoder

The engine that can convert a sequence of bytes in a particular charset into a sequence of 16-bit Unicode characters.

Charsetencoder class: Encoder, coded behavior

An engine capable of converting a sequence of 16-bit Unicode characters into a sequence of bytes in a particular charset.

Network programming:

Basic knowledge of the network

MAC Address: The private address of each NIC is also unique.

Port: Identity of the application (process) (Network communication Program)

There can be 65536 (2^16) ports in the OS, and processes exchange data over ports.

A port is an abstract software structure that is related to protocols: TCP 23 ports and 23 ports of UDTs are two different concepts.

Ports should be more than 1024 ports, the following ports have been set to function.

Protocol: In order to make the data exchange in the network agreement, the Protocol is to ensure the security of communications, the different layers of the protocol is completely different.

TCP Protocol: Transport layer protocol, re-send all the wrong information

IP protocol: Guaranteed address and host one by one correspondence (IP address + network card address)

TCP Programming:

TCP is a connection-oriented protocol that guarantees reliable transmission. With the TCP protocol transmission, a sequential error-free data stream is obtained. A connection must be established between the sender and the receiver's paired two sockets to communicate on the basis of the TCP protocol, and when a socket (usually a server socket) waits for a connection, the other socket can require a connection. Once the two sockets are connected, they can carry out two-way data transfer and both can send or receive operations.

1) The server assigns a port number, the server waits for the client signal with the Accept () method, signals one to open the socket connection, obtains outputstream and InputStream from the socket.

2) The client provides the host address and port number using the socket port to establish the connection, get OutputStream and InputStream.

Steps for server-side encoding:

1. New ServerSocket Open port

2. The ServerSocket accept () waits for the client to connect when the connection is successfully returned to the interactive socket.

3. Call Socket.getinputstream,getoutputstream to get the server-side IO stream

4, with the processing flow encapsulated after interacting with the client, remember that you read my writing, read and write.

5, close the single client call to the socket close (), close the server tune ServerSocket Close ();

Socket-side encoding steps:

1, the new Socket (Server ip,server Port) attempts to connect, if the object is successful

2. Call Socket.getinputstream,getoutputstream to get the server-side IO stream

3, with the processing flow encapsulated after interacting with the client, remember that you read my writing, read and write.

4, close, only the socket's close () method.

Java Interview 14th Day

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.