SlideShare a Scribd company logo
1 of 57
Download to read offline
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
PAPER NAME: JAVA PROGRAMMING
PAPER CODE: BCA 206
CLASS: BCA IVth Semester
UNIT-I Inheritance and Class Hierarchies
• Object-oriented programming (OOP) is popular because:
• It enables reuse of previous code saved as classes
• All Java classes are arranged in a hierarchy
• Object is the superclass of all Java classes
• Inheritance and hierarchical organization capture idea:
• One thing is a refinement or extension of another
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Inheritance and Class Hierarchies
superclass
subclass
Summary
Is-a Versus Has-a Relationships
• Confusing has-a and is-a leads to misusing inheritance
• Model a has-a relationship with an attribute (variable)
public class C { ... private B part; ...}
• Model an is-a relationship with inheritance
• If every C is-a B then model C as a subclass of B
• Show this: in C include extends B:
public class C extends B { ... }
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
A Superclass and a Subclass
• Consider two classes: Computer and Laptop
• A laptop is a kind of computer: therefore a subclass
variables of Computer
and all subclasses
additional variables for
class Laptop
(and its subclasses)
methods of Computer
and all subclasses
additional Methods for
class Laptop
(and its subclasses)
Illustrating Has-a with Computer
public class Computer {
private Memory mem;
...
}
public class Memory {
private int size;
private int speed;
private String kind;
...
}
A Computer has only one Memory
But neither is-a the other
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Initializing Data Fields in a Subclass
• What about data fields of a superclass?
• Initialize them by invoking a superclass constructor with the
appropriate parameters
• If the subclass constructor skips calling the superclass ...
• Java automatically calls the no-parameter one
• Point: Insure superclass fields initialized before
subclass starts to initialize its part of the object
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Example of Initializing Subclass Data
public class Computer {
private String manufacturer; ...
public Computer (String manufacturer, ...) {
this.manufacturer = manufacturer; ...
}
}
public class Laptop extends Computer {
private double weight; ...
public Laptop (String manufacturer, ...,
double weight, ...) {
super(manufacturer, ...);
this.weight = weight;
}
}
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Protected Visibility for Superclass Data
• private data are not accessible to subclasses!
• protected data fields accessible in subclasses
(Technically, accessible in same package)
• Subclasses often written by others, and
• Subclasses should avoid relying on superclass details
• So ... in general, private is better
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Method Overriding
• If subclass has a method of a superclass (same signature),
that method overrides the superclass method:
public class A { ...
public int M (float f, String s) { bodyA }
}
public class B extends A { ...
public int M (float f, String s) { bodyB }
}
• If we call M on an instance of B (or subclass of B), bodyB runs
• In B we can access bodyA with: super.M(...)
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Method Overloading
• Method overloading: multiple methods ...
• With the same name
• But different signatures
• In the same class
• Constructors are often overloaded
• Example:
• MyClass (int inputA, int inputB)
• MyClass (float inputA, float inputB)
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Example of Overloaded Constructors
public class Laptop extends Computer {
private double weight; ...
public Laptop (String manufacturer,
String processor, ...,
double weight, ...) {
super(manufacturer, processor, ...);
this.weight = weight;
}
public Laptop (String manufacturer, ...,
double weight, ...) {
this(manufacturer, “Pentium”, ...,
weight, ...);
}
}
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Overloading Example From Java Library
ArrayList has two remove methods:
remove (int position)
• Removes object that is at a specified place in the list
remove (Object obj)
• Removes a specified object from the list
It also has two add methods:
add (Element e)
• Adds new object to the end of the list
add (int index, Element e)
• Adds new object at a specified place in the list
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Polymorphism
• Variable of superclass type can refer to object of subclass type
• Polymorphism means “many forms” or “many shapes”
• Polymorphism lets the JVM determine at run time which method to invoke
• At compile time:
• Java compiler cannot determine exact type of the object
• But it is known at run time
• Compiler knows enough for safety: the attributes of the type
• Subclasses guaranteed to obey
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Interfaces vs Abstract Classes vs Concrete Classes
• A Java interface can declare methods
• But cannot implement them
• Methods of an interface are called abstract methods
• An abstract class can have:
• Abstract methods (no body)
• Concrete methods (with body)
• Data fields
• Unlike a concrete class, an abstract class ...
• Cannot be instantiated
• Can declare abstract methods
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Abstract Classes and Interfaces
• Abstract classes and interfaces cannot be instantiated
• An abstract class can have constructors!
• Purpose: initialize data fields when a subclass object is created
• Subclass uses super(…) to call the constructor
• An abstract class may implement an interface
• But need not define all methods of the interface
• Implementation of them is left to subclasses
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Example of an Abstract Class
public abstract class Food {
public final String name;
private double calories;
public double getCalories () {
return calories;
}
protected Food (String name, double calories) {
this.name = name;
this.calories = calories;
}
public abstract double percentProtein();
public abstract double percentFat();
public abstract double percentCarbs();
}
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Example of a Concrete Subclass
public class Meat extends Food {
private final double protCal; ...;
public Meat (String name, double protCal,
double fatCal double carbCal) {
super(name, protCal+fatCal+carbCal);
this.protCal = protCal;
...;
}
public double percentProtein () {
return 100.0 * (protCal / getCalories());
}
...;
}
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Example: Number and the Wrapper Classes
Declares what the
(concrete)
subclasses have in
common
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Inheriting from Interfaces vs Classes
• A class can extend 0 or 1 superclass
• Called single inheritance
• An interface cannot extend a class at all
• (Because it is not a class)
• A class or interface can implement 0 or more interfaces
• Called multiple inheritance
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
UNIT-II EXCEPTION HANDLING
Use
try,
throw,
catch
to
watch for indicate
exceptions
handle
How to process exceptions and failures.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Overview
• Exception
• Indication of problem during execution
• Uses of exception handling
• Process exceptions from program components
• Handle exceptions in a uniform manner in large projects
• Remove error-handling code from “main line” of execution
• A method detects an error and throws an exception
• Exception handler processes the error
• Uncaught exceptions yield adverse effects
• Might terminate program execution
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Overview
• Code that could generate errors put in try blocks
• Code for error handling enclosed in a catch clause
• The finally clause always executes
• Termination model of exception handling
• The block in which the exception occurs expires
• throws clause specifies exceptions method throws
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Exception Handler
Exception
"thrown" here
Exception
handler
Exception
handler
Thrown exception matched against
first set of exception handlers
If it fails to match, it is matched against
next set of handlers, etc.
If exception matches none of handlers,
program is abandoned
Terminology
• Thrown exception – an exception that has occurred
• Stack trace
• Name of the exception in a descriptive message that indicates the
problem
• Complete method-call stack
• ArithmeticException – can arise from a number of different problems in
arithmetic
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Terminology
• Throw point – initial point at which the exception occurs, top row of call
chain
• InputMismatchException – occurs when Scanner method nextInt receives a
string that does not represent a valid integer
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Termination Model of Exception Handling
• When an exception occurs:
• try block terminates immediately
• Program control transfers to first matching catch block
• try statement – consists of try block and corresponding catch and/or finally
blocks
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Enclosing Code in a try Block
• try block – encloses code that might throw an exception and the code that
should not execute if an exception occurs
• Consists of keyword try followed by a block of code enclosed in curly
braces
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Using the throws Clause
• Appears after method’s parameter list and before the method’s body
• Contains a comma-separated list of exceptions
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Using the throws Clause
• Exceptions can be thrown by statements in method’s body of by methods
called in method’s body
• Exceptions can be of types listed in throws clause or subclasses
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Example: Handling ArithmeticExceptions and
InputMismatchExceptions
• With exception handling
• program catches and handles the exception
• Example
• Allows user to try again if invalid input is entered (zero for
denominator, or non-integer input)
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Sequence of Events for throw
Preceding step
try block
throw
statement
unmatched catch
matching catch
unmatched catch
next step
Sequence of Events for
No throw
Preceding step
try block
throw
statement
unmatched catch
matching catch
unmatched catch
next step
When to Use Exception Handling
• Exception handling designed to process synchronous errors
• Synchronous errors – occur when a statement executes
• Asynchronous errors – occur in parallel with and independent of the
program’s flow of control
• Avoid using exception handling as an alternate form of flow of control.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Java Exception Hierarchy
• Superclass Throwable
• Subclass Exception
• Exceptional situations
• Should be caught by program
• Subclass Error
• Typically not caught by program
• Checked exceptions
• Catch or declare
• Unchecked exceptions
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Java Exception Hierarchy
• All exceptions inherit either directly or indirectly from class Exception
• Exception classes form an inheritance hierarchy that can be extended
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Java Exception Hierarchy
• Class Throwable, superclass of Exception
• Only Throwable objects can be used with the exception-handling
mechanism
• Has two subclasses: Exception and Error
• Class Exception and its subclasses represent exception situations that
can occur in a Java program and that can be caught by the application
• Class Error and its subclasses represent abnormal situations that could
happen in the JVM – it is usually not possible for a program to recover
from Errors
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Inheritance hierarchy for class Throwable
Checked Exceptions
• Inherit from class Exception but not from RuntimeException
• Compiler enforces catch-or-declare requirement
• Compiler checks each method call and method declaration
• determines whether method throws checked exceptions.
• If so, the compiler ensures checked exception caught or declared in
throws clause.
• If not caught or declared, compiler error occurs.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Unchecked Exceptions
• Inherit from class RuntimeException or class Error
• Compiler does not check code to see if exception caught or declared
• If an unchecked exception occurs and not caught
• Program terminates or runs with unexpected results
• Can typically be prevented by proper coding
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Java Exception Hierarchy
• catch block catches all exceptions of its type and subclasses of its type
• If there are multiple catch blocks that match a particular exception type, only
the first matching catch block executes
• Makes sense to use a catch block of a superclass when all catch blocks for
that class’s subclasses will perform same functionality
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
finally Block
• Consists of finally keyword followed by a block of code enclosed in curly
braces
• Optional in a try statement
• If present, is placed after the last catch block
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
finally Block
• Executes whether or not an exception is thrown in the corresponding try
block or any of its corresponding catch blocks
• Will not execute if the application exits early from a try block via method
System.exit
• Typically contains resource-release code
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Using finally
• View program
• Re-throw of exception
• Code for throw exception
• Blocks using finally
• Suggestion
• Do not use a try block for every individual statement which may cause
a problem
• Enclose groups of statements
• Follow by multiple catch blocks
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Sequence of Events for finally clause
Preceding step
try block
throw
statement
unmatched catch
matching catch
unmatched catch
next step
finally
UNIT-III Event Handling & DEM
• Java uses an Event Delegation Model.
• Every time a user interacts with a component on the GUI, events are
generated.
• Events are component-specific.
• Events are objects that store information like
• the type of event that occurred,
• the source of the event,
• the time of an event to name a few.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Event Delegation Model
• Once the event is generated, then the event is passed to other objects which
handle or react to the event, thus the term event delegation.
• The objects which react to or handle the events are called event listeners.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Three Players
• Event source which generates the event object
• Event listener which receives the event object and handles it
• Event object that describes the event
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Registering Listeners
• By having a class implement a listener interface, it can contain code to
handle an event.
• However, unless an instance of the class is registered with the component ,
the code will never be executed. (Common novice error.)
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
A Few More Java Events
• FocusEvent – component gains or loses focus
• MouseEvent – mouse is moved, dragged, pressed, released or clicked
• WindowEvent– window is iconified, deiconified, opened or closed
• TextEvent – text is modified
• KeyEvent – key is pressed, depressed or both
• ContainerEvent – components are added or removed from Container
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Corresponding Listeners
• FocusEvent – FocusListener
• MouseEvent – MouseListener, MouseMotionListener
• WindowEvent–WindowStateListener,WindowListener,
WindowFocusListener
• TextEvent – TextListener
• KeyEvent – KeyListener
• ItemEvent- ItemListener
• ContainerEvent – ContainerListener
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Methods for Registering Listeners
• JButton
• addActionListener(ActionListener a)
• addChangeListener(ChangeListener c)
• addItemListener(ItemListener i)
• JList
• addListSelectionListener(ListSelectionListener l)
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Adapter Classes
• In the previous implementation, we implemented four
empty methods.
• We can create a listener class that extends its
corresponding adapter class.
• Adapter classes provide the empty implementation of all
the methods in a listener interface
• We only need to override the method(s) whose behavior
we want to influence.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
UNIT-IV Servlet Request Dispatcher
• Forward a request from one servlet to another (or jsp).
• Have first servlet do some of the work and then pass on to another.
• Can even forward on to a static source like html
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
The Request Dispather
• The RequestDispatcher object is used to send a a client request to any
resource on the server
• Such a resource may be dynamic (e.g. a Servlet or a JSP file) or static (e.g.
a HTML document)
• To send a request to a resource x, use:
getServletContext().getRequestDispatcher("x")
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Request Dispatcher Methods
• void forward(ServletRequest request, ServletResponse response)
• Forwards a request from a Servlet to another resource
• void include(ServletRequest request, ServletResponse response)
• Includes the content of a resource in the current response
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Passing on Data
• 3 different ways to pass parameters for the forwarded Servlet or JSP
• Data that will be used only for this request:
request.setAttribute("key“,value);
• Data will be used for this client (also for future requests):
session.setAttribute("key“,value);
• Data that will be used in the future for every client
context.setAttribute("key", value);
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)

More Related Content

What's hot (18)

Classes and objects till 16 aug
Classes and objects till 16 augClasses and objects till 16 aug
Classes and objects till 16 aug
 
Corejava Training in Bangalore Tutorial
Corejava Training in Bangalore TutorialCorejava Training in Bangalore Tutorial
Corejava Training in Bangalore Tutorial
 
Oops in java
Oops in javaOops in java
Oops in java
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Static keyword ppt
Static keyword pptStatic keyword ppt
Static keyword ppt
 
C# by Zaheer Abbas Aghani
C# by Zaheer Abbas AghaniC# by Zaheer Abbas Aghani
C# by Zaheer Abbas Aghani
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
OOP with Java - Abstract Classes and Interfaces
OOP with Java - Abstract Classes and InterfacesOOP with Java - Abstract Classes and Interfaces
OOP with Java - Abstract Classes and Interfaces
 
Classes and Objects
Classes and ObjectsClasses and Objects
Classes and Objects
 
Classes and objects in java
Classes and objects in javaClasses and objects in java
Classes and objects in java
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
OOP with Java - Continued
OOP with Java - Continued OOP with Java - Continued
OOP with Java - Continued
 
Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1
 
CLASS & OBJECT IN JAVA
CLASS & OBJECT  IN JAVACLASS & OBJECT  IN JAVA
CLASS & OBJECT IN JAVA
 
Lecture 4. mte 407
Lecture 4. mte 407Lecture 4. mte 407
Lecture 4. mte 407
 
Cso gaddis java_chapter6
Cso gaddis java_chapter6Cso gaddis java_chapter6
Cso gaddis java_chapter6
 
Java interview questions 2
Java interview questions 2Java interview questions 2
Java interview questions 2
 

Similar to JAVA PROGRAMMING

OPPS using C++
OPPS using C++ OPPS using C++
OPPS using C++ cpjcollege
 
Object oriented programming using BCA 209
Object oriented programming using BCA 209Object oriented programming using BCA 209
Object oriented programming using BCA 209cpjcollege
 
FRONT END DESIGN TOOL VB.NET
FRONT END DESIGN TOOL VB.NET FRONT END DESIGN TOOL VB.NET
FRONT END DESIGN TOOL VB.NET cpjcollege
 
Front End Design Tool VB.Net BCA 205
Front End Design Tool VB.Net BCA 205Front End Design Tool VB.Net BCA 205
Front End Design Tool VB.Net BCA 205cpjcollege
 
Software Testing
Software Testing Software Testing
Software Testing cpjcollege
 
Introduction to IT
Introduction to ITIntroduction to IT
Introduction to ITcpjcollege
 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingNithyaN19
 
Linux environment
Linux environment Linux environment
Linux environment cpjcollege
 
Production Management & Total Quality Management
Production Management & Total Quality ManagementProduction Management & Total Quality Management
Production Management & Total Quality Managementcpjcollege
 
Methods and constructors
Methods and constructorsMethods and constructors
Methods and constructorsRavi_Kant_Sahu
 
Digital electronics
Digital electronicsDigital electronics
Digital electronicscpjcollege
 
Introduction To Database Management System
Introduction To Database Management SystemIntroduction To Database Management System
Introduction To Database Management Systemcpjcollege
 
Introduction to VB Programming
Introduction to VB ProgrammingIntroduction to VB Programming
Introduction to VB Programmingcpjcollege
 
5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and Intefaces5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and IntefacesNilesh Dalvi
 
Object-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & ProgrammingObject-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & ProgrammingAllan Mangune
 
Introduction to operating system
Introduction to operating systemIntroduction to operating system
Introduction to operating systemcpjcollege
 
Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1PRN USM
 

Similar to JAVA PROGRAMMING (20)

OPPS using C++
OPPS using C++ OPPS using C++
OPPS using C++
 
Object oriented programming using BCA 209
Object oriented programming using BCA 209Object oriented programming using BCA 209
Object oriented programming using BCA 209
 
FRONT END DESIGN TOOL VB.NET
FRONT END DESIGN TOOL VB.NET FRONT END DESIGN TOOL VB.NET
FRONT END DESIGN TOOL VB.NET
 
Front End Design Tool VB.Net BCA 205
Front End Design Tool VB.Net BCA 205Front End Design Tool VB.Net BCA 205
Front End Design Tool VB.Net BCA 205
 
Software Testing
Software Testing Software Testing
Software Testing
 
Introduction to IT
Introduction to ITIntroduction to IT
Introduction to IT
 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overriding
 
Linux environment
Linux environment Linux environment
Linux environment
 
Production Management & Total Quality Management
Production Management & Total Quality ManagementProduction Management & Total Quality Management
Production Management & Total Quality Management
 
Methods and constructors
Methods and constructorsMethods and constructors
Methods and constructors
 
Digital electronics
Digital electronicsDigital electronics
Digital electronics
 
RDBMS
RDBMSRDBMS
RDBMS
 
Introduction To Database Management System
Introduction To Database Management SystemIntroduction To Database Management System
Introduction To Database Management System
 
Introduction to VB Programming
Introduction to VB ProgrammingIntroduction to VB Programming
Introduction to VB Programming
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and Intefaces5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and Intefaces
 
Object-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & ProgrammingObject-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & Programming
 
Ch5 inheritance
Ch5 inheritanceCh5 inheritance
Ch5 inheritance
 
Introduction to operating system
Introduction to operating systemIntroduction to operating system
Introduction to operating system
 
Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1
 

More from cpjcollege

Tax Law (LLB-403)
Tax Law (LLB-403)Tax Law (LLB-403)
Tax Law (LLB-403)cpjcollege
 
Law and Emerging Technology (LLB -405)
 Law and Emerging Technology (LLB -405) Law and Emerging Technology (LLB -405)
Law and Emerging Technology (LLB -405)cpjcollege
 
Law of Crimes-I ( LLB -205)
 Law of Crimes-I  ( LLB -205)  Law of Crimes-I  ( LLB -205)
Law of Crimes-I ( LLB -205) cpjcollege
 
Socio-Legal Dimensions of Gender (LLB-507 & 509 )
Socio-Legal Dimensions of Gender (LLB-507 & 509 )Socio-Legal Dimensions of Gender (LLB-507 & 509 )
Socio-Legal Dimensions of Gender (LLB-507 & 509 )cpjcollege
 
Family Law-I ( LLB -201)
Family Law-I  ( LLB -201) Family Law-I  ( LLB -201)
Family Law-I ( LLB -201) cpjcollege
 
Alternative Dispute Resolution (ADR) [LLB -309]
Alternative Dispute Resolution (ADR) [LLB -309] Alternative Dispute Resolution (ADR) [LLB -309]
Alternative Dispute Resolution (ADR) [LLB -309] cpjcollege
 
Law of Evidence (LLB-303)
Law of Evidence  (LLB-303) Law of Evidence  (LLB-303)
Law of Evidence (LLB-303) cpjcollege
 
Environmental Studies and Environmental Laws (: LLB -301)
Environmental Studies and Environmental Laws (: LLB -301)Environmental Studies and Environmental Laws (: LLB -301)
Environmental Studies and Environmental Laws (: LLB -301)cpjcollege
 
Code of Civil Procedure (LLB -307)
 Code of Civil Procedure (LLB -307) Code of Civil Procedure (LLB -307)
Code of Civil Procedure (LLB -307)cpjcollege
 
Constitutional Law-I (LLB -203)
 Constitutional Law-I (LLB -203) Constitutional Law-I (LLB -203)
Constitutional Law-I (LLB -203)cpjcollege
 
Women and Law [LLB 409 (c)]
Women and Law [LLB 409 (c)]Women and Law [LLB 409 (c)]
Women and Law [LLB 409 (c)]cpjcollege
 
Corporate Law ( LLB- 305)
Corporate Law ( LLB- 305)Corporate Law ( LLB- 305)
Corporate Law ( LLB- 305)cpjcollege
 
Human Rights Law ( LLB -407)
 Human Rights Law ( LLB -407) Human Rights Law ( LLB -407)
Human Rights Law ( LLB -407)cpjcollege
 
Labour Law-I (LLB 401)
 Labour Law-I (LLB 401) Labour Law-I (LLB 401)
Labour Law-I (LLB 401)cpjcollege
 
Legal Ethics and Court Craft (LLB 501)
 Legal Ethics and Court Craft (LLB 501) Legal Ethics and Court Craft (LLB 501)
Legal Ethics and Court Craft (LLB 501)cpjcollege
 
Political Science-II (BALLB- 209)
Political Science-II (BALLB- 209)Political Science-II (BALLB- 209)
Political Science-II (BALLB- 209)cpjcollege
 
Health Care Law ( LLB 507 & LLB 509 )
Health Care Law ( LLB 507 & LLB 509 )Health Care Law ( LLB 507 & LLB 509 )
Health Care Law ( LLB 507 & LLB 509 )cpjcollege
 
Land and Real Estate Laws (LLB-505)
Land and Real Estate Laws (LLB-505)Land and Real Estate Laws (LLB-505)
Land and Real Estate Laws (LLB-505)cpjcollege
 
Business Environment and Ethical Practices (BBA LLB 213 )
Business Environment and Ethical Practices (BBA LLB 213 )Business Environment and Ethical Practices (BBA LLB 213 )
Business Environment and Ethical Practices (BBA LLB 213 )cpjcollege
 
HUMAN RESOURCE MANAGEMENT (BBA LLB215 )
HUMAN RESOURCE MANAGEMENT (BBA LLB215 )HUMAN RESOURCE MANAGEMENT (BBA LLB215 )
HUMAN RESOURCE MANAGEMENT (BBA LLB215 )cpjcollege
 

More from cpjcollege (20)

Tax Law (LLB-403)
Tax Law (LLB-403)Tax Law (LLB-403)
Tax Law (LLB-403)
 
Law and Emerging Technology (LLB -405)
 Law and Emerging Technology (LLB -405) Law and Emerging Technology (LLB -405)
Law and Emerging Technology (LLB -405)
 
Law of Crimes-I ( LLB -205)
 Law of Crimes-I  ( LLB -205)  Law of Crimes-I  ( LLB -205)
Law of Crimes-I ( LLB -205)
 
Socio-Legal Dimensions of Gender (LLB-507 & 509 )
Socio-Legal Dimensions of Gender (LLB-507 & 509 )Socio-Legal Dimensions of Gender (LLB-507 & 509 )
Socio-Legal Dimensions of Gender (LLB-507 & 509 )
 
Family Law-I ( LLB -201)
Family Law-I  ( LLB -201) Family Law-I  ( LLB -201)
Family Law-I ( LLB -201)
 
Alternative Dispute Resolution (ADR) [LLB -309]
Alternative Dispute Resolution (ADR) [LLB -309] Alternative Dispute Resolution (ADR) [LLB -309]
Alternative Dispute Resolution (ADR) [LLB -309]
 
Law of Evidence (LLB-303)
Law of Evidence  (LLB-303) Law of Evidence  (LLB-303)
Law of Evidence (LLB-303)
 
Environmental Studies and Environmental Laws (: LLB -301)
Environmental Studies and Environmental Laws (: LLB -301)Environmental Studies and Environmental Laws (: LLB -301)
Environmental Studies and Environmental Laws (: LLB -301)
 
Code of Civil Procedure (LLB -307)
 Code of Civil Procedure (LLB -307) Code of Civil Procedure (LLB -307)
Code of Civil Procedure (LLB -307)
 
Constitutional Law-I (LLB -203)
 Constitutional Law-I (LLB -203) Constitutional Law-I (LLB -203)
Constitutional Law-I (LLB -203)
 
Women and Law [LLB 409 (c)]
Women and Law [LLB 409 (c)]Women and Law [LLB 409 (c)]
Women and Law [LLB 409 (c)]
 
Corporate Law ( LLB- 305)
Corporate Law ( LLB- 305)Corporate Law ( LLB- 305)
Corporate Law ( LLB- 305)
 
Human Rights Law ( LLB -407)
 Human Rights Law ( LLB -407) Human Rights Law ( LLB -407)
Human Rights Law ( LLB -407)
 
Labour Law-I (LLB 401)
 Labour Law-I (LLB 401) Labour Law-I (LLB 401)
Labour Law-I (LLB 401)
 
Legal Ethics and Court Craft (LLB 501)
 Legal Ethics and Court Craft (LLB 501) Legal Ethics and Court Craft (LLB 501)
Legal Ethics and Court Craft (LLB 501)
 
Political Science-II (BALLB- 209)
Political Science-II (BALLB- 209)Political Science-II (BALLB- 209)
Political Science-II (BALLB- 209)
 
Health Care Law ( LLB 507 & LLB 509 )
Health Care Law ( LLB 507 & LLB 509 )Health Care Law ( LLB 507 & LLB 509 )
Health Care Law ( LLB 507 & LLB 509 )
 
Land and Real Estate Laws (LLB-505)
Land and Real Estate Laws (LLB-505)Land and Real Estate Laws (LLB-505)
Land and Real Estate Laws (LLB-505)
 
Business Environment and Ethical Practices (BBA LLB 213 )
Business Environment and Ethical Practices (BBA LLB 213 )Business Environment and Ethical Practices (BBA LLB 213 )
Business Environment and Ethical Practices (BBA LLB 213 )
 
HUMAN RESOURCE MANAGEMENT (BBA LLB215 )
HUMAN RESOURCE MANAGEMENT (BBA LLB215 )HUMAN RESOURCE MANAGEMENT (BBA LLB215 )
HUMAN RESOURCE MANAGEMENT (BBA LLB215 )
 

Recently uploaded

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 

Recently uploaded (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 

JAVA PROGRAMMING

  • 1. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) PAPER NAME: JAVA PROGRAMMING PAPER CODE: BCA 206 CLASS: BCA IVth Semester
  • 2. UNIT-I Inheritance and Class Hierarchies • Object-oriented programming (OOP) is popular because: • It enables reuse of previous code saved as classes • All Java classes are arranged in a hierarchy • Object is the superclass of all Java classes • Inheritance and hierarchical organization capture idea: • One thing is a refinement or extension of another Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 3. Inheritance and Class Hierarchies superclass subclass Summary
  • 4. Is-a Versus Has-a Relationships • Confusing has-a and is-a leads to misusing inheritance • Model a has-a relationship with an attribute (variable) public class C { ... private B part; ...} • Model an is-a relationship with inheritance • If every C is-a B then model C as a subclass of B • Show this: in C include extends B: public class C extends B { ... } Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 5. A Superclass and a Subclass • Consider two classes: Computer and Laptop • A laptop is a kind of computer: therefore a subclass variables of Computer and all subclasses additional variables for class Laptop (and its subclasses) methods of Computer and all subclasses additional Methods for class Laptop (and its subclasses)
  • 6. Illustrating Has-a with Computer public class Computer { private Memory mem; ... } public class Memory { private int size; private int speed; private String kind; ... } A Computer has only one Memory But neither is-a the other Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 7. Initializing Data Fields in a Subclass • What about data fields of a superclass? • Initialize them by invoking a superclass constructor with the appropriate parameters • If the subclass constructor skips calling the superclass ... • Java automatically calls the no-parameter one • Point: Insure superclass fields initialized before subclass starts to initialize its part of the object Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 8. Example of Initializing Subclass Data public class Computer { private String manufacturer; ... public Computer (String manufacturer, ...) { this.manufacturer = manufacturer; ... } } public class Laptop extends Computer { private double weight; ... public Laptop (String manufacturer, ..., double weight, ...) { super(manufacturer, ...); this.weight = weight; } } Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 9. Protected Visibility for Superclass Data • private data are not accessible to subclasses! • protected data fields accessible in subclasses (Technically, accessible in same package) • Subclasses often written by others, and • Subclasses should avoid relying on superclass details • So ... in general, private is better Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 10. Method Overriding • If subclass has a method of a superclass (same signature), that method overrides the superclass method: public class A { ... public int M (float f, String s) { bodyA } } public class B extends A { ... public int M (float f, String s) { bodyB } } • If we call M on an instance of B (or subclass of B), bodyB runs • In B we can access bodyA with: super.M(...) Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 11. Method Overloading • Method overloading: multiple methods ... • With the same name • But different signatures • In the same class • Constructors are often overloaded • Example: • MyClass (int inputA, int inputB) • MyClass (float inputA, float inputB) Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 12. Example of Overloaded Constructors public class Laptop extends Computer { private double weight; ... public Laptop (String manufacturer, String processor, ..., double weight, ...) { super(manufacturer, processor, ...); this.weight = weight; } public Laptop (String manufacturer, ..., double weight, ...) { this(manufacturer, “Pentium”, ..., weight, ...); } } Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 13. Overloading Example From Java Library ArrayList has two remove methods: remove (int position) • Removes object that is at a specified place in the list remove (Object obj) • Removes a specified object from the list It also has two add methods: add (Element e) • Adds new object to the end of the list add (int index, Element e) • Adds new object at a specified place in the list Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 14. Polymorphism • Variable of superclass type can refer to object of subclass type • Polymorphism means “many forms” or “many shapes” • Polymorphism lets the JVM determine at run time which method to invoke • At compile time: • Java compiler cannot determine exact type of the object • But it is known at run time • Compiler knows enough for safety: the attributes of the type • Subclasses guaranteed to obey Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 15. Interfaces vs Abstract Classes vs Concrete Classes • A Java interface can declare methods • But cannot implement them • Methods of an interface are called abstract methods • An abstract class can have: • Abstract methods (no body) • Concrete methods (with body) • Data fields • Unlike a concrete class, an abstract class ... • Cannot be instantiated • Can declare abstract methods Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 16. Abstract Classes and Interfaces • Abstract classes and interfaces cannot be instantiated • An abstract class can have constructors! • Purpose: initialize data fields when a subclass object is created • Subclass uses super(…) to call the constructor • An abstract class may implement an interface • But need not define all methods of the interface • Implementation of them is left to subclasses Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 17. Example of an Abstract Class public abstract class Food { public final String name; private double calories; public double getCalories () { return calories; } protected Food (String name, double calories) { this.name = name; this.calories = calories; } public abstract double percentProtein(); public abstract double percentFat(); public abstract double percentCarbs(); } Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 18. Example of a Concrete Subclass public class Meat extends Food { private final double protCal; ...; public Meat (String name, double protCal, double fatCal double carbCal) { super(name, protCal+fatCal+carbCal); this.protCal = protCal; ...; } public double percentProtein () { return 100.0 * (protCal / getCalories()); } ...; } Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 19. Example: Number and the Wrapper Classes Declares what the (concrete) subclasses have in common Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 20. Inheriting from Interfaces vs Classes • A class can extend 0 or 1 superclass • Called single inheritance • An interface cannot extend a class at all • (Because it is not a class) • A class or interface can implement 0 or more interfaces • Called multiple inheritance Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 21. UNIT-II EXCEPTION HANDLING Use try, throw, catch to watch for indicate exceptions handle How to process exceptions and failures. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 22. Overview • Exception • Indication of problem during execution • Uses of exception handling • Process exceptions from program components • Handle exceptions in a uniform manner in large projects • Remove error-handling code from “main line” of execution • A method detects an error and throws an exception • Exception handler processes the error • Uncaught exceptions yield adverse effects • Might terminate program execution Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 23. Overview • Code that could generate errors put in try blocks • Code for error handling enclosed in a catch clause • The finally clause always executes • Termination model of exception handling • The block in which the exception occurs expires • throws clause specifies exceptions method throws Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 24. Exception Handler Exception "thrown" here Exception handler Exception handler Thrown exception matched against first set of exception handlers If it fails to match, it is matched against next set of handlers, etc. If exception matches none of handlers, program is abandoned
  • 25. Terminology • Thrown exception – an exception that has occurred • Stack trace • Name of the exception in a descriptive message that indicates the problem • Complete method-call stack • ArithmeticException – can arise from a number of different problems in arithmetic Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 26. Terminology • Throw point – initial point at which the exception occurs, top row of call chain • InputMismatchException – occurs when Scanner method nextInt receives a string that does not represent a valid integer Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 27. Termination Model of Exception Handling • When an exception occurs: • try block terminates immediately • Program control transfers to first matching catch block • try statement – consists of try block and corresponding catch and/or finally blocks Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 28. Enclosing Code in a try Block • try block – encloses code that might throw an exception and the code that should not execute if an exception occurs • Consists of keyword try followed by a block of code enclosed in curly braces Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 29. Using the throws Clause • Appears after method’s parameter list and before the method’s body • Contains a comma-separated list of exceptions Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 30. Using the throws Clause • Exceptions can be thrown by statements in method’s body of by methods called in method’s body • Exceptions can be of types listed in throws clause or subclasses Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 31. Example: Handling ArithmeticExceptions and InputMismatchExceptions • With exception handling • program catches and handles the exception • Example • Allows user to try again if invalid input is entered (zero for denominator, or non-integer input) Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 32. Sequence of Events for throw Preceding step try block throw statement unmatched catch matching catch unmatched catch next step
  • 33. Sequence of Events for No throw Preceding step try block throw statement unmatched catch matching catch unmatched catch next step
  • 34. When to Use Exception Handling • Exception handling designed to process synchronous errors • Synchronous errors – occur when a statement executes • Asynchronous errors – occur in parallel with and independent of the program’s flow of control • Avoid using exception handling as an alternate form of flow of control. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 35. Java Exception Hierarchy • Superclass Throwable • Subclass Exception • Exceptional situations • Should be caught by program • Subclass Error • Typically not caught by program • Checked exceptions • Catch or declare • Unchecked exceptions Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 36. Java Exception Hierarchy • All exceptions inherit either directly or indirectly from class Exception • Exception classes form an inheritance hierarchy that can be extended Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 37. Java Exception Hierarchy • Class Throwable, superclass of Exception • Only Throwable objects can be used with the exception-handling mechanism • Has two subclasses: Exception and Error • Class Exception and its subclasses represent exception situations that can occur in a Java program and that can be caught by the application • Class Error and its subclasses represent abnormal situations that could happen in the JVM – it is usually not possible for a program to recover from Errors Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 38. Inheritance hierarchy for class Throwable
  • 39. Checked Exceptions • Inherit from class Exception but not from RuntimeException • Compiler enforces catch-or-declare requirement • Compiler checks each method call and method declaration • determines whether method throws checked exceptions. • If so, the compiler ensures checked exception caught or declared in throws clause. • If not caught or declared, compiler error occurs. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 40. Unchecked Exceptions • Inherit from class RuntimeException or class Error • Compiler does not check code to see if exception caught or declared • If an unchecked exception occurs and not caught • Program terminates or runs with unexpected results • Can typically be prevented by proper coding Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 41. Java Exception Hierarchy • catch block catches all exceptions of its type and subclasses of its type • If there are multiple catch blocks that match a particular exception type, only the first matching catch block executes • Makes sense to use a catch block of a superclass when all catch blocks for that class’s subclasses will perform same functionality Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 42. finally Block • Consists of finally keyword followed by a block of code enclosed in curly braces • Optional in a try statement • If present, is placed after the last catch block Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 43. finally Block • Executes whether or not an exception is thrown in the corresponding try block or any of its corresponding catch blocks • Will not execute if the application exits early from a try block via method System.exit • Typically contains resource-release code Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 44. Using finally • View program • Re-throw of exception • Code for throw exception • Blocks using finally • Suggestion • Do not use a try block for every individual statement which may cause a problem • Enclose groups of statements • Follow by multiple catch blocks Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 45. Sequence of Events for finally clause Preceding step try block throw statement unmatched catch matching catch unmatched catch next step finally
  • 46. UNIT-III Event Handling & DEM • Java uses an Event Delegation Model. • Every time a user interacts with a component on the GUI, events are generated. • Events are component-specific. • Events are objects that store information like • the type of event that occurred, • the source of the event, • the time of an event to name a few. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 47. Event Delegation Model • Once the event is generated, then the event is passed to other objects which handle or react to the event, thus the term event delegation. • The objects which react to or handle the events are called event listeners. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 48. Three Players • Event source which generates the event object • Event listener which receives the event object and handles it • Event object that describes the event Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 49. Registering Listeners • By having a class implement a listener interface, it can contain code to handle an event. • However, unless an instance of the class is registered with the component , the code will never be executed. (Common novice error.) Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 50. A Few More Java Events • FocusEvent – component gains or loses focus • MouseEvent – mouse is moved, dragged, pressed, released or clicked • WindowEvent– window is iconified, deiconified, opened or closed • TextEvent – text is modified • KeyEvent – key is pressed, depressed or both • ContainerEvent – components are added or removed from Container Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 51. Corresponding Listeners • FocusEvent – FocusListener • MouseEvent – MouseListener, MouseMotionListener • WindowEvent–WindowStateListener,WindowListener, WindowFocusListener • TextEvent – TextListener • KeyEvent – KeyListener • ItemEvent- ItemListener • ContainerEvent – ContainerListener Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 52. Methods for Registering Listeners • JButton • addActionListener(ActionListener a) • addChangeListener(ChangeListener c) • addItemListener(ItemListener i) • JList • addListSelectionListener(ListSelectionListener l) Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 53. Adapter Classes • In the previous implementation, we implemented four empty methods. • We can create a listener class that extends its corresponding adapter class. • Adapter classes provide the empty implementation of all the methods in a listener interface • We only need to override the method(s) whose behavior we want to influence. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 54. UNIT-IV Servlet Request Dispatcher • Forward a request from one servlet to another (or jsp). • Have first servlet do some of the work and then pass on to another. • Can even forward on to a static source like html Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 55. The Request Dispather • The RequestDispatcher object is used to send a a client request to any resource on the server • Such a resource may be dynamic (e.g. a Servlet or a JSP file) or static (e.g. a HTML document) • To send a request to a resource x, use: getServletContext().getRequestDispatcher("x") Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 56. Request Dispatcher Methods • void forward(ServletRequest request, ServletResponse response) • Forwards a request from a Servlet to another resource • void include(ServletRequest request, ServletResponse response) • Includes the content of a resource in the current response Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 57. Passing on Data • 3 different ways to pass parameters for the forwarded Servlet or JSP • Data that will be used only for this request: request.setAttribute("key“,value); • Data will be used for this client (also for future requests): session.setAttribute("key“,value); • Data that will be used in the future for every client context.setAttribute("key", value); Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)