Archive for July, 2011

Java’s interface inheritance mechanism

Sunday, July 17th, 2011 | SEO with Comments Off
Most people think that the interface is about the replacement of multiple inheritance. Known as Java does not c + + multiple inheritance mechanism, but can implement multiple interfaces. Actually, this is very far-fetched, interfaces and inheritance are completely different things, the interface can not afford to replace the multiple inheritance, there is no such obligation. The role of interfaces, in a word, is a sign class category (type of class).
Attributed to different types of classes of different …
Most people think that the interface is about the replacement of multiple inheritance. Known as Java does not c + + multiple inheritance mechanism, but can implement multiple interfaces. Actually, this is very far-fetched, interfaces and inheritance are completely different things, the interface can not afford to replace the multiple inheritance, there is no such obligation.

Use Java Collections Framework

Sunday, July 10th, 2011 | SEO with Comments Off
First, an overview of the data structure has a profound impact on program design, process-oriented C language, with a struct to describe the database structure, while in object-oriented programming, data structures are described using class, and includes methods of operation of the data structure. In the Java language, Java language designers commonly used data structures and algorithms to do a number of specification (interface) and implementation (concrete realization of interface). All abstract …
I. Introduction
Data structure of the program design has a profound impact on the process-oriented C language, database structure with the struct be described in the object-oriented programming, data structures are used to describe the class, and contains a Duigaishuoju structure operation method.
In the Java language, Java language design are commonly used data structures and algorithms to do a number of specification (interface) and implementation (concrete realization of interface). Out of all the abstract data structures and operations (algorithms) collectively referred to as Java Collections Read the rest of this entry »

JAVA array initialization

Friday, July 8th, 2011 | SEO with Comments Off

the array name can be represented with subscript array elements. The first element is an array subscript to O elements, such as points [0]. The last element of the subscript for the length of a 1, such as points [points.1ength 1 1]. When you create an array, each element is initialized. As previously created character array s, each of its value is initialized to O (\ 0000). The array of points …

Subscript array name with an array of elements can be expressed. The first element is an array subscript to O elements, such as points [0]. The last element of the subscript for the length of a 1, such as points [points.1ength 1 1].

Read the rest of this entry »

Java exception handling of special cases

Thursday, July 7th, 2011 | SEO with Comments Off

1, can not finally block the implementation of return, continue such statements, or exceptions will “eat”; 2, in the try, catch the return statement if, in the implementation of the return prior to implementation of the finally block below please example: public class TryTest (public static void …

1, not in the finally block in the implementation of the return, continue such statements, or exceptions will “eat”;
2, in the try, catch the return statement if, in the implementation of the return prior to implementation of the finally block

Read the rest of this entry »

Java byte stream and character stream

Wednesday, July 6th, 2011 | SEO with Comments Off
For our common GBK Chinese and English is occupied by a byte, in Chinese, 2 for UTF-8, English is one, in Chinese, 3 for Unicode, English and Chinese are two operations on Java’s stream byte stream and character stream for the two. 1, byte stream read operations are all inherited from a common super class java.io.InputStream class. All write operations are inherited from one …
GBK in our common English, it is occupied by a byte, in Chinese 2
For UTF-8, English is one, in Chinese, 3
For Unicode, English and Chinese are two
Java’s current operations are divided into two kinds of byte stream and character stream.
1, a byte stream
All read operations are inherited from a common super class java.io.InputStream class.
All write operations are inherited from a common super class java.io.OutputStream class.
InputStream and OutputStream are abstract classes.
InputStream has six low-level input stream:
Low flow
The use of flow
ByteArrayInputStream
Read data from memory array of bytes
FileInputStream
From the local file system to read data byte
PipedInputStream
Pipeline from the thread to read data byte
StringBufferInputStream
Read data byte from a string
SequenceInputStream
Low-level flow from two or more data bytes to read, when the reach the end of the stream flow from one to another stream
System.in
Read data byte from the user console
There is also a subclass of InputStream: filter flow java.io.FilterInputStream. Filter stream that can wrap up the basic flow, provide more convenient usage.
FilterInputStream class constructor for the FilterInputStream (InputStream), on the specified input stream, create an input stream filter.
Common FilterInputStream subclass as follows:
Filter input stream
The use of flow
BufferedInputStream
Buffer access to data to improve efficiency
DataInputStream
Read from the input stream of basic data types, such as int, float, double, or even one line of text
LineNumberInputStream
In the translation of line endings, based on maintaining a counter that shows which line is being read.
PushbackInputStream
Pushed back to allow the data bytes to the stream of first
OutputStream (abbreviated)
The structure of OutputStream and InputStream is the same.
2, the character stream
Note: It is introduced in jdk1.1 inside, above the byte stream is introduced in jdk1.0. When used to process text data, select the character stream better than the byte stream. But the basic data types only way developers can continue to use the byte stream.
All read operations are inherited from a common super class java.io.Reader class.
All write operations are inherited from a common super class java.io.Writer class.
Reader and Writer is the same abstract class.
Reader’s common subclass as follows:
Low-level reader
The use of flow
CharArrayReader
Read data from a character array
InputStreamReader
FileReader (InputStreamReader sub-category)
From the local file system, a sequence of characters to read
StringReader
Read a sequence of characters from the string
PipedReader
Pipeline from the thread to read a sequence of characters
InputStreamReader highlight:
InputStreamReader to read from the input data stream, the connection input stream on the reader. Such as:
new InputStreamReader (System.in)
Constructor:
InputStreamReader (InputStream)
Use the default character encoding, create a InputStreamReader.
InputStreamReader (InputStream, String)
With a named character encoding, create a InputStreamReader.
Commonly used filters reader:
Filter reader
The use of flow
BufferedReader
Buffered data access, to improve efficiency
LineNumberReader (BufferedReader sub-category)
Maintains a counter that shows which line is being read.
FilterReader (abstract class)
Create a filter to provide a class can extend this class
PushbackReader (FilterReader sub-category)
Pushed back to allow the text data stream reader
These filters reader can pass a Reader as a constructor parameter.
Writer (abbreviated)
The structure of Writer and Reader are the same.
Byte stream is the most basic, the characters flow in order to deal with characters of their argument.
new BufferedReader (new InputStreamReader (client.getInputStream ())); explained:
client.getInputStream () is a byte stream;
InputStreamReader stream the byte stream into characters;
BufferedReader buffered character stream, makes it possible to use the readline () and other methods to read a line directly.