You are on page 1of 60

LANGUAGES:

Generation of Languages.
Monolithic Languages
Procedure Oriented Languages
Structured Programming Languages
Object Oriented Languages.

Monolithic Languages: The language that doesn’t support user-defined functions is called
monolithic languages.
Ex: Assembly Language.

Procedure oriented Languages: These languages support user-defined functions.


Ex: Fortran etc
Structured Programming Languages: the languages that enable program to divide the
project into small modules(programs) and each module further divided into functions and all
modules joined together for running as a project.
Ex: C

OOPS:
Object Oriented Programming System. This enables the project divided into modules; each
module further divided into objects and further each object into functions.
For working with oops one should have knowledge of two things.

1. class

2. object

Basic terms :

Reference : a name declared for a class that has no memory is called a referece.

Instance : memory allocated for a class that has no name.

Object : when a reference and an instance are bound together , it becomes object.

Class : is defined an combination of features that an object should possess. It is also called
ADT (Abstract Data Type) , simply user defined data type. The class is like a blue print of
a concept.

Object : is defined as a named instance of the class. The object is created for a class and
when object is created, all the features declared with in the class are allocated with
memory into object.

We use a . DOT operator called period to access features of the object. Ex :


Obj.feature

** java is dynamic. Each feature must be allocated with memory dynamically with the
keyword “new”.

Concepts of oops : any language to be oops, should satisfy some standards and these are
called oops concepts. They are:

1. abstraction
2. encapsulation
3. polymorphism
4. dynamic binding

Abstraction : is getting / gathering / summarizing. When we create an instance of the class,


all the features of the class are abstracted into object. With this, we get an advantage
that use need not know what is written in the class. With out knowing these background
details, user can simply use the object.

The abstraction is of two types.


a. data abstraction
b. functional abstraction.
The data abstraction is getting variables’ features to the object, and it is performed
individually for each object. Functional abstraction is getting memory of methods of the
class into object. This is done once and all objects of the same class share the same
memory, thus providing better memory management.

The abstraction looks as below :

If we call O1. disp(); “disp() belongs to O1 is called”, is a wrong way of


understanding. We need to understand it as “ disp() is called for O1”

When we call a method for an object, The objects puts itself into the method
definition and gets processed, the updated values are stored back in variables memory (data
abstraction)of the object.

*** when an object is put itself into a method, it is refered with the keyword “this” with in
that method definition.
this : is a keyword that refers the current object that placed itself into method.

Encapsulation: It is selective hiding of elements of the class.


This is used to specify how the class members are to be accessed through the object.
It is supported with key words “private”,”protected”,”public”. These key words are called
access specifiers.

Private: anything declared under private section, is accessible only with in that object.
Protected: the var.s declared under protected section can be accessed with in the same
class object and also with in the derived class object.
Public: every thing declared under public can be accessed any where in the program.
It is an exemplary program for understanding access specifiers.

C++ example :
class base
{
private : int pri;
protected : int pro;
public : int pub;
};

class der : public base


{
public :
void disp(){
cout<<pri;//raise error.
cout<<pro;
cout<<pub;
}
};

void main()
{
der d;
cout<<d.pri;//error
cout<<d.pro;//error
cout<<d.pub;
}

*****When an object is created for a class, the abstraction is performed as per he


specifications of encapsulation.
Polymarphism : is one thing existing in many forms. It is classified into two types.

1. compile time polymorphism : it is further classified into two types.


Functional polymorphism : it is defining more number of functions with same name with in a
class. i.e. the same function can have more than one definition (with same name with in a
class ) is called functional polymorphism.
It is generally said that we did function overloading. Functional overloading is not over
loading functions. But it is a concept of overloading runtime environment with the help of
functions.

** Functional overloading is what we do and the result is functional polymorphism.

The overloading is done in following ways :

 by passing different number of arguments.


 By passing different data type arguments
 By passing arguments in different sequence

Functional overloading can not be done by return type of method, or by changing argument
names.

It is said functional polymorphism, only if the all methods are declared with same name and
with in ONE class. If they are defined in different classes, then it is not polymorphism.

Operational polymorphism: it is a concept of assigning a new process to an operator. As with


this, the basic meaning of the operator gets changed, it is not supported by java. But it is
supported in C++.

Java has built in operational polymorphism implemented for + operator for string
concatenation.

So it can be said that java has no user level operational polymorphism.

2. Runtime polymorphism : it is dynamic binding and will be discussed after inheritance


inheritance : it is a concept of getting features of a class to another. it cna be understood
in different ways.

getting features of a class to another.....

creating a new class as of existing class....

extending features of existing class with a new class....

in java the inh., is implemented with the keyword "extends".

when inh is implemented, the class giving features is called base class or super class and the
class getting features is called derived class or child class.

->how to access features?


with base object we can access only base class features. with derived object we can
access both base and derived class features.

base features can be used with both base and derived objects. derived features can
be used only with derived object.

Ex :

class B1
{
int x=5;
}

class D1 extends B1
{
int y=10;
}

class I1
{
public static void main(String a[])
{
B1 b=new B1();
System.out.println(b.x);
System.out.println(b.y); //error
D1 d=new D1();
System.out.println(d.x);
System.out.println(d.y);

}
}
--------------------

-> how constructors behave?


when base instance created, base const gets called and when derived class is instantited,
first base const gets called and then derived const , as unless base memory existing, it can
not be extended.

Ex :
class B3
{
B3()
{
System.out.println("base");
}
}

class D3 extends B3
{
D3()
{
System.out.println("der");
}

class I3
{
public static void main(String a[])
{
New B3(); // only base const
new D3(); //first base const and then der const
}
}

-------------------------

-> how to access features with objects :


derived features can be accessed only with derived object. base features can be
accessed with base object as well as with derived object. but with derived object, we can
access base features in two ways.

1. we can call base method directly with derived object. ex: dobj. bdisp();
2. we can call derived method with derived object and make a call of base method in
derived method definition directly.

Ex :
class B4
{
public void bdisp()
{
System.out.println("base");
}
}

class D4 extends B4
{
public void ddisp()
{
bdisp();
System.out.println("der");
}

class I4
{
public static void main(String a[])
{
D4 b=new D4();
b.ddisp();

}
}

and also calling setSize() etc in our class after extending from Frame.

---------------------------

-> over riding? it is a concept of defining a method in derived class that is already defined in
base class. i.e. both base and derived methods have same name. when derived re-defines
base method, it is said that the derived class is OVERRIDING the specific method of base
class.
when overriding is implemented, if the method is called with base object, then base method
definition executes and when called with derived object, derived method definition
executes.

Ex :
class B5
{
public void disp()
{
System.out.println("base");
}
}

class D5 extends B5
{
public void disp()
{
System.out.println("der");
}

class I5
{
public static void main(String a[])
{
B5 b=new B5();
b.disp(); //base’s disp

D5 d=new D5();
d.disp();//der ‘s disp

}
}

--------------------

-> when inh is implemented, and when method overriding is implemented, then, if we get a
requirement of executing both processes..... then?
---> we can not call base method directly with derived object.
( because local has higher priority local (der) method executes. )
---> we can not call base method in derived method definition. ( because local has higher
priorioty, the local method calls local method and develops infinite recursion).
---> here comes into picture a new keyword "super", used to refer IMMEDIATE base class
features in DER class.

class B5
{
public void disp()
{
System.out.println("base");
}
}

class D5 extends B5
{
public void disp()
{
Super.disp();
System.out.println("der");
}

class I5
{
public static void main(String a[])
{
D5 d=new D5();
d.disp();

}
}

*** SUPER : can be used to refer IMMEDIATE base class features in DERIVED class.

the super can also be used to call a specific constructor of immediate base class as super().

import java.awt.*;

class MF41 extends Frame


{
MF41()
{
super("hello");
setSize(400,300);
setLocation(200,100);
setVisible(true);
}

public static void main(String a[])


{
new MF41();
}
}
//now the frame object gets a title on to title bar.
--------------------------------
Abstract classes and interfaces :

-> why overriding? to make sure the same kind of process is always identified with same
name.

-> HOW to make sure ? java has "abstract classes" and "interfaces" to make sure
programmer maintains standard method names in his programs / classes.

abst classes :

a class is made as abst class by placing atleast one abst method in it.
a method is said to be abst method if it is declared with keyword "abstract"

abst methods can not have body i.e. definition, and they must have only declarations.

abstract classes can not be instantiated, i.e. allocated with memory. so it can be
used only as base in inheritance.

when an abst class is declared as base, then in derived class, all the abst methods of
abst base class must be overriden in derived class, unless which derived class can not be
instantiated.

THUS making sure, programmer maintains standard method names.

abstract classes can also have non-abst methods.

when we (team leader) need programmers to maintain standard method names in their
classes, then we declare those methods as abst methods in in abst base class, and when we
need same process to be done in all derived class, then we define those methods as non-abst
(normal) methods with definitions in our abst class.

based on number of classes participating in inheritance, we can have simple classifications of


inheritance.

single inheritance : 1-1


multi-level inh : 1->1->1
hierarchical inh : 1->2 or more
multiple :- 2 or more -> 1 (supported in C++, not in java)
hibride : mixture of any two.

java does not support multiple inheritance of classes as it is a meaningless concept. class MF
extends Button, Frame .... the MF can not behave like Button as well as Frame at a time. so
java doesn't support multiple inh of classes.
( it is not at all a concept that c++ has dimond inh problem and to overcome that problem,
java is made as it wont support multiple inh. as in C++ the virtual inh is used in that case, so
it is not at all a problem).

interfaces : are something like abst classes in their purpose. (to makse sure programmer
maintains standard method names in his classes).

interface is defined with keyword "interface" instead of "class".


iunterface methods are by default abstract.
interfaces can not be instantiated, so can be used as bases in inh.
interfaces can be used as base with keyword "implementes".

when an interface is implemented, we must override all the methods of the interface, unless
which the derived class is not compiled.

java supports multiple inh of interfaces.

ex :
interface abc
{
public void disp();
}

class bca implements abc


{
here we must override disp()
}

---------------------

dynamic binding : is a concept of assigning derived class instance to base class reference
during running of program.

when derived instance assigned to base reference, the base reference behaves like derived
object. is a type of polymarphism. (run time PM).

when DB is implemented, and when a method is called, the derived over ridden method is
executed whose memory is assigned to base refernece.
When dynamic binding is implemented, ie. When derived method is assigned to base
reference, we can call only over ridden methods. We can not call derived class independent
methods with base reference.
-----------
in C++, assinging derived memory to base pointer.
in C++, when DB is implemented, and a function is called with base pointer, the base
class function executes (unlike in java). , here to make sure, when DB is implemented, and a
function is called with ebase pointer, and we need derived over ridden function executing,
then we must declare base class function as "virtual function".

History:

It is developed by SUN Micro systems. (Sanford


University networks) in 1992, and it was named “OAK”. In
1995 it was released with the name java. As the java is
its 2nd name, it got started calling as java2. Java is a
French word that means multi purpose.
It is actually developed for electronic programming.
Because of its platform independency, it is used much for
internet programming.

We need to install java software of a specific type on the


particular OS. When java is installed on system, it loads
JRE. The JRE includes two components.
1) API
2) JVM.

The java API (Application Programming Interface)


includes number of packages, and each package consists of
number of classes. The API is nothing but the Library like.
The API also includes java compiler, and other RE
components.
In C, 1st compiler converts source code into
intermediate code that can run on the OS on which it is
generated.
But the javac generates byte code. The Byte code is
JVM Specific. That can run on any JVM.
The C ‘s 2nd compiler takes input of .obj file
generated on same OS.
But the JVM is capable of taking input of byte code
generated by javac (irrespective of OS) and converts into
local code.
JVM Architecture

Parts of JVM
1. Byte Code Verifier: this is a sw mechanism, that checks
whether the IC passed to JVM is generated by a proper javac
OR not. The verification is done with the signature made by
the javac. This works as a firewall.
Firewall is nothing but a sw filter which will not permit
unauthorised programs to use system resources. (to provide
security). The JVM makes java as secured.
2. JDB: this is Java De Bugger. Debugging is a process of
identifying logical errors and rectifying them.
This JDB makes java as Robust (perfect / healthy)
The JVM includes one interpreter and one compiler.
The actual mechanism placed first was interpreter. To
provide high speed of conversion of IC into LL code, a
compiler is placed with in JVM.
The compiler with in JVM is called JIT (Just In Time)
compiler. When a program is executed with the command java
<classname>, the java command invokes the JVM, the byte
code passes through the byte code verifier-> JDB and
through the JIT.
NOTE: at a time either interpreter can be used OR JIT can
be used.
The default converter is JIT compiler. We can also
switch of JIT compiler to use the interpreter.
NOTE: Default is JIT compiler.
Interpreter converts line after line and compiler at
once. Interpreter will not generate a file but compiler
generates a file.
In JVM the JIT COMPILER is used. There must be a file
generated.
1. But generating a LL code file is meaning less in
java.
2. If LL Code is available, it can be read and
understood about its technology, which leads to insecurity
of technology.
So the JVM when uses JIT and convert byte code into
native code, (as the JVM works as mini OS, and resource
management is done by itself), the JVM will not let native
code written to Hard disk as a file.

Program development:
Programming is nothing but giving instructions to the
computer to fulfill the requirement of the users.
If remember the basic functionality of the system, the
system takes input, do process and gives output. This is
the functionality need to be remembered by user. But as a
programmer, we need to give instructions to the system to
take input from user, do required process and also we must
give instructions to the system to produce output to the
user.

When we (programmer) develop a program, we must


concentrate on three things.

1. Managing user interface : This is nothing but


providing interactivity between user and system. The
interactivity is nothing but taking input and giving
output.

2. Data storage : when user gives input we (the


programmer) need to reserve some memory (variables)
and store data temporarily during running of
program. So data storage is managed using variables.

3. Process : it is carried out with the help of


Operators, like +, -, * etc.

java api is called "java" and it has number of sub packages. each package incldues
number of classes.

io : has classes for input output management.

lang : has classes for java language basic features. this package is automatically
imported to all programs. so we need not import this explicitly.
net : has classes for networked applications.

rmi : for client-server programs.

util : has classes for basic utilkities like working with data structures, (stacks,
queues, linked lists etc) and has classes for data, time management etc.

awt : this is abstract windowing toolkit is a package that has classes for GUI
development.

constructor :

is a special method that has same name of the class name and will be invoked
automatically when the class is instantiated (allocated with memory with new).

as this method is used to construct memory for member references of the


class, it is called a constructor.

constructors can not return any values and it has no return type.

Frame :
this class provides a base container onto which otehr components cna be
added with.

classes hierarchy :
Object -> Component -> Container -> Window -> Frame

const :
Frame();
Frame(String title);

methods :
setSize(int w, int h)
setLayout() :
setVisible(boolean) : if set to true the frame will
be visible

setLocation(int x, int y)
add( Component );
setResizable(boolean) default is true
setUndecorated(boolean) if set to true, removes
borders and titlebar.

remvoe(Component)
-----------

Label :

this class is used for labeling other components.

CH : Object -> Component -> Label

const :
Label()
Label(String txt)

methods :
getText()
setText(String)

----------
TextField : this class is used to provide a box in which user can type single lined
text.

CH : Object -> Component -> TextComponent -> TextField

cosnt :
TextField ()
TextField (int size)
TextField(String default_txt)
TextField (String def_txt, int size)

methods :
getText() : returns String
setText( String txt );
setEchoChar( char)
setEditable(boolean)
----------
Button : this class provides a push button.

CH : Object -> Component -> Button


cosnt :
Button()
Button(String label)

methods :
getLabel()
setLabel(String)
addActionListener()
-----------
Choice : this class provides a DROP DOWN list of ITEMs, used to provide multiple
items to user amongst which user can select only one.

CH :
Object -> Component -> Choice

const :
Choice();

methods :
add(String item)

getSelectedItem()
getSelectedIndex()

getItem(int index)
remove(int index)
removeAll()

---------
List : this class provides SCROLLABLE list of items amongst which user can seledct
either one or multiple.

CH :
Object -> Component -> List

const :
List()
List(int visible items)
List(int v_items, boolean multi_selection_mode)

methods :
add(String item)
getSelectedItem()
getSelectedIndex()

getItem(int index)
remove(int index)
removeAll()

getSelectedItems()
getSelectedIndexes()
-----------
TextArea : this class provides a box in which user can type multiple lines of text.

CH :
Object -> Component -> TextComponent -> TextArea

const :
TextArea()
TextArea(int r, int c)
TextArea(String def_txt, int r, int c)
TextArea(String def_txt, int r, int c, int scrollbars)

the int scrollbars are represented with built in static variables of the same class
viz.,

SCROLLBARS_NONE
SCROLLBARS_HORIZONTAL_ONLY
SCROLLBARS_VERTICAL_ONLY
SCROLLBARS_BOTH

methods:
getText()
setText(String)
append(String)

Checkbox : used to provide a square shaped box to user with a label. it is generally
used to provide multiple options to user amongst which user can select many.

const :
Checkbox()
Checkbox(String label)
Checkbox(String label, boolean default_selection)
Checkbox(Str lab, bool def_sel, CheckboxGroup obj)

methods :
setState(boolean)
getState();
---------

radio buttons : the java.awt has no special clas to manage radio buttons.

we can use the class CheckboxGroup to turn check boxes into radio buttons.
ex : MCB.java
----------

Panel : is an invisible container, that has no borders and title bar.

this is used to group other components together. its size is increased based
on number of components added to it.

const :
Panel()
methods :
setLayout(), add( Component )

-----------
Dialog :
is one that when raised from an application will not permit user to interact
with application from which it is raised unless user responds to it.

const :
Dialog(Frame instance, String title, boolean model)

method:
al methods are like that of a Frame object.

---------
working with menus :

java.awt has three classes to work with menus .

MenuBar : used to provide a bar onto which Menu objects can be added with.
this can be set to Frame using a method setMenuBar() of Frame class.

MB will be visible only when atleast one Menu object is added to it.

const :
MenuBar();

methods :
add(Menu obj);

Menu : used to group MenuItem objects together.

const :
Menu();
Menu(String label);

methods :
add(Menuitem obj);
add(Menu obj) : to develop sub menus
addSeparator();

MenuItem : used to provide each menu option to user.


const :
Menuitem()
Menuitem(String label)

the menu item objects raise action events.

Font : this class is used to control font specifications.

const :
Font("String font name", int STYLE, int size);

int style is specified with built in static variables viz., PLAIN,BOLD, ITALIC
etc.

font can be set to any GUI component like, Button, Label etc with a method
setFont(Font obj) of Component class.

awt components doesnt support all font types.

-----------
Color : this class is sued for color specifications.

the colors are combination of three basic colors red, green and blue. (RGB).

cosnt :
Color(int r, int g, int b)

the color class has built in static objects of same class to represent
standard colors like, white, black, blue, green, orange, etc (14 obj).

colors can be set to any component with the methods setBackground() or


setForeground()

Layout managers :

layout is a concept related with arrangement of the components on the


container.

java.awt package ahs number of classes for component arrangement on


container.

FlowLayout : when this layout manager is set to container, the layout manager lets
components arranged like a flow.

const :
FlowLayout();

methods :
setVgap(int pixels);
setHgap(int pixels);
setAlignment(int alignment); where the alignment is specified with built in
static variables of the same class viz, LEFT, RIGHT and CENTER (being default).

****** this is default layaout manager for Panel and Applet classes.

-----------
CardLayout : use less , so we dont discuss this

------------
GridLayout :
grid is a thing that has same number of columns in each row.

this layotu manager divides the container into a logical grid of specified rows and
columns.

when this layout is set to container, the number of rows are fixed and
number of columns are tend to change based on number of components added to
container.

const :
GridLayout()
GridLayout(int rows, int cols).

methods :
setVgap() / setHgap()
------------
BorderLayout :

when this layout is set to container, the layout manager divides the
container into five parts.

when this layout is set to container, the add() takes a different form.

add(Component, int location)

the location is specified with buile in static variables viz., NORTH, EAST, WEST ,
SOUTH and CENTER.

*****
This is default layout manager for Frame and Dialog classes.

if we get a requirement of adding more than five components to Frame when


this layotu is set , then HOW?

we take help of Panels.

null layout : this is not a special layout manager. when we remove all layout managers
from a container, it is said that we set null as laayout.

when null is set as layout, we must specify boundaries for each component
with the method setBounds(int x, int y, int w, int h) of Component class, unless
which the component will not be visible.
--------
GridBagLayout : this layout manager when set to container, divides the container
into a logical grid , where number of rows is equal to maximum number of
components added in a column.

when this layout is set to container, the add() takes a different form.

add(component, GridBagConstraints location)

the GC has number of variables to specify where to place component.

gridx : used to specify column number


gridy : used to specify row number
gridwidth : used to specify how many columns to be occupied by the component.
gridheight : no. rows to be occupied.

fill : used to specify how the component to be spread in given location, its values can
be specified with built in static variables of the same class viz., VERTICAL,
HORIZONTAL and BOTH

other than these 5 values, there are anotehr 9 values can be set to GC.

ipadx/ ipady, weightx/ weighty, anchor, Isets( top,left,bottom,right).

we use the first five.

---------
we write a user defined function to add components to container to reduce un
necesary code.

ex :

public void addC(Component cc, int r, int c, int w, int h)


{
gc.gridx=c;
gc.gridy=r;
gc.gridheight=h;
gc.gridwidth=w;
gc.fill=gc.BOTH;
add(cc,gc);
}
-------------

dynamic binding : is a concept of assigning derived class instance to base class


reference.

in this, the base reference behaves like derived object whose memory is allocated
to it.

DB is the example of run time polymarphism.

Event Handling
Event is defined as change of status. The change of status can be done either by
user (from user interface) or by changing a value.
The event handling can be performed with two different mechanisms, viz.
event delegation model and event association model.

The language VB supports Event Association Model. In this model, each


individual component is associated with a specific function. (The handling code is
generally placed as a function definition.) For ex., if there are two buttons placed
on User Interface, each button will be associated(linked) with a specific function.
In Event delegation model, whenever an event is raised, if the source
component is of similar type, same function will be called, i.e. the program control is
delegated to a particular method irrespective of the source component.
EVENT ASSOCIATION MODEL

B1_clicked() B2_clicked()
{ {
} }
EVENT DELEGATION MODEL
Irrespective of the source component,
the same method is called and this is even d
delegation model.
One_method_defined()
{
}

In event delegation model to maintain standard method names, we have


number of interfaces provided in java.awt.event package. Each type of java
component is capable of raising a specific type of event. For each type of event the
java.awt.event. Package has a specific interface, like for the events raised by
Button objects, the java.awt.event package has ActionListener interface.
When we we need to handle events for buttons, we must implement action
listener interface. When implementing AL, we must override the interface method.
In the program, when a button is clicked, irrespective of button name, label, the
over ridden method is called.
The java.awt.event. Package also has number of classes to handle events.
When any button is clicked, the same method is called, thus leading to
execute same functionality for all similar type of components. To execute different
code for different components, the event classes re used.
When a component raise an event, there are two things performed.
1. Appropriate event class is instantiated, stored with details (name) of the
component.
2. Appropriate interface’s overridden method is called, and the event class instance is
passed as argument.
The JRE has a very good event handling mechanism, such that, when the
event is raised, the component creates instance of appropriate event class, calls
over ridden method and passes the event instance as argument to the overridden
method.
All event classes have a method “getSource()” that returns name of the
component that is stored in the event instance, this can be used to develop user
required processes.
When we need a component to raise event, we must register the component
with its type listener. The registration of listener to the component is done with
the method “addTypeListener()”, where the Type is replaced with appropriate type.
Syntax : “addTypeListener(TypeListener object);
Ex : addActionListener( ActionListener obj);
as we can not create object for interface, we need to use them as bases in inh.
-------------------------------------------------------
Component Event Name/ Interface
Class name
--------------------------------------------------
Button ActionEvent ActionListener
Choice ItemEvent ItemListener
Frame/Dialog WindowEvent WindowListener
List
(single Click) ItemEvent ItemListener
(Double click) ActionEvent ActionListener
ActionEvent: button click, list item double click, hitting enter in text field
Item event : selecting an item in choice, list or checking a checkbox
Text event : text field , text area
Focus event : all GUI components (other than Label)
Mouse events : all gui components
abstract classes and interfaces can be instantiated by providing a definition with in
{ } and over riding required methods.

ex :

b.addActionListener( new ActionListener()


{
actionPerformed(...)
{
def
}
} );

-----------------
adapter classes :

as when we use window listener, we need to override all seven methods


though not required.

to overcome this problem, the java.awt evnet package has number of classes
called adapter classes.

for example, the class WindowAdapter is for WindowLisstener. it is an abstract


class. it implemented WindowListener and over ridden all seven methods with empty
definitions. we can override the methods that we require.

so adapters are used to reduce un-necessary coding for event handling.

WindowListener - WindowAdapter
KeyListener - KeyAdapter
MouseListener - MouseAdapter
MouseMotionListener - MouseMotionAdapter
FocusListener - FocusAdapter

errors :

the errors (english) are two types.

1. Error (technical term) : syntax errors are called errors.


2. Exception : logical erors are called exceptions.

the exceptions are two types.

a. compile time exceptions : the code that has hardware intearactivity always
throws exceptions. so we must handle it using try-catch OR by declaring the
method as it throws a specific excpetion, unless which the program will not be
compiled. these are called compile time exceptions.

b. run time excpetions : the exception thrown by JRE during running of


program ( based on data given input by user) are called runtime exceptions.

when an exception is thrown by JRE, the JRE terminatres the method


execution from the line that thrown exception.

the java has a very good handling mechanism to control when excception is
thrown.

it is supported with keywords try-catch-finally, throw and throws, amongst


which try-catch-finally are one set.

syntax :
try
{
code that is EXPECTED to
throw Exception
}
catch(TYPEException obj)
{
code that need to be executed when
ex. is thrown by JRE
}
finally
{
code that need to be executed when
ex. is throws and not handled.
}

TYPEException is catch() is replaced with apprpriate excepotion type class.


the java is capable of handling more than 800 types of exceptions.

each exception is represented with a class.

for ex :

NumberFormatException : when a non-numeric value is tried to be parsed.

2. ArithmeticException : when a division is done with ZERO

3. NullPointerException : when a reference is used with out instantiation.

4. ArrayIndexOutOfBoundsException :
5. StringIndexOutOfBoundsException :
6. MalformedURLException
ConnectException
SQLException
IOException
FileNotFoundException etc...

all these exception classes are derived from a class Exception that is derived from
Object.
----------
when an exception is thrown by JRE the method in which excpetion prone
statement existing (executed) that method terminates.

------------

when exception is throws by JRE, the JRE performs two tasks at a time.
creates an intsnace of appropriate exception type class , stores corresponding
message and the JRE calls catch() method and passes the ex. instance as argument.

a try must have atleast one catch or finally. a try can have any number of
catches, each handling a specific type of excpetion.

as Exception is abse class to all exception classes, if we write


catch(Exception e) then all exceptions are handled. so here finally becomes
optional.
as when we use catch(Excepotion e), we (programmer) will not be in a
position to provide diferent / corresponding messages to user. so it is always a good
practice of using number of catches.

--------
throws : is a keyword used to declare a method that it throws a specific exception
when we have nothing to do using try-catch.

simple : throws is alternate to try-catch.

throw : when we need to throw a specific excpetion, then we use throw.

ex :

throw new ArithmeticException();

IO Operations :

the basic IO operations in C are called standard input and standard output.
the same in oops is caled input stream and output stream.

the java.io package has number of classes to manage these streams. java can
handle more than 40 types of streams.

the java streams are two types:

1. low level stream : the streams that have hardware interactivity are called low
level streams. these streams work with ASCII code i.e. work with byte data type.
these classes are identified with a suffix InputStream / OutputStream.

2. high level streams : the streams that don't have hardware interactivity are
called high level streams. these work with unicode i.e. with char / string data type.
these classes are suffixed with words Reader / Writer.

for ex :
FileInputStream
FileOutputSTreasm
PrintStream ( object System.... out)
InputStream (object is System... in)
ByteArrayInputStream
PrintWriter
FileReader
FileWriter
BufferedReader
CharArrayReader

---------------

when we take input from KB, we must use the KB representing stream i.e. System.in.

but System.in reads data in byte format (ASCII format), so when user gives
input 'A' the System.in reads it as 65 and returns as int. so when it is displayed , it
shows 65 on screen but not 'A'.

so when we read data from KB,m we must convert / translate the low level data
(ASCII formatted data ) into high l;evel data (String format) and display to user.

so we use a high level stream object of class BufferedReader to read data in string
fromat from KB.

but we need a translator that translates ASCII formatted data into unicode
formatted data.

ex :
YOUR HAND ---- PATTA KARA --- PALA GINNE

ur hand is BR
PALA GINNE - System.in

now the PATTA KARA is a class InputStreamReader.

the ISR converts low level stream data into high level stream data.

so we can witre :

InputStreamReader isr= new InputStreamReader(System.in);

BufferedReader br=new BufferedReader( isr );


now the BR has a method readLine() that actually activates System.in.read()
and reads data from KB (till user hits ENTER).

br.readLine();

BufferedReader br=new BufferedReader( new


InputStreamReader(System.in) );

all streams throw IOException other than PrintStream (System.out)

-----------

when we develop a program/ project, we concentrate on three things.

1. developing UI : in case of C, we used CUI, in java we use awt, swings to develop


GUI.

2. process : is done with the help of operators, branching, loops, functions, event
handling etc.

3. data storage : is taken care by variables, arrays, pointers, structures, objects


etc.

but all these are managed with in RAM which is volatile. so to use data in
future, we can store data into hard disk.

the process of writing data to hard disk and reading data from hard disk is
called file processing / file handling.

Example program of notepad :


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

class MyNP extends JFrame implements ActionListener


{
JMenuBar mb;
JMenu fil;
JMenuItem ne,op,sv,sa,xi;
JTextArea ta;
MyNP()
{
Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
setSize(d.width,d.height-100);
ta=new JTextArea();
add( new JScrollPane(ta));

mb=new JMenuBar();
setJMenuBar(mb);
fil=new JMenu("File");
mb.add(fil);
ne=new JMenuItem("New");
op=new JMenuItem("Open");
sv=new JMenuItem("Save");
sa=new JMenuItem("Save As");
xi=new JMenuItem("Exit");

ta.setFont( new Font("comic snas ms",Font.PLAIN,18));

fil.add(ne);
fil.add(op);
fil.addSeparator();
fil.add(sv);
fil.add(sa);
fil.addSeparator();

fil.setMnemonic(KeyEvent.VK_F);
ne.setMnemonic(KeyEvent.VK_N);
op.setMnemonic(KeyEvent.VK_O);
sv.setMnemonic(KeyEvent.VK_S);
sa.setMnemonic(KeyEvent.VK_A);
xi.setMnemonic(KeyEvent.VK_X);

ne.addActionListener(this);
op.addActionListener(this);
sv.addActionListener(this);
sa.addActionListener(this);
xi.addActionListener(this);
fil.add(xi);
setVisible(true);
}

public static void main(String a[])


{
new MyNP();
}

public void actionPerformed(ActionEvent e)


{
if(e.getSource()==xi)
System.exit(0);
if(e.getSource()==ne)
ta.setText("");

if(e.getSource()==sa)
{
try{
FileDialog fd=new FileDialog(new Frame(), "Save As",
FileDialog.SAVE);
fd.setVisible(true);
String fn=fd.getDirectory()+fd.getFile();

FileOutputStream fout=new FileOutputStream(fn);


String data= ta.getText();
fout.write( data.getBytes() );
fout.close();

}catch(Exception ee){}
}

if(e.getSource()==op)
{
try{
FileDialog fd=new FileDialog(new Frame(), "Save As",
FileDialog.LOAD);
fd.setVisible(true);
String fn=fd.getDirectory()+fd.getFile();

FileInputStream fout=new FileInputStream(fn);


byte b[]=new byte[ fout.available() ];
fout.read( b );
ta.setText( new String(b) );
fout.close();

}catch(Exception ee){}
}

}
}
DBMS

when we develop a project, wqe concentrate on three things.

1. UI management

2. process

3. data storage : as variables, objects etc are managed with in RAM which is
volatile, we prefer storing data on disk in the form of a file.

buit there are many problems in managing data in files.

1. no data security
2.no proper sharing on network
3.no consistency
4. no data integrity
5. no data types.

over all there is no guarantee of data.

to overcome these problems a new technique of data management is developed


called DBMS (Data Base Management System).

the different DBMS products are :

Oracle, MS-Access, MS-SQL Server, MySQL, DB2, Foxpro, Dbase, Sybase,


Ingrece,
System - R (1st DBMS by IBM)

------

in a DBMS , the data is managed in a tabular format.


generation of DBMS :

1 G : flat file system (it is not a pure dbms , so no tabular format).

2. hierarchical model DBMS :


in this model, the first columns is linked to second , and second to third and
so on.

we can retrieve data from a table in the same sequence in which it is


created. we can not miss even a single column.

3. network model DBMS :

this is similar to hie. model. but when creating a table, we can establish a
network (link) between required coumns., so that we can either get data in sequence
or as network established.

4G > Relational model DBMS : (RDBMS)

in this model, each column is linked with every otehr column. so we can
etrieve data in desired sequence.

5g : Object relational model DBMS : we use clases and objects.

--------------------

taking eacmple of Oracle :

when a DBMS product is installe dinto system, there will be three


components installed into system.

1. Physical DB (a file existing on hard disk)

2. DB Engine ( this is actual sw mechanism that works as an interface


between DB UI and PDB). the DBE includes many parts amongst which two are
important (for programmers). a. ODBC, b. SQL a language

3. User Interface : from where user can pass commands.

Oracle is available in different versions and editions.


edition is for a specific purpose. the different editions are

1. personal edition : when this is installed into system, the system gets installed
with all three components. i.e. UI, DBE and PDB. but it is not sharable on network.

2. enterprise edition : this supports network. it has two sub editions.

a. server edition : when this is installed, it gets installed with all three
components. PDB, UI and DBE. the DBE of server edition is capable of getting
connected with DB client's DBE.

b. client edition : when this is installed into system, the system gets installed
with UI, DBE. (no pdb). the client's DBE is configured such that it communicates
with server's DBE, so that the data sent from cleint is stored on server's PDB.
--------

the configurtation done on client to work with a specific server is identified with a
name.

OR

the transactions performed from cleint to server are identified with a name called
TNS name (managed by Transaction Naming Service).

this TNS name is used while logging into DB environment.

the Oracle provides a login screen to work with Oracle DB.

the default user name is scott and its password is tiger. the third option in login
screen in HOST string which is to be given with this TNS name configured.

(here in arc the TNS is ora)

we use the language SQL to pass queries from UI to the DBE.

---------------

data types :

char : fixed length text data


varchar : variable length text data.

number : used for numeric data


sal number
sal number(5)
sal number(9,2)

date : for date and time management.


BLOB : Binary Large OBject (used to store multimedia data)

clob : character LOB : used to store stories medical reports etc.


-----------

when we need to work with a DB, we need to know 3 things.

1. create a table
2. load data into table
3. read data from table.

1. syn :

create table <table name> ( < field definitions> )

the field definition includes field name, its data type and constraints if any.

ex :
create table remp ( eid number, ename varchar2(20) ) ;

----------
2. load ata :

synm :
insert into <tablename> (<fieldnames> ) values ( <values>)

ex :
insert into remp(eid,ename) values(101,'aaa');

when we load data into all fields in the same sequence in which they are created,
then the field names is optional with table name.

insert into remp values( 102,'niveditha');


3. get data and see :

select <field names> from <table name>

when we need to retrieve all fields data we can use * instead of field anems.

select * from remp;

but for a programmer select * is a wrong practice.

so use select <field names> from remp;

-----------

create table emp(eid number, ename varchar2(20) );

insert into emp values( 101, 'aaa');

select eid,ename from remp;

----------
removing table :

drop table <table name>


----------
constraints :

1. primary key : this wont permit uiser to store duplicate values in a column.

--------------

where clause : used to retrieve data based on a


search criteria. (condition)

select * from remp where eid=102;

---------
foreign key : is a constraint used to let a field to be stored with specific data of
otehr table's PK.

the FK is established with a keyword "references".

****
there will be two tables.

each table has a PK

one table's PK is used as FK in other table.

the table that has PK (giving with) is called parent table

the table that has a field as FK is called child table.

-----------
ex :

create table rdept (did number primary key, dname varchar2(20) );


insert into rdept values(101,'admin');
insert into rdept values(102,'accounts');
insert into rdept values(103,'sales');

create table remp(eid number primary key, ename varchar2(20), sal number, dep
number references rdept(did) );

insert into remp values(101,'aaa',3000,101); //gets loaded


insert into remp values(102,'bbb',13000,104); //NOT gets loaded

****
we can get data of two tables like this :
ex:
select eid,ename,sal,dname from remp,rdept where dep=did

case 1 :

we created a table for emp data management :

EMP ( eid, ename, sal, skills)


data :
101 niveditha 30000 C,C++,java
102 swathi 40000 c,java,oracle
103 jyotsna 34000 c,oracle, DB2

and so on....

to get data of java known programmers :


if we type :
select * from emp where skills='java';

shall we get data?

NO.

as skills is varcahr data and data given is 'c,c++,java' as one string.

so when we store multiple values (as per user) as one value( as per DB), we can not
apply where clause on it.

so when we create a table, the table should not have multiple valued field.

---------------------
case 2 :
a:
when we stored data of emp like :

EMP( eid, ename,sal)

we could store data as

101 niveditha 30000


101 swathi 3000

which is wrong.

so we apply PK on eid.

b:

EMP( eid PK, ename, sal, dept)


101 nivedita 2000 admin
102 swathi 3000 washing cloths

is again wrong data.

as the dept name is not depending on PK, there is a chance of entering wrong data
that leads to data corruption.

so conclusion....

a table should have a PK, and all fields depending on PK.

------------
case 3 : a table should ot have TRANSITIVE dependency.

transitive dependency means, a field depending on PK and also depending on


other field.

----------------
when we develop a DB for a small enterprise, the DB will include from 20 to 400
tables and all tables are linked with each otehr with PK-FK.

we use a scientific approach for DIVIDING DATA into multiple tables and
establish relationship amongst them, to manage data with integrity.

this is called NORMALISATION

the different standards are called normal formations in short normal forms. . the
different NFs are

basic NFs :
1NF : a table must not have multi values attribute (field)
? we can not apply where clause

2NF : a table should have PK and all fields depending on PK.


? to overcome insertion/ updation and deletion anamolies ( problems)

3NF : no transitive dependency.


? to overcome insertion/ updation and deletion anamolies ( problems)

adv. NFs :
4NF
BCNF (*Boyece Codd NF)
5NF
DKNF (Domine key NF)

a DB is said to be a proper DB if all the tables are atleast in 3NF.

------------
OKA TABLE LONI OKA RECORD other table LONI ENNI RECORDS THO LINK
AYI VUNDI ANI CHEPPADAANNI WE CALL cardinalities.

the different cardinalities are :

1-M cardinality
M-1 cardinality

1-1 cardinality
M-M cardinality

EMP( M ) - DEPT( 1 )

croom( 1 ) - Stud( M )

SA( 1 )- Cust( M )

**
1 participating table's PK is used as FK in M participating table.

-------------------

when we divide data into multiple tables (as per rules), we say , we did normalisation.

but normalised data in normal for DB,not for user

so to show user data as he desire, we must get data from both tables by joining two
tables in a select query.

this colelcting dta from multiple tables (in a select query , using joins) is called
denormalisation.
---------
the SQL queries are classified into :

DDL :
data definition language commands >

create : used to create a table

alter : used to modify table structure.

drop : used to remove table

DML :
data manipulation language commands :

insert :

update :
syn :
update <tab> set <field> = <value>

delete :
syn :
delete from <tab>

with delete and update queries we must use where clause.

DQL : Data Query LaNGUAGE :

select : used to get data

TCS :
commit (lets data be updated into server's PDB)

rollback : (it is not undo, or cancel previous action).

the rollback cancels all transactions and takes DB to previously committed


state.

DAS : data administration statements. ( used by a DBA)


DB connectivity :

we must use drivers to establish connection from a java program to a DB.

the different drivers available are :

1. jdbc odbc bridge : this is given free with java software. this is managed by a
class JdbcOdbcDriver of the package sun.jdbc.odbc. this need to be loaded into
memory so that the program can make use of it.

2. pure java oriented driver : this is by sun micro systems, but one need to purchase
these to use.

3. net oriented driver : these are third party drivers. but these need to be
purchased .

4. oracle thin driver : provided by oracle incr. can be used to connect java with
oracle only.

5. mysql driver : my sql is a DBMS product. these drivers are used to connect java
with mysql only.

etc....
-------

the bridge is loaded with a static method forName() of the class java.lang.Class.

so the code is :

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

this method loads given class into memory, so that the program from which it is
loaded can make use of it.

----------

making use of the above jdbc odbc driver, we can establish a connection from java
to oracle.
every DB has a DBE. and DBE has number of components amongst which ODBC is
one. ODBC is open db connecticity, is a sw mechanism to which a program can be
connected with.
the DB is a different environment and java is different env.

so we take help of OS to give a name to ODBC of DBE and we refer that name in
our java program.

this name is given from start up-> settings -> control panel -> admin tools -> Data
Sources( ODBC) (open this program)....

give required name, TNS name and user name click on OK buttons.

this name is called DSN (Data Source Name), and it is used in java program
to establish connection.

------
URL standards :-

protocol : // where / what

here the : specifies that the data from RHS must be received as per
standards of LHS.

http: // gmail.com/...

now the data received from gmail is received as per standards of http.
------

the DriverManager has a static method getConnection() that established connection


from java program to the DSN mentioned.

code :

DriverManger.getConnection("jdbc:odbc:DSN", "user","pw");

odbc:dsn gets data from DSN given , as per standards of ODBC (DB
standards).

the jdbc:odbc lets the DB standard data be received as per java standards.

JDBC : Java DB Connectivity


this getConnection() establishes connection to the DSN specified using the above
loaded drivers. and this method returns the connection established as an instance
of Connection interface type.

so code :
Connection con=DriverManger.getConnection("....");

-------
the con has a method createStatement() that creates an instance of Statement
interface .

code :

Statement st=con.createStatement();

-----
the st has a method executeQuery() that converts string query into SQL query and
executes on DB. this method returns results as an instance of ResultSet interface.

code :
ResultSet rs=st.executeQuery("query");

the rs has two types of methods.

one for movement of rs .... next(), previous(), last() and first()

the other methods are used to getdata.... getInt(), getString() etc.

--------

1. create DSN

2. establish connection connection and get data.

code :
* load jdbc odbc driver
* establish connection
* create statement with con
* get data into rs using st
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con= DriverManager.getConnection("jdbc:odbc:DSN","ft2","ft2");

Statement st=con.createStatement();

ResultSet rs=st.executeQuery("select * from remp");

NETWORKING

it is a concept of connecting systems together to establish communication between


then and to share resources.

a system to be in network should have some standards OR should follow some rules
and regulations called protocols.

the basic protocols are :

IP : this is internet protocol that specifies that each system in network ust be
identified with a unique number called IP address.

the IP address is a 4 byte address where each byte is separated with a DOT

ex : 100.100.100.100

a typical ip address has two parts.

network address and host address. (ward no and door no. like).

the OS provides a facility to identify network address by masking it.

i.e. by using subnet mask we can identify network address.


as it is difficult to remember IP addresses of the systems, the OS provides
a facility to identify system with names.

TCP : Transmission control protocol. : this specifies that the data is divided into
small pieces called data packets and then transferred to receiver system.

the receiver system merges all DPs and represent to user as one file.
the TCP is connection oriented protocol. ie. when two systems are communicating as
per TCP standards, no third system can communicate with those two.

-------------

socket : is something to which something else can be connected with .

the sw sockets are two types.

1. server socket : can listen.

2. socket : is capable of transferring and receiving.

a system can have 65536 server sockets running on it, where each SS is
identified with a unique number called port number.

the port numbers from 0-1024 are reserved for OS.

other port numebrs like 8080 is reserved for apache server. 80 is reserved
for OS web server and so on.

we create stream objects from Socket class to transfer and receive data.

----------

ServerSocket :
cosnt : ServerSocket(int port no)

methods :
accept() creates a PA socket object for this SS

Socekt :
cosnt :
Socket(String system_name, int port no)

methods :
getInputStream()
getOutputStream()

import java.net.*;
import java.io.*;
class MySS1
{
public static void main(String a[])throws Exception
{
ServerSocket ss=new ServerSocket(8676);
Socket skt=ss.accept();

InputStream is=skt.getInputStream();
OutputStream os=skt.getOutputStream();
byte b[];
String data;
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));

while(true)
{
b=new byte[100];
is.read(b);
data=new String(b);
data=data.trim();
System.out.println("CLIENT:>"+data);

System.out.print("SERVER :>");
data=br.readLine();
os.write( data.getBytes() );

}
}
}
------------
import java.net.*;
import java.io.*;

class MySkt1
{
public static void main(String a[]) throws Exception
{
Socket skt=new Socket("laptop3",8676);

InputStream is=skt.getInputStream();
OutputStream os=skt.getOutputStream();
byte b[];
String data;
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));

while(true)
{
System.out.print("CLIENT :>");
data=br.readLine();
os.write( data.getBytes() );

b=new byte[100];
is.read(b);
data=new String(b);
data=data.trim();
System.out.println("SERVER:>"+data);

}
}
}

user defined packages :

we can develop user defined packages that includes all byte code files that are to
be produced to user.

we can create a pckage by placing a package statement in a program. and we


can make use of these packages by a simple import statement.

for example class A to be placed into a package and we use its object on class B.....

* class A program should have a package statement.


* class A must be public
* all methods / constructoirs must be public

*** when compiling class A , we use option -d with javac command

ex :
javac -d <path> A.java
---------
* class B program must have import statement.
* in class B we can create object of class A and call required methods of class A

***** when this is compiled, we use option -classpath with javac command.

ex : javac -classpath <path> B.java

when rtunnign class B, we use option -cp with command java.

ex :
java -cp . ; <path> B

-----------

javac -d <path> packedclass


javac -classpath <path> packusedclass
java -cp .; <path>packusedclass
---------------

when working with user defined packages, we can come to a conclusion that ...

we provide user with a user defined package (of project).


all classes in UDP must be public classes.
one program - one class -. that is public class and then the class name and program
name must be same.
---------------

encapsulation :

it is selective hiding of class members in object. it is supported with keywords


private, protected and public.

when no access specifier is given , the features are by default friendly.

when the access specifier is not mentioned, as the features are friendly, can be
used in current class, DERIVED CLASS IN CURRENT FOLDER, other classes in
current folder. CAN NOT be accessed in derived classes of other folders.
when protected specified, can be used in current class, DERIVED CLASS IN
CURRENT FOLDER, other classes in current folder. CAN also be accessed in
derived classes of other folders.

Thread :

it is processor utilisation time by a process is called a thread.

to work with threads, the java.lang package has a class Thread and an interface
Runnable.

the Thread has following features :

thread name : a thread can be identified with a name.

priority : priority DOES NOT refers sequence of execution. the priority refers
HOW MANY TIMES THE THREAD IS TO USE THE MICRO PROCESSOR WITH
IN GIVEN STIPULATED TIME.

thread group name :

Thread :

const :
Thread()
Thread(Thread obj)

methods :
sleep() : is a static method of Thread class that is used to suspend program
execution for specified number of milli seconds. this method throws
InterruptedException.

currentThread() : this is a static method used to get the instance of current


thread being executed.

setName(String) : used to change name of the thread.

setPriority(int) : used to set priority of the thread. priority can be between


1-10.
run() : this is actually derived from Runnable interface. when user creates a
class that extends Thread or implements Runnable , user must over ride this
method.

in general practice we prefer implementing Runnable than extending Thread.

com : communication file (it is an extension here)

ex :
command .com
format . com

yahoo.com, gmail.com , here com is commercial (it is commercial sites). like .com, we
have .org, .net etc...

in C/S modal the com is component object modal.

RMI :

when the client-server applications first developed, the applications were running
on COM technology
(COM =Component Object Modal).

in COM modal of working :

in this modal, there will be a server program (a class developed in ajva or c++), when
a client sends a reqauest an object of the server class is created and that object
manages the data processing for that client component.
if 10 clients connect to same server there will be 10 objects created for same
class. if million, then ......

in this technique of programming the server 's memory gets over loaded with
number of objects of same class. this leads to server system getting hung.

to overcome this problem, a new technique of C/S architecture developed callede


DCOM (Distributed COM)

in this modal, the server object by implementing multi threading, one object
responds for multiple clients.
the dcom developed by microsoft is called RPC and the same dcom of sun
microsystems is called RMI .

RPC : Remote Procedure Call

RMI : Remote Method Invocation.

in this both mechanisms, the method / function is defined in a system and called /
invoked in other systems.

---------------

after DCOM development, there were diferent protocols developed for server
working process.

CORBA : Common Object Request Broker Architecture.

SOAP : Simple Object Acess Protocol

Frameworks : the frame works developed by microsoft is called .Net and the Frame
works of java is called J2EE.
the J2EE .... servlets, JSPs, Enterprise java beans etc.

----------

in RMI technology.....

there will be a server program, and a client program. server program runs on
a server system and client runs on other system.

the server program is created with 2 assitants called SKEL program and
STUB program.

the skel of server is placed on server system and the stub is transferred to
cleint system.

the communication from clkient to server is as follow s:

clietn -> stub ------> skel -> server


and the otherwise is

server -> skel ------> stub -> client

the communication established between stub to skel is called marshalling and the
otehrwise communication from skel to stub is called un marshalling.

-------------

we define a function is server and call the function in client.

i.e. we must call a function in client that is already defined in server.

i.e. we must define a method in server that is expected to be called in client.

i.e. we must have same name to the method definition in server that is called in
client.

i.e. we must have standard method names maintained in RMI.

so we use a user defined interface in RMI programming.

the user defined interface will have method to be over riden in server program .
and this user def interface must be base to server program.

we make sure the user def interface extends a built in interface java.rmi.Remote
interface.

declare required methods in this user interface. and make sure all these methods
throws RemoteException
------

develop a server program that extends a class


java.rmi.server.UnicastRemoteObject ....
....that lets when one object created for server , it will implement multi threading
on its own and respond for mulktiple clients at a time.

and further make sure the server class implements user interface, so that the
server overrides the method to be called in client.
----------
develop a client class in which we can create object of .... server class so that we
can call the method. but if server object is copied onto cient, then the client itself
becomes server and there is no REMOTE in method calling.

so we create skel and stub programs from server and we try to capture stub of
server in client program. but as we can not user server class rerference, we copy
user interface .class file onto client, which is base to server, and declare a
reference of user interface and hold memory of stub with its base reference (user
interface) ... it is waht we called dynamic binding.
----------

the rmi programs run on rmi protocol. the java sw has a program called rmiregistry
that maintains rmi protocol.

it can be started with a command "start rmiregistry" from prompt.

---------

as we create a DSN in db connectivity ( a nick name given to ODBC) , we should give


a name to server instance running on server system. this name is refered in client
program.

this giving name and refering name can be done with static methods rebind() and
lookup() of Namning class of java.rmi package.

** all classes must be public classes


** server must have a public const., that throws RemoteException

You might also like