Posts

this keyword

  There can be a lot of usage of   Java this keyword . In Java, this is a   reference variable   that refers to the current object. Usage of Java this keyword Here is given the 6 usage of java this keyword. this can be used to refer current class instance variable. this can be used to invoke current class method (implicitly) this() can be used to invoke current class constructor. this can be passed as an argument in the method call. this can be passed as argument in the constructor call. this can be used to return the current class instance from the method . 1) this: to refer current class instance variable The this keyword can be used to refer current class instance variable. If there is ambiguity between the instance variables and parameters, this keyword resolves the problem of ambiguity. class  Student{   int  rollno;   String name;   float  fee;   Student( int  rollno,String name, float  fee){   rollno=rollno;   name=name;   fee=fee;   }   void  display(){System.out.println(rollno

Java AWT

  Java AWT Java AWT  (Abstract Window Toolkit) is  an API to develop Graphical User Interface (GUI) or windows-based applications  in Java. Java AWT components are platform-dependent i.e. components are displayed according to the view of operating system. AWT is heavy weight i.e. its components are using the resources of underlying operating system (OS). The java.awt package provides classes for AWT API such as T extField , Label ,   RadioButton, CheckBox etc. The AWT tutorial will help the user to understand Java GUI programming in simple and easy steps. Components All the elements like the button, text fields, scroll bars, etc. are called components. In Java AWT, there are classes for each component as shown in above diagram. In order to place every component in a particular position on a screen, we need to add them to a container. Container The Container is a component in AWT that can contain another components like  buttons , textfields, labels etc. The classes that extends Contain

Applet life cycle

  Applet Life Cycle in Java In Java, an  applet  is a special type of program embedded in the web page to generate dynamic content. Applet is a class in Java. The applet life cycle can be defined as the process of how the object is created, started, stopped, and destroyed during the entire execution of its application. It basically has five core methods namely init(), start(), stop(), paint() and destroy().These methods are invoked by the browser to execute. Along with the browser, the applet also works on the client side, thus having less processing time. Methods of Applet Life Cycle init():  The init() method is the first method to run that initializes the applet. It can be invoked only once at the time of initialization. The web browser creates the initialized objects, i.e., the web browser (after checking the security settings) runs the init() method within the applet. start():  The start() method contains the actual code of the applet and starts the applet. It is invoked immediate

Java Applet

  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 Lifecycle methods for Applet: The java.applet.Applet class 4 life cycle methods and java.awt.Component class provides 1 life cycle methods for an applet. java.applet.Applet class For creating any applet java.applet.Applet class must be inherited. It provides 4 life cycle methods of applet. public void init():  is used to initialized the Applet. It is invoked only once. public void start():  is in

Exceptions in Java

  Exceptions 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. In this tutorial, we will learn about Java exceptions, it's types, and the difference between checked and unchecked exceptions. Types of Java Exceptions There are mainly two types of exceptions: checked and unchecked. An error is considered as the unchecked exception. However, according to Oracle, there are three types of exceptions namely: Checked Exception Unchecked Exception Error Difference between Checked and Unchecked Exceptions 1) Checked Exception The classes that directly inherit the Throwable class except RuntimeException and Error are known as checked exceptions. For example, IOException, SQLException, etc. Checked exceptions are checked at compile-time. 2) Unchecked Exception The classes that inherit the RuntimeException are known as unchecked exceptions. For example, ArithmeticException,