Java The Complete Reference, Seventh Edition
808 Part II: The Java Library The Concurrent Collections As explained, the concurrent API defines several collection classes tha ...
Chapter 26: The Concurrency Utilities 809 java.util.concurrent.lockssupplies an implementation ofLockcalledReentrantLock. Reentr ...
810 Part II: The Java Library // A shared resource. class Shared { static int count = 0; } // A thread of execution that increme ...
Chapter 26: The Concurrency Utilities 811 B: 2 B is sleeping. B is unlocking count. java.util.concurrent.locksalso defines theRe ...
System.out.println(name + " got: " + Shared.ai.getAndSet(i)); } } In the program, a staticAtomicIntegernamedaiis created byShare ...
27 NIO, Regular Expressions, and Other Packages W hen Java was originally released, it included a set of eight packages, called ...
814 Part II: The Java Library Package Primary Function java.awt.font Represents various types of fonts. java.awt.geom Allows you ...
Chapter 27: NIO, Regular Expressions, and Other Packages 815 NIO A relatively new addition to Java is calledNIO (New I/O),and it ...
816 Part II: The Java Library Buffers Buffers are defined in thejava.niopackage. All buffers are subclasses of theBufferclass, w ...
FromBufferare derived the following specific buffer classes, which hold the type of data that their names imply: ByteBuffer Char ...
Channels Channels are defined injava.nio.channels. A channel represents an open connection to an I/O source or destination. You ...
Because default encoders and decoders are provided, you will not often need to work explicitly withcharsets. Aselectorsupports k ...
FileChannel fChan; long fSize; ByteBuffer mBuf; try // First, open a file for input. fIn = new FileInputStream("test.txt"); // N ...
Chapter 27: NIO, Regular Expressions, and Other Packages 821 A second, and often easier, way to read a file is to map it to a bu ...
// Read bytes from the buffer. for(int i=0; i < fSize; i++) System.out.print((char)mBuf.get()); fChan.close(); // close chann ...
// Write some bytes to the buffer. for(int i=0; i<26; i++) mBuf.put((byte)('A' + i)); // Rewind the buffer so that it can be ...
824 Part II: The Java Library // Write some bytes to the buffer. for(int i=0; i<26; i++) mBuf.put((byte)('A' + i)); // close ...
Chapter 27: NIO, Regular Expressions, and Other Packages 825 // Write the buffer to the output file. fOChan.write(mBuf); // this ...
826 Part II: The Java Library Here,patternis the regular expression that you want to use. Thecompile( )method transforms the str ...
Chapter 27: NIO, Regular Expressions, and Other Packages 827 Here,newStrspecifies the new character sequence that will replace t ...
«
38
39
40
41
42
43
44
45
46
47
»
Free download pdf