0% found this document useful (0 votes)
21 views13 pages

Java Applet and HTML Overview

Here are the steps to open and close a file using File class in Java: 1. Import java.io.File class 2. Create a File object and pass the file path/name as a parameter to the File constructor For example: File file = new File("filename.txt"); 3. Check if the file exists using file.exists() method 4. Open the file for reading/writing using file.createNewFile() method This will create the file if it doesn't exist. 5. Perform read/write operations on the file like reading content using FileReader, writing using FileWriter etc. 6. Close the file using file.close()

Uploaded by

Junaid Ali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views13 pages

Java Applet and HTML Overview

Here are the steps to open and close a file using File class in Java: 1. Import java.io.File class 2. Create a File object and pass the file path/name as a parameter to the File constructor For example: File file = new File("filename.txt"); 3. Check if the file exists using file.exists() method 4. Open the file for reading/writing using file.createNewFile() method This will create the file if it doesn't exist. 5. Perform read/write operations on the file like reading content using FileReader, writing using FileWriter etc. 6. Close the file using file.close()

Uploaded by

Junaid Ali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1. Define Applet.

2. Define Applet life cycle

Applet life cycle is a process of how an object in java is created, initiated, ended, and destroyed
during its entire cycle of execution in an application.
It has five core methods which are, init(), start(), stop(), paint() and destroy(). In java, their methods
are invoked for execution.

3. Define HTML

HTML stands for Hyper Text Markup Language. HTML is the standard markup language for creating
Web pages. HTML describes the structure of a Web page. HTML consists of a series of elements.
HTML elements tell the browser how to display the content.

4. What is Applet tag

The <APPLET> tag resembles the HTML <IMG> image tag. It contains attributes that identify the
applet to be displayed and, optionally, give the web browser hints about how it should be
displayed. [50] The standard image tag sizing and alignment attributes, such as height and width,
can be used inside the applet tag.

5. What is Stream. Class

The Stream class defines objects which accepts a sequence of characters. Streams may also have an output
in which case multiple stream objects can be cascaded to build a stream pipe where the output of a stream
is directed into the input of the next stream object "down the line".

6. What is file

In Java, a File is an abstract data type. A named location used to store related
information is known as a File. There are several File Operations like creating a
new File, getting information about File, writing into a File, reading from a File
and deleting a File.

7. Write down a purpose of file write class or file reader class.

The purpose of FileReader class is to read the streams of characters. This class inherits form the
InputStreamReader class.
The Purpose of FileWriter class is to write streams of characters. This class inherits from the
OutputStreamWriter class.

3M
1. Function of file class.

2. What is random excess file.

a. RandomAccessFile in java is a class that lets the user read and write to a file at the same
time.
b. It extends the Object class and implements DataInput and DataOutput interfaces.
c. These interfaces facilitate the conversion of primitive type data to a sequence of bytes and
bytes to specified type data.
d. It is used to read and write data to a file simultaneously. The file acts as a large array of
bytes stored in the file system.
e. Methods of this class usually throw EOFException i.e. End of File Exception if the end of the
file is reached before the desired number of bytes are read. It is a type of IOException.
f. IOException is thrown if any error occurs other than EOFException like if the byte cannot be
read or written.

3. Write any 3 input stream methods of byte stream class.

Any 3
4. Explain any 3 method of applet clas
5. How to applet differ from application program.

6. Explain the purpose of param tag.


5M
1. Explain Output Stream class with example

2. Explain reader class with example


In this tutorial, we will learn about Java Reader, its subclasses and its methods with the help
of an example.

The Reader class of the [Link] package is an abstract superclass that represents a stream of
characters.
Since Reader is an abstract class, it is not useful by itself. However, its subclasses can be used
to read data.

import [Link];
import [Link];
class Main {
public static void main(String[] args) {

// Creates an array of character


char[] array = new char[100];

try {
// Creates a reader using the FileReader
Reader input = new FileReader("[Link]");

// Checks if reader is ready


[Link]("Is there data in the stream? " + [Link]());

// Reads characters
[Link](array);
[Link]("Data in the stream:");
[Link](array);

// Closes the reader


[Link]();
}

catch(Exception e) {
[Link]();
}
}
}

Output

Is there data in the stream? true


Data in the stream:
This is a line of text inside the file.

3. What is applet tag. Explain with example.


4. Write a program to pass a parameter

5. Explain stock destroy method in applet.


10 M
1. What is applet? Life cycle of applet in detail.
OR
2. How to pass parameter with example
3. How to build applet code . explain its syntax example.
4. Discuss any 10 HTML tag with example.

I. <h1> - Heading Tag: Represents the main heading of a webpage.

Example: <h1>Welcome to My Website</h1>

II. <p> - Paragraph Tag: Defines a paragraph of text.

Example: <p>This is a paragraph of text.</p>

III. <a> - Anchor Tag: Creates a hyperlink to another webpage or resource.

Example: <a href="[Link] here</a>

IV. <img> - Image Tag: Inserts an image into the webpage.

Example: <img src="[Link]" alt="Image description">

V. <ul> - Unordered List Tag: Defines an unordered (bulleted) list.

Ex –

<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
VI. <ol> - Ordered List Tag: Defines an ordered (numbered) list.
Ex-
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>

VII. <div> - Division Tag: Defines a division or section of a webpage.

Example: <div>This is a division.</div>

VIII. <table> - Table Tag: Creates a table with rows and columns.
Ex-
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</table>
IX. <form> - Form Tag: Represents an HTML form for user input.
Ex –
<form action="/submit" method="post">
<input type="text" name="username" placeholder="Enter your username">
<input type="password" name="password" placeholder="Enter your password">
<input type="submit" value="Submit">
</form>

X. <span> - Span Tag: Defines a section within a document.

Example: <span style="color: red;">This is a red span.</span>

5. What is file class. Explain how to open and close file class.

Common questions

Powered by AI

Applets differ significantly from application programs in terms of their execution environment and intended purpose. Applets are designed to be embedded within web pages and run in the context of a browser, whereas application programs are typically standalone applications that run directly on the Java Virtual Machine (JVM). Applets are sandboxed, meaning they have restricted access to the host system for security reasons, which is not a constraint on application programs. Furthermore, the lifecycle management of applets is controlled by the browser, consisting of lifecycle methods like init() and destroy(), whereas application programs have a main() method that initiates execution .

The init(), start(), and destroy() methods of the applet lifecycle manage different phases of applet execution. init() is the first method called when an applet is loaded, used for initialization tasks. After the init() method, the start() method is invoked, called each time the user returns to the page containing the applet. The destroy() method is the last method called, responsible for cleanup before the applet is terminated, freeing resources used during execution. These methods coordinate the initialization, activation, and destruction phases, ensuring efficient resource management and execution state control .

The <APPLET> tag in HTML resembles the <IMG> image tag in structure as they both include attributes for managing display. The <APPLET> tag contains attributes that specify the applet to be displayed and provides hints to the web browser for its display, similar to the sizing and alignment attributes in the <IMG> tag. Both tags can include height and width attributes, aligning in how they manage element dimensions. However, whereas <IMG> is specifically for images, <APPLET> is used for embedding Java applets .

HTML elements such as <form>, <div>, and <span> are foundational in web development for structuring content, applying styles, and enhancing interactivity. The <form> element is crucial for collecting user inputs and submitting data to servers, supporting interactivity with attributes like action and method, which dictate the data handling process. The <div> element is used as a container for various content blocks, allowing for CSS manipulation to organize and style sections of a webpage. The <span> element targets inline portions of content, ideal for applying style or script effects without disrupting document flow. Collectively, these elements contribute to semantic, flexible, and responsive web design, facilitating both backend integration and frontend aesthetics .

The purpose of the FileReader class in Java is to read streams of characters from a file. It is a subclass of the Reader class and inherits its capabilities. When a FileReader is created, it is associated with a file from which it reads characters via a stream. This class is suitable for reading text data rather than binary data from a file. Using the Reader superclass, FileReader provides methods to check the readiness of the stream with ready(), read arrays of characters, and handle I/O exceptions efficiently, allowing character-based file input .

The Reader class is a fundamental component of Java's I/O hierarchy, serving as an abstract base class for reading streams of characters. It is part of the java.io package and provides the core functionality required for subclasses to handle character input efficiently. The design of Reader supports a wide array of character-based input operations, which are crucial for applications dealing with text data. Being abstract, it cannot be instantiated directly, allowing the flexibility for various Reader implementations, such as FileReader and BufferedReader, each optimized for specific use cases like reading files or buffering input for efficiency .

The Stream class in Java provides a way to handle sequences of characters efficiently through input and output streams. It defines standard I/O objects for reading and writing streams of data, thus vital to Java's I/O mechanisms. One of its core functionalities is accepting characters, and potentially producing output, allowing streams to be cascaded to form stream pipes. For instance, while reading from a file, bytes are filtered through an InputStream and can be converted to characters using a Reader class. Similarly, data can be written back with OutputStream classes, enhancing the versatility of I/O operations through abstraction and piping .

RandomAccessFile in Java allows both reading and writing to a file simultaneously, distinct from typical file handling classes that handle either reading or writing. It treats the file as an array of bytes and uses the DataInput and DataOutput interfaces to convert primitive data types into sequences of bytes and back. Unlike other file handling classes which might read/write sequentially, RandomAccessFile supports non-sequential, or 'random', access, enabling the file pointer to be moved to any position for reading or writing. It throws EOFException and IOException for handling specific file system issues, providing robust error handling capabilities .

Key methods of the InputStream class in Java for handling byte streams include read(), available(), and close(). The read() method reads the next byte of data from the input stream. The available() method returns an estimate of the number of bytes that can be read (or skipped over) from the input stream without blocking by the next invocation of a method for this input stream. The close() method closes the input stream and releases any system resources associated with the stream. These methods collectively enable efficient reading and management of byte streams .

The applet life cycle in Java consists of five core methods: init(), start(), stop(), paint(), and destroy(). The init() method initializes the applet when it is first loaded. The start() method is called each time the applet starts, such as when a user navigates back to the page containing the applet after navigating away. The stop() method is invoked when the applet is no longer visible, for example, when the user navigates to another tab. The paint() method is responsible for rendering the applet's graphics. Finally, destroy() is called when the applet is being removed completely, allowing for cleanup of resources .

You might also like