2. An overview of I/o stream
A stream is an ordered sequence of bytes that has a SOURCE or DESTINATION.
two methods for input and output
System.in.read()
System.out.println()
3. Java i/o
Java .io package defines a collection of stgream classes that represent input and output
using
import java.io.*
Streams are classified into two types
1.character streams
2.byte streams
Java .io package provides two sets of hierarchies to handle character and streams
inputStream and OutputStream classes
Reader and Writer are operated on characters
4. Java i/o
Name of class description
Reader, Writer Supports read/write
inputStream and
OutputStream
Define methods
file Enable creating,deleting
and renaming
Random Access File Program to read /write
from/to any location
8. Working with i/o super classes
Methods contained by Reader class for reading character arrays
Methods contained by InputStream class for reaching array of bytes
Method description
Int read()
Int read(char cbuf[])
Int read(char cbuf[], int offset,int length)
Method description
Int read()
Int read(char cbuf[])
Int read(char cbuf[], int offset,int length)
9. Java i/o
Java .io package defines a collection of stgream classes that represent input and output
using
import java.io.*
Streams are classified into two types
1.character streams
2.byte streams
Java .io package provides two sets of hierarchies to handle character and streams
inputStream and OutputStream classes
Reader and Writer are operated on characters
10. APPLETS
Applet Programming
Applets are small Java applications that can be accessed on an Internet server,
transported over Internet, and can be automatically installed and run as a part of a web
document.
An Applet is a Java class that extends the java.applet.Applet class.
An Applet class does not have any main() method.
It is viewed using JVM. The JVM can use either a plug-in of the Web browser or a
separate runtime environment to run an applet application that is “appletviewer”.
Applets are designed to be embedded within an HTML page.
When a user views an HTML page that contains an applet, the code for the applet is
downloaded to the user's machine.
11. Life cycle of Applets
Init( ) - Initialize a variable. Called when an applet begins execution. It is the first method
called for any applet
Start( )- After the init( ) method the program should be started. Called by browser when an
applet should start() execution. It automatically calle init().
Paint( ) -drawing, writing and color creation. The paint( ) method is called Each time your
applet’s output must be redrawn. Paint( ) is also Called when the applet begins execution.
This method has one Parameter of type Graphics. It contain the Graphics context, which
describes the graphics environment. This context is used whenever output to the applet.
Stop( )-Halt of the running applet. Called by browser to suspend execution of the applet.
Once stopped an applet is restarted when the browser calls start().
Destroy( ) -> terminated. Called by browser just before an applet is terminated.
Repaint( ) call update method.
12. How Applets differ from applications
The applets and stand-alone applications are java programs, there are significant differences
between. Applets are not full-featured application program. They are usually written to accomplish a
small task or a component of a task.
They are usually designed for use on the internet, they impose certain limitations and restrictions in
their design. Applets do not use the main( ) method for initiating the execution of the code. Applets,
when loaded, automatically call certain methods of Applet class to start and execute the applet
code.
Unlike stand-alone applications, applets cannot be run independently. They are run from inside a
web page using a special feature known as HTML tag.
Applets cannot read from or write to the files in the local computer. Applets cannot communicate
with other servers on the network.
Applets cannot run any program form the local computer.
Applets are restricted from using libraries from other languages such as c or c++.
13. Life cycle of Applets
Init( ) - Initialize a variable. Called when an applet begins execution. It is the first method
called for any applet
Start( )- After the init( ) method the program should be started. Called by browser when an
applet should start() execution. It automatically calle init().
Paint( ) -drawing, writing and color creation. The paint( ) method is called Each time your
applet’s output must be redrawn. Paint( ) is also Called when the applet begins execution.
This method has one Parameter of type Graphics. It contain the Graphics context, which
describes the graphics environment. This context is used whenever output to the applet.
Stop( )-Halt of the running applet. Called by browser to suspend execution of the applet.
Once stopped an applet is restarted when the browser calls start().
Destroy( ) -> terminated. Called by browser just before an applet is terminated.
Repaint( ) call update method.
14. HTML Applet tag
The APPLET tag is used to start an applet from both an HTML(Hyper Text Markup
Language) document and from an applet viewer
An applet viewer will execute each APPLET tag that if finds in a separate window, while web
browsers like Netscape Navigator, Internet Explorer, and HotJava will allow many applets on
a single page. So far, we have been using only a simplified form of the APPLET tag.
The syntax for the standard APPLET tag is shown here. Bracketed items are optional.
<APPLET
[CODEBASE = codebase URL]
CODE = applet file
WIDTH = pixels HEIGHT = pixels
[ALIGN = alignment] >
[<PARAM NAME = Attribute Name VALUE = Attribute value> ] [<PARAM NAME = Attribute Name2
VALUE = attribute value> ]
</APPLET>
15. THE HTML APPLET TAG:
CODEBASE:
It is an optional attribute that specifies the base URL of the applet code, which is the directory that will be searched for the applet’s
executable class file. The HTML document’s URL directory is used as the CODEBASE if this attribute is not specified.
CODE:
It is a required attribute that gives the name of the file containing your applet’s compiled .class file. This file is relative to the code
base URL of the applet, which is the directory that the HTML file was in or the directory indicated by CODEBASE if set.
WIDTH AND HEIGHT:
WIDTH and HEIGHT are required attributes that give the size ( in pixels) of the applet display area.
ALIGN:
It is an optional attribute that specifies the alignment of the applet. This attributes is treated the same as the HTML IMG tag with these
possible values: LEFT, RIGHT, TOP, BOTTOM, MIDDLE, BASELINE, TEXTTOP, ABSMIDDLE, and ABSBOTTOM.
PARAM NAME AND VALUE:
The PARAM tag allows you to specify applet specific arguments in an HTML page.
Applets access their attributes with the getParameter( ) method.
HANDLING BROWSERS:
The best way to design your HTML page to deal with such browsers is to include HTML text and markup within your
<applet></applet> tags. If the applet tags are not recognized by your browser, you will see the alternate markup. If java is available, it
will consume all of the markup between the <applet></applet> tags and disregard the alternate markup.