Java
Java
start():
The start() method contains the actual code of the applet and starts the applet. It is invoked immediately after the init()
method is invoked. Every time the browser is loaded or refreshed, the start() method is invoked
stop():
The stop() method stops the execution of the applet. The stop () method is invoked whenever the applet is stopped, minimized,
or moving from one tab to another in the browser, the stop() method is invoked.
destroy():
The destroy() method destroys the applet after its work is done. It is invoked when the applet window is closed or
when the tab containing the webpage is closed.
paint():
The paint() method belongs to the Graphics class in Java. It is used to draw shapes like circle, square, trapezium, etc.,
in the applet. It is executed after the start() method and when the browser or applet windows are resized
1] Exception handling
Ans:Exception Handling in Java
• The Exception Handling in Java is one of the powerful mechanism to handle the runtime errors so that
the normal flow of the application can be maintained.
What is Exception in Java?
What is Exception Handling?
In Java, an exception is an event that disrupts the normal flow of the program. It is an object which is thrown
at runtime.
Exception, SQL Exception, Remote Exception, etc.
Advantage of Exception Handling
Exception Handling is a mechanism to handle runtime errors such as Class Not Found Exception, IO
• The core advantage of exception handling is to maintain the normal flow of the application. An exception normally
disrupts the normal flow of the application; that is why we need to handle exceptions
Ans:Try, Catch, and Finally Block in Java:In Java, exception handling is done
using the try, catch, and finally blocks. These blocks help manage
exceptions and ensure that the program continues to run smoothly even in
case of errors.Explanation:try block: The code that might throw an
exception is placed inside the try block. If an exception occurs, the flow of
control moves to the corresponding catch block.catch block: This block
catches and handles the exception thrown by the try block. You can have
multiple catch blocks to handle different types of exceptions.finally block:
The finally block is optional but, if present, it is executed whether an
exception is thrown or not. It is typically used to release resources like
closing files or network connections.
what is text and binary i/o?
Text and Binary I/O in Java:In Java, I/O (Input/Output) operations are classified into two types based on the
format in which data is read from or written to files:1. Text I/O:Text I/O refers to the reading and writing of data
in the form of human-readable characters (such as letters, digits, and symbols).Data is usually read or written
using character streams like FileReader and FileWriter in Java.It works with character encoding (e.g., UTF-8) to
convert between characters and bytes.
2.Binary i/o
*refers to the reading and writing of data in the form of raw binary format, including all types of data (e.g.,
images, videos, audio, and other files) that are not human-readable.
•Data is usually read or written using byte streams like FileInputStream and FileOutputStream.
•Binary I/O does not apply any character encoding or transformation, making it more efficient for handling non-text
data.