The java.lang.Thread class & Methods
|
The Thread class creates individual threads. To create a thread either (i) extend the Thread class or (ii) implement the Runnable interface. In both cases, the run() method defines operations performed by the thread.
Methods of the Thread class:
Methods | Description |
---|
run() | Must be overridden by Runnable object; contains code that the thread should perform |
start() | Causes the run method to execute and start the thread |
sleep() | Causes the currently executing thread to wait for a specified time before allowing other threads to execute |
interrupt() | Interrupts the current thread |
Yield() | Yields the CPU to other runnable threads |
getName() | Returns the current thread’s name |
getPriority() | Returns the thread’s priority as an integer |
isAlive() | Tests if the thread is alive; returns a Boolean value |
join() | Waits for specified number of milliseconds for a thread to die |
setName() | Changes the name of the thread |
setPriority() | Changes the priority of the thread |
currentThread() | Returns a reference to the currently executing thread |
activeCount() | Returns the number of active threads in a thread group |
|
I/O classes in Java (part of the java.io package):
|
I/O class name | Description |
---|
BufferedInputStream | Provides the ability to buffer the input. Supports mark() and reset() methods. |
BufferedOutputStream | Provides the ability to write bytes to the underlying output stream without making a call to the underlying system. |
BufferedReader | Reads text from a character input stream |
BufferedWriter | Writes text to character output stream |
DataInputStream | Allows an application to read primitive datatypes from an underlying input stream |
DataOutputStream | Allows an application to write primitive datatypes to an output stream |
File | Represents disk files and directories |
FileInputStream | Reads bytes from a file in a file system |
FileOutputStream | Writes bytes to a file |
ObjectInputStream | Reads bytes i.e. deserializes objects using the readObject() method |
ObjectOutputStream | Writes bytes i.e. serializes objects using the writeObject() method |
PrintStream | Provides the ability to print different data values in an efficient manner |
RandomAccessFile | Supports reading and writing to a random access file |
StringReader | Character stream that reads from a string |
StringWriter | Character stream that writes to a StringBuffer that is later converted to a String
|
|
The java.io.InputStream class:
|
The InputStream class is at the top of the input stream hierarchy. This is an abstract class which cannot be instantiated. Hence, subclasses like the DataInputStream class are used for input purposes.
Methods of the InputStream class:
Method | Description |
---|
available() | Returns the number of bytes that can be read |
close() | Closes the input stream and releases associated system resources |
mark() | Marks the current position in the input stream mark |
Supported() | Returns true if mark() and reset() methods are supported by the input stream |
read() | Abstract method which reads the next byte of data from the input stream |
read(byte b[]) | Reads bytes from the input stream and stores them in the buffer array |
skip() | Skips a specified number of bytes from the input stream
|
|
The java.io.OutputStream class:
|
The OutputStream class which is at the top of the output stream hierarchy, is also an abstract class, which cannot be instantiated. Hence, subclasses like DataOutputStream and PrintStream are used for output purposes.
Methods of the OutputStream class:
Method | Description |
---|
close() | Closes the output stream, and releases associated system resources |
write(int b) | Writes a byte to the output stream |
write(byte b[]) | Writes bytes from the byte array to the output stream |
flush() | Flushes the ouput stream, and writes buffered output bytes
|
|
java.io.File class:
|
The File class abstracts information about files and directories.
Methods of the File class:
Method | Description |
---|
exists() | Checks whether a specified file exists |
getName() | Returns the name of the file and directory denoted by the path name |
isDirectory() | Tests whether the file represented by the pathname is a directory |
lastModified() | Returns the time when the file was last modified |
length() | Returns the length of the file represented by the pathname |
listFiles() | Returns an array of files in the directory represented by the pathname |
setReadOnly() | Marks the file or directory so that only read operations can be performed |
renameTo() | Renames the file represented by the pathname |
delete() | Deletes the file or directory represented by the pathname |
canRead() | Checks whether the application can read from the specified file |
canWrite() | Checks whether an application can write to a specified file
|
|
Click for Next Quick Reference
|
|
|
|
About Author
|
Author Name : Mr. R.Franklin Bourgia Singh
Country : INDIA
Working In : Aryans Infoway (P) Ltd.
Email : admin@completetutorials.co.cc
Author Home Page : http://www.completetutorials.googlepages.com
|
Reach me!
|
|
Send your feed-back and query to admin@completetutorials.co.cc
©2008 Bourgia
|