Contents - Cultural View

Contents - Cultural View Contents - Cultural View

culturalview.com
from culturalview.com More from this publisher
14.07.2013 Views

New I/O 236 sz); } } // Decode the file into a char buffer CharBuffer cb = decoder.decode(bb); // Perform the search grep(f, cb); // Close the channel and the stream fc.close(); public static void main(String[] args) { } if (args.length < 2) { } System.err.println("Usage: java Grep pattern file..."); return; compile(args[0]); for (int i = 1; i < args.length; i++) { } File f = new File(args[i]); try { grep(f); } catch (IOException x) { } JDK 7 and NIO.2 System.err.println(f + ": " + x); JDK 7 includes a java.nio.file package which, with the java.io.file.Path class (also new to JDK 7), among other features, provides extended capabilities for filesystem tasks, e.g. can work with symbolic/hard links and dump big directory listings into buffers more quickly than the old File class does. External links • Java SE 6 API Javadocs • JDK 5.0 New I/O-related APIs & Developer Guides [4] - description of New I/O by Sun Microsystems • JSR 51 [5] (NIO) • JSR 203 [6] (NIO2) • Architecture of a Highly Scalable NIO-Based Server [7] - discussion on Java NIO and patterns of usage

New I/O 237 References [1] "JSR 51: New I/O APIs for the JavaTM Platform" (http:/ / www. jcp. org/ en/ jsr/ detail?id=51). The Java Community Process(SM) Program - JSRs: Java Specification Requests. . Retrieved 2009-05-23. [2] "This JSR will be delivered as part of Java SE 7 "Dolphin"." "JSR 203: More New I/O APIs for the JavaTM Platform ("NIO.2")" (http:/ / www. jcp. org/ en/ jsr/ detail?id=203). The Java Community Process(SM) Program - JSRs: Java Specification Requests. 2006-01-30. . Retrieved 2009-05-23. [3] http:/ / java. sun. com/ j2se/ 1. 4. 2/ docs/ guide/ nio/ example/ index. html [4] http:/ / java. sun. com/ j2se/ 1. 5. 0/ docs/ guide/ nio/ index. html [5] http:/ / www. jcp. org/ en/ jsr/ detail?id=51 [6] http:/ / www. jcp. org/ en/ jsr/ detail?id=203 [7] http:/ / today. java. net/ pub/ a/ today/ 2007/ 02/ 13/ architecture-of-highly-scalable-nio-server. html Object type (object-oriented programming) In computer science, an object type (a.k.a. wrapping object) is a datatype which is used in object-oriented programming to wrap a non-object type to make it look like a dynamic object. Some object-oriented programming languages make a distinction between reference and value types, often referred to as objects and non-objects on platforms where complex value types don't exist, for reasons such as runtime efficiency and syntax or semantic issues. For example, Java has primitive wrapper classes corresponding to each primitive type: Integer and int, Character and char, Float and float, etc. Languages like C++ have little or no notion of reference type; thus, the use of object type is of little interest. Boxing Boxing is the process of placing a primitive type within an object so that the primitive can be used as a reference object. For example, lists may have certain methods which arrays might not, but the list might also require that all of its members be dynamic objects. In this case, the added functionality of the list might be unavailable to a simple array of numbers. For a more concrete example, in Java, a LinkedList can change its size, but an array must have a fixed size. One might desire to have a LinkedList of ints, but the LinkedList class only lists references to dynamic objects — it cannot list primitive types, which are value types. To get around this, ints can be boxed into Integers, which are dynamic objects, and then added to a LinkedList of Integers. (Using generic parameterized types introduced in J2SE 5.0, this type is represented as LinkedList.) On the other hand, C# has no primitive wrapper classes, but allows boxing of any value type, returning a generic Object reference. The boxed object is always a copy of the value object, and is usually immutable. Unboxing the object also returns a copy of the stored value. Note that repeated boxing and unboxing of objects can have a severe performance impact, since it dynamically allocates new objects and then makes them eligible for Garbage collection. Autoboxing Autoboxing is the term for treating a value type as a reference type without any extra source code. The compiler automatically supplies the extra code needed to perform the type conversion. For example, J2SE 5.0 allows the programmer to create a LinkedList of ints. This does not contradict what was said above: the LinkedList still only lists references to dynamic objects, and it cannot list primitive types. But now, when Java expects a reference but receives a primitive type, it immediately converts that primitive type to a dynamic object. Note that the declaration List is illegal in Java, but List is not, and autoboxing will allow adding of primitive ints to the collection. For example, in versions of Java prior to J2SE 5.0, the following code did not compile:

New I/O 236<br />

sz);<br />

}<br />

}<br />

// Decode the file into a char buffer<br />

CharBuffer cb = decoder.decode(bb);<br />

// Perform the search<br />

grep(f, cb);<br />

// Close the channel and the stream<br />

fc.close();<br />

public static void main(String[] args) {<br />

}<br />

if (args.length < 2) {<br />

}<br />

System.err.println("Usage: java Grep pattern file...");<br />

return;<br />

compile(args[0]);<br />

for (int i = 1; i < args.length; i++) {<br />

}<br />

File f = new File(args[i]);<br />

try {<br />

grep(f);<br />

} catch (IOException x) {<br />

}<br />

JDK 7 and NIO.2<br />

System.err.println(f + ": " + x);<br />

JDK 7 includes a java.nio.file package which, with the java.io.file.Path class (also new to JDK 7), among other<br />

features, provides extended capabilities for filesystem tasks, e.g. can work with symbolic/hard links and dump big<br />

directory listings into buffers more quickly than the old File class does.<br />

External links<br />

• Java SE 6 API Javadocs<br />

• JDK 5.0 New I/O-related APIs & Developer Guides [4] - description of New I/O by Sun Microsystems<br />

• JSR 51 [5] (NIO)<br />

• JSR 203 [6] (NIO2)<br />

• Architecture of a Highly Scalable NIO-Based Server [7] - discussion on Java NIO and patterns of usage

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!