J ava Classes
  
 Introduction

The class body (the area between the braces) contains all the code that provides for the life cycle of the objects created from the class: constructors for initializing new objects, declarations for the fields that provide the state of the class and its objects, and methods to implement the behavior of the class and its objects.

The preceding class declaration is a minimal one—it contains only those components of a class declaration that are required. You can provide more information about the class, such as the name of its superclass, whether it implements any interfaces, and so on, at the start of the class declaration.

In general, class declarations can include these components, in order:

  1. Modifiers such as public, private, and a number of others that you will encounter later.
  2. The class name, with the initial letter capitalized by convention.
  3. The name of the class's parent (superclass), if any, preceded by the keyword extends. A class can only extend (subclass) one parent.
  4. A comma-separated list of interfaces implemented by the class, if any, preceded by the keyword implements. A class can implement more than one interface.
  5. The class body, surrounded by braces, {}.
Your Ad Here

 
 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:
MethodsDescription
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 nameDescription
BufferedInputStreamProvides the ability to buffer the input. Supports mark() and reset() methods.
BufferedOutputStreamProvides the ability to write bytes to the underlying output stream without making a call to the underlying system.
BufferedReaderReads text from a character input stream
BufferedWriterWrites text to character output stream
DataInputStreamAllows an application to read primitive datatypes from an underlying input stream
DataOutputStreamAllows an application to write primitive datatypes to an output stream
FileRepresents disk files and directories
FileInputStreamReads bytes from a file in a file system
FileOutputStreamWrites bytes to a file
ObjectInputStreamReads bytes i.e. deserializes objects using the readObject() method
ObjectOutputStreamWrites bytes i.e. serializes objects using the writeObject() method
PrintStreamProvides the ability to print different data values in an efficient manner
RandomAccessFileSupports reading and writing to a random access file
StringReaderCharacter stream that reads from a string
StringWriterCharacter 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:
MethodDescription
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:
MethodDescription
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:
MethodDescription
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
PreviousNext



Your Ad Here


 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!
   My Web URL : http://www.completetutorials.googlepages.com
   If you like this article and/or code, make a small donation to my account,
Till we meet next time BYE     

  Send your feed-back and query to admin@completetutorials.co.cc
©2008 Bourgia