Posts

Showing posts from September, 2019

Exception Handling in Java

Image
  Exception Handling in Java : The  Exception Handling in Java  is one of the powerful  mechanism to handle the runtime errors  so that normal flow of the application can be maintained. In this page, we will learn about Java exceptions, its type and the difference between checked and unchecked exceptions. What is Exception in Java Dictionary Meaning:  Exception is an abnormal condition. What is Exception Handling Exception Handling is a mechanism to handle runtime errors such as ClassNotFoundException, IOException, SQLException, RemoteException, etc. Hierarchy of Java Exception classes Types of Java Exceptions There are mainly two types of exceptions: checked and unchecked. Here, an error is considered as the unchecked exception. According to Oracle, there are three types of exceptions: Checked Exception Unchecked Exception Error Difference between Checked and Unchecked Exceptions 1) Checked Exception The classes which directly inherit Th

JAVA IMPORTANT QUESTIONS

EXAMPLE PROGRAM 1(APPLETS)

How to run an Applet? There are two ways to run an applet By html file. By appletViewer tool (for testing purpose). EXAMPLE PROGRAM : import java . applet .*; import java . awt .*; public class HelloWorldApplet extends Applet { public void paint ( Graphics g ) { g . drawString ( "Hello World" , 25 , 50 ); } } These import statements bring the classes into the scope of our applet class − import java.awt.applet.*; import java.awt.Graphics; Invoking an Applet <html> <title> The Hello, World Applet </title> <hr> <applet code = "HelloWorldApplet.class" width = "320" height = "120" > </applet> <hr> </html>

APPLET LIFE CYCLE

Image
Java Applet Applet is a special type of program that is embedded in the webpage to generate the dynamic content. It runs inside the browser and works at client side. Advantage of Applet There are many advantages of applet. They are as follows: It works at client side so less response time. Secured It can be executed by browsers running under many plateforms, including Linux, Windows, Mac Os etc. Drawback of Applet Plugin is required at client browser to execute applet. Lifecycle of Java Applet Applet is initialized. Applet is started. Applet is painted. Applet is stopped. Applet is destroyed. Life Cycle of an Applet Four methods in the Applet class gives you the framework on which you build any serious applet − init  − This method is intended for whatever initialization is needed for your applet. It is called after the param tags inside the applet tag have been processed. start  − This method is automatically called after the brow