Core Java Unit 4
Core Java Unit 4
Core Java Unit 4
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.
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.
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.
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.
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.
Any 3
4. Explain any 3 method of applet clas
5. How to applet differ from application program.
The Reader class of the java.io 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 java.io.Reader;
import java.io.FileReader;
class Main {
public static void main(String[] args) {
try {
// Creates a reader using the FileReader
Reader input = new FileReader("input.txt");
// Reads characters
input.read(array);
System.out.println("Data in the stream:");
System.out.println(array);
catch(Exception e) {
e.getStackTrace();
}
}
}
Output
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>
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>
5. What is file class. Explain how to open and close file class.