Professional Documents
Culture Documents
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.
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.
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.
** 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
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.
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;
};
void main()
{
der d;
cout<<d.pri;//error
cout<<d.pro;//error
cout<<d.pub;
}
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.
Java has built in operational polymorphism implemented for + operator for string
concatenation.
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.
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);
}
}
--------------------
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
}
}
-------------------------
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.*;
-> 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.
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.
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).
when an interface is implemented, we must override all the methods of the interface, unless
which the derived class is not compiled.
ex :
interface abc
{
public void 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:
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.
java api is called "java" and it has number of sub packages. each package incldues
number of classes.
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.
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).
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 :
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.
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.
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
----------
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 :
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);
const :
Menu();
Menu(String label);
methods :
add(Menuitem obj);
add(Menu obj) : to develop sub menus
addSeparator();
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.
-----------
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).
Layout managers :
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.
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.
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.
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.
---------
we write a user defined function to add components to container to reduce un
necesary code.
ex :
in this, the base reference behaves like derived object whose memory is allocated
to it.
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.
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()
{
}
ex :
-----------------
adapter classes :
to overcome this problem, the java.awt evnet package has number of classes
called adapter classes.
WindowListener - WindowAdapter
KeyListener - KeyAdapter
MouseListener - MouseAdapter
MouseMotionListener - MouseMotionAdapter
FocusListener - FocusAdapter
errors :
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.
the java has a very good handling mechanism to control when excception is
thrown.
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.
}
for ex :
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.
--------
throws : is a keyword used to declare a method that it throws a specific exception
when we have nothing to do using try-catch.
ex :
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.
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
the ISR converts low level stream data into high level stream data.
so we can witre :
br.readLine();
-----------
2. process : is done with the help of operators, branching, loops, functions, event
handling 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.
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");
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);
}
if(e.getSource()==sa)
{
try{
FileDialog fd=new FileDialog(new Frame(), "Save As",
FileDialog.SAVE);
fd.setVisible(true);
String fn=fd.getDirectory()+fd.getFile();
}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();
}catch(Exception ee){}
}
}
}
DBMS
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.
1. no data security
2.no proper sharing on network
3.no consistency
4. no data integrity
5. no data types.
------
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.
in this model, each column is linked with every otehr column. so we can
etrieve data in desired sequence.
--------------------
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.
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).
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.
---------------
data types :
1. create a table
2. load data into table
3. read data from table.
1. syn :
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.
when we need to retrieve all fields data we can use * instead of field anems.
-----------
----------
removing table :
1. primary key : this wont permit uiser to store duplicate values in a column.
--------------
---------
foreign key : is a constraint used to let a field to be stored with specific data of
otehr table's PK.
****
there will be two tables.
-----------
ex :
create table remp(eid number primary key, ename varchar2(20), sal number, dep
number references rdept(did) );
****
we can get data of two tables like this :
ex:
select eid,ename,sal,dname from remp,rdept where dep=did
case 1 :
and so on....
NO.
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 :
which is wrong.
so we apply PK on eid.
b:
as the dept name is not depending on PK, there is a chance of entering wrong data
that leads to data corruption.
so conclusion....
------------
case 3 : a table should ot have TRANSITIVE dependency.
----------------
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.
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
adv. NFs :
4NF
BCNF (*Boyece Codd NF)
5NF
DKNF (Domine key NF)
------------
OKA TABLE LONI OKA RECORD other table LONI ENNI RECORDS THO LINK
AYI VUNDI ANI CHEPPADAANNI WE CALL cardinalities.
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.
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 >
DML :
data manipulation language commands :
insert :
update :
syn :
update <tab> set <field> = <value>
delete :
syn :
delete from <tab>
TCS :
commit (lets data be updated into server's PDB)
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 :-
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.
------
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.
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");
--------
1. create DSN
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();
NETWORKING
a system to be in network should have some standards OR should follow some rules
and regulations called protocols.
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
network address and host address. (ward no and door no. like).
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.
-------------
a system can have 65536 server sockets running on it, where each SS is
identified with a unique number called port number.
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);
}
}
}
we can develop user defined packages that includes all byte code files that are to
be produced to user.
for example class A to be placed into a package and we use its object on class B.....
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 :
java -cp . ; <path> B
-----------
when working with user defined packages, we can come to a conclusion that ...
encapsulation :
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 :
to work with threads, the java.lang package has a class Thread and an interface
Runnable.
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 :
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.
ex :
command .com
format . com
yahoo.com, gmail.com , here com is commercial (it is commercial sites). like .com, we
have .org, .net etc...
RMI :
when the client-server applications first developed, the applications were running
on COM technology
(COM =Component Object Modal).
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.
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 .
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.
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 established between stub to skel is called marshalling and the
otehrwise communication from skel to stub is called un marshalling.
-------------
i.e. we must have same name to the method definition in server that is called in
client.
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
------
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.
---------
this giving name and refering name can be done with static methods rebind() and
lookup() of Namning class of java.rmi package.