Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

Advance Programming

Lecture 1: 09-11-21 – University of Education Multan


 An abstract class is a class that is declared abstract—it may or may not
Abstract include abstract methods.
Classes  Abstract classes cannot be instantiated, but they can be sub-classed.
 Abstract class is used when you know something and rely on others for
what you don't know.
Abstract
Classes
 An abstract method is a method that is declared without an
implementation.
 abstract void moveTo();
 If a class includes abstract methods, then the class itself must be
declared abstract.
Abstract
Classes public abstract class GraphicObject
{
abstract void draw();
}
When an abstract class is sub-classed, the subclass usually provides
Abstract implementations for all of the abstract methods in its parent class.

Classes However, if it does not, then the subclass must also be


declared abstract.
Abstract
Classes
 Abstract classes have more use in real projects as on books. some
times project managers just provide the methods declaration and you
have to write code for the methods without modify the core syntax
Why Abstract provided by manager.
Classes?  So that is how an abstract class is use full. in simple class method
define, declared and coded in same time but not in abstract classes.
 Another reason for declaring a class as abstract is so that it can't be
instantiated. There are situations where you will have common
functionality that is shared between a number of classes, but by itself
Why Abstract that common functionality does not represent an object or represents
Classes? an incomplete object.
 In that case, you define the common functionality as abstract so that
it can't be instantiated.
 Abstract class usually supports an idea of the generalization and to
Why Abstract contribute from programmers to keep a quite little brain discipline by
designing multi-years projects because of they when include an
Classes? abstract methods have to describe an implementation.
Why Abstract  An Abstract Class is a partially assembled car in a crate that you have
to finish off to your own requirements.
Classes?
In the Java programming language, an interface is a reference type,
similar to a class, that can contain only constants, method signatures,
Interface default methods, static methods, and nested types.
Interfaces cannot be instantiated—they can only be implemented by
Interface classes or extended by other interfaces. Extension is discussed later in
this lesson.
Defining an interface is similar
Interface to creating a new class:
 Packages are used in Java in order to prevent naming conflicts, to
control access, to make searching/locating and usage of classes,
interfaces, enumerations and annotations easier, etc.
 A Package can be defined as a grouping of related types (classes,
Java Packages interfaces, enumerations and annotations ) providing access
protection and namespace management.
 Some of the existing packages in Java are −
 java.lang − bundles the fundamental classes
 java.io − classes for input , output functions are bundled in this
package
 // import the Vector class from util

 package. import java.util.vector;


Java Packages
 // import all the classes from util package

 import java.util.*;
Types of
packages:
Exception
 In Java, an exception is an event that disrupts the normal flow of
Handling in the program. It is an object which is thrown at runtime.
Java
 In Java, an exception is an event that disrupts the normal flow of
Exception the program. It is an object which is thrown at runtime.
Handling in  Exception Handling is a mechanism to handle runtime errors such
as ClassNotFoundException, IOException, SQLException,
Java RemoteException, etc.
Hierarchy of
Java Exception
classes
 Checked Exception
Types of Java  Unchecked Exception
Exceptions  Error
 Checked Exception
Types of Java  Unchecked Exception
Exceptions  Error
 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
Types of Java  The classes that inherit the RuntimeException are known as
Exceptions unchecked exceptions. For example, ArithmeticException,
NullPointerException, ArrayIndexOutOfBoundsException, etc.
Unchecked exceptions are not checked at compile-time, but they
are checked at runtime.
 3) Error
 Error is irrecoverable. Some example of errors are
OutOfMemoryError, VirtualMachineError, AssertionError etc.
Java
Exception
Keywords
Event  Events are a useful way to collect data about a user's
Handling interaction with interactive components of Applications.
 Event Listeners − An event listener is an interface in the View class
that contains a single callback method. These methods will be
called by the Android framework when the View to which the
listener has been registered is triggered by user interaction with
the item in the UI.
Event  Event Listeners Registration − Event Registration is the process
Handling by which an Event Handler gets registered with an Event Listener
so that the handler is called when the Event Listener fires the
event.
 Event Handlers − When an event happens and we have registered
an event listener for the event, the event listener calls the Event
Handlers, which is the method that actually handles the event.
Important Event Classes and Interface

Event Classes Description Listener Interface


ActionEvent generated when ActionListener
button is pressed,
menu-item is selected,
list-item is double
clicked
MouseEvent generated when MouseListener
Event mouse is dragged,
moved,clicked,pressed
Handling or released and also
when it enters or exit a
component
KeyEvent generated when input KeyListener
is received from
keyboard
ItemEvent generated when ItemListener
check-box or list item
is clicked
generated when value of textarea
TextEvent TextListener
or textfield is changed

generated when mouse wheel is


MouseWheelEvent MouseWheelListener
moved

generated when window is


WindowEvent activated, deactivated, deiconified, WindowListener
iconified, opened or closed

Event generated when component is

Handling ComponentEvent hidden, moved, resized or set


visible
ComponentEventListener

generated when component is


ContainerEvent ContainerListener
added or removed from container

generated when scroll bar is


AdjustmentEvent AdjustmentListener
manipulated

generated when component gains


FocusEvent FocusListener
or loses keyboard focus
Event Handler Event Listener & Description
OnClickListener()
This is called when the user either clicks or touches
or focuses upon any widget like button, text, image
onClick() etc. You will use onClick() event handler to handle
such event.

OnLongClickListener()
Event This is called when the user either clicks or touches
or focuses upon any widget like button, text, image

Handling onLongClick()
etc. for one or more seconds. You will use
onLongClick() event handler to handle such event.

OnFocusChangeListener()
This is called when the widget looses its focus ie.
user goes away from the view item. You will use
onFocusChange() onFocusChange() event handler to handle such
event.
OnFocusChangeListener()
This is called when the user is focused on the item and presses or
releases a hardware key on the device. You will use onKey() event
onKey() handler to handle such event.

OnTouchListener()
This is called when the user presses the key, releases the key, or any
movement gesture on the screen. You will use onTouch() event handler

Event onTouch() to handle such event.

Handling OnMenuItemClickListener()
This is called when the user selects a menu item. You will use
onMenuItemClick() onMenuItemClick() event handler to handle such event.

onCreateContextMenuItemListener()
This is called when the context menu is being built(as the result of a
sustained "long click)
onCreateContextMenu()
Event
Handling
Event
Handling

You might also like