44648785-java (1)
TRANSCRIPT
-
7/29/2019 44648785-Java (1)
1/159
Topics in Enterprise Architecture
07MCA41
-
7/29/2019 44648785-Java (1)
2/159
UNIT- I
-
7/29/2019 44648785-Java (1)
3/159
Introduction to JAVAJava is a programming language originally developed by Sun
Microsystems and released in 1995 as a core component of Sun
Microsystems Java platform. The language derives much of its
syntax from C and C++ but has a simpler object model and fewer
low-level facilities. Java applications are typically compiled to
bytecode (class file) that can run on any Java Virtual Machine (JVM)regardless ofcomputer architecture.
Java was initially called as OAK later it was renamed as JAVA
in
the year 1995.
Write Once Run Anywhere
-
7/29/2019 44648785-Java (1)
4/159
Editions of Java
1.) Java SE2.) Java EE
3.) Java ME
-
7/29/2019 44648785-Java (1)
5/159
JDK(Java Development Kit)1.) Java Loader2.) Javac - Compiler
3.) JAR Java ARchiver
4.) Jdb Java Debugger
5.) Javap Class file Disassembler6.) Javah C header and stub generator
7.) Applet viewer
8.) Javaws Java Web Start
9.) Javadoc Java Documentation
-
7/29/2019 44648785-Java (1)
6/159
Java Applications1.) Mobiles
2.) Games
3.) Blu Ray Disc
4.) NASA5.) Web Sites
-
7/29/2019 44648785-Java (1)
7/159
Creating, Compiling and Executing a Java Program
Create / Modify Source code
any compilation errors
Compile Source code
Bytecode
Run Byte code
Result
Source code
-
7/29/2019 44648785-Java (1)
8/159
JVM(Java Virtual Machine)A Java Virtual Machine (JVM) is a set of computer
software programs and data structures that use a
virtual machine model for the execution of other
computer programs and scripts. The model used by a
JVM accepts a form of computer intermediate
Language commonly referred to as Java bytecode .
JVM is an Interpreter for bytecode. Translating a Java
program into bytecode makes it much easier to run a
program in a wide variety of environments.
-
7/29/2019 44648785-Java (1)
9/159
JVM(Java Virtual Machine)
In Java a program will be written once and thesource program can be compiled into a special
type of machine language code known as
bytecode.
Any
Computer
JVM
Java Bytecode
-
7/29/2019 44648785-Java (1)
10/159
JVM Architecture
Class loader
subsystem
PC
Registers
Java
StacksHeapMethod
Area
Native Method
InterfaceExecution
Engine
Native Method
Stack
Class files
Native method libraries
Runtime Data Area
-
7/29/2019 44648785-Java (1)
11/159
Java Buzzwords or Features
1.) Simple2.) Secure
3.) Portable
4.) Object Oriented
5.) Robust
6.) Multithreaded
7.) Architecture Neutral
8.) Interpreted & High Performance10.) Distributed
11.) Dynamic
-
7/29/2019 44648785-Java (1)
12/159
A Simple Program in Java
import java.io.*;class Simple
{
public static void main(String args[]){
System.out.println(a simple program);
}
}
-
7/29/2019 44648785-Java (1)
13/159
Compilation of Java Program
1.) After writing the source code
2.) Save it with .java extension.
3.) To Compile:-
javac pgmname.java
4.) Execution or Interpreting or Running:-
java pgmname or classname
-
7/29/2019 44648785-Java (1)
14/159
Polymorphism
Static Dynamic(Method Overloading) (Method Overriding)
1.)Static /(Early Binding)/(Compile Time)2.) Dynamic/(Late Binding)/(Run Time)
-
7/29/2019 44648785-Java (1)
15/159
Datatypes and Other Tokens, Boolean Variables
Datatypes
Integers Floating-point Characters BooleanByte Float Char Boolean
Int Double
Shortlong
-
7/29/2019 44648785-Java (1)
16/159
Datatypes and Sizes
Datatypes Width(in Bits)1.)Long 64(8)
2.)Int 32(4)
3.)Short 16(2)
4.)Byte 8 (1)
5.)Double 64(8)
6.)Float 32(4)7.)Char 16(2)
8.)Boolean True/False
-
7/29/2019 44648785-Java (1)
17/159
Identifiers, LiteralsI
dentifiers in Java are used as:-(i) Class Names
(ii) Method Names
(iii) Variable Names
Literals:-
Any constant value in java is created by using
a literal representation.
E.g:- int a=100; char c=x
-
7/29/2019 44648785-Java (1)
18/159
TokensIn a Java program, all characters are grouped into symbols called tokens.
There are six kinds of Tokens available in Java. Each Token should be
identified in Java programs.
Token
-
7/29/2019 44648785-Java (1)
19/159
OOP ( Object Oriented Programming)
1.) Encapsulation2.) Inheritance
3.) Polymorphism
-
7/29/2019 44648785-Java (1)
20/159
Access Specifiers
Private No Modifier Protected Public
Same Class Yes Yes Yes Yes
Same Package
Subclass
No Yes Yes Yes
Same Package
non subclass
No Yes Yes Yes
Different
Package
Subclass
No No Yes Yes
Different
Package non
Subclass
No No Nos Yes
-
7/29/2019 44648785-Java (1)
21/159
StreamsThere are Two types of Streams:-1.) Byte Streams
2.) Character Streams
InputStream
Byte Stream Classes
OutputStream
Reader
Character Stream Classes
Writer
-
7/29/2019 44648785-Java (1)
22/159
Streams
Input Stream ------------------------- System.in
Print Stream -----------System.out, System.err
-
7/29/2019 44648785-Java (1)
23/159
Streams
Buffer Java Program
Output
Input
Print()
Println()
Input StreamReader
Readline()
Read()
Buffered Reader
-
7/29/2019 44648785-Java (1)
24/159
Control StatementsControl Statements
Selection(conditional) Iteration(loops) Jump
if For Return
Nested ifs While Break
if-else-if Dowhile Continue
SwitchNested Switch
-
7/29/2019 44648785-Java (1)
25/159
Type Conversion and Type CastingRules are:-
1.) The two types should be compatible
2.) The destination type should be larger than the
source type Range increases
Byte, short, int, long, float, double
-
7/29/2019 44648785-Java (1)
26/159
Java Escape SequencesCharacterEscapeSequence Name
\b Backspace
\t Tab
\n Linefeed\f Formfeed
\r Carriage Return
\\ Backslash
\ Single Quote\ Double Quote
-
7/29/2019 44648785-Java (1)
27/159
Operators and ExpressionsOperator Result
+ Addition- Subtraction
* Multiplication
/ Division
% Modulus++ Increment
+= Addition Assignment
-= Subtraction Assignment
*= Multiplication Assignment/= Division Assignment
%= Modulus Assignment
-- Decrement
-
7/29/2019 44648785-Java (1)
28/159
Bitwise OperatorsOperator Result~ Bitwise unary NOT
& Bitwise AND
| Bitwise OR
^ Bitwise exclusive OR
>> Shift right>>> Shift right zero fill
>= Shift right assignment
>>>= Shift right zero fill assignment
-
7/29/2019 44648785-Java (1)
29/159
Relational OperatorsOperator Result
== Equal to
!= Not equal to
> Greater than
< Less than>= Greater than or equal to
-
7/29/2019 44648785-Java (1)
30/159
Boolean Logical OperatorsOperator Result
& Logical AND| Logical OR
^ Logical XOR( exclusive OR)
|| Short circuit OR
&& Short circuit AND
== Equal to
!= Not equal to
! Logical Unary NOT
&= AND assignment
|= OR assignment
^= XOR assignment
?: Ternary if-then-else
-
7/29/2019 44648785-Java (1)
31/159
The Assignment Operator
Var=expression;e.g:- int a,b,c;
a=b=c=54;
The ? Operator:- (Ternary Operator)Expression ? Expression2 : Expression3
Operator Precedence.Highest:-
(),[],.,++,--,~,!,*,/,%,+,-,>>,>>>, =,
-
7/29/2019 44648785-Java (1)
32/159
String HandlingMethods in String Handling are:-1.)length();
2.)concat();
3.)toString();
Character Extraction Methods:-1.)charAt();
2.)getChars();
3.)getBytes();
4.)toCharArray();
-
7/29/2019 44648785-Java (1)
33/159
String Handling
String Comparison Methods are:-1.)equals() and equalsIgnoreCase()
2.)regionMatches()
3.)startsWith() , endsWith()4.)compareTo()
Searching of Strings:-1.)indexOf()
2.)lastIndexOf()
-
7/29/2019 44648785-Java (1)
34/159
String Handling
Modifying a String:-1.)substring()
2.)concat()
3.)replace()
4.)trim()
Data conversion using valueOf().
Changing the case of characters with in a
String:-1.)toLowerCase()
2.)toUpperCase()
-
7/29/2019 44648785-Java (1)
35/159
II -UNIT
-
7/29/2019 44648785-Java (1)
36/159
ClassesA Class is a Template for an Object, anObject is an instance of a Class.
The base class for all classes in Java isObject Class. All other classes are
subclasses of Object class. The Object
class defines few methods, that impliesthey are available in every object.
-
7/29/2019 44648785-Java (1)
37/159
ClassesSyntax:-
Class classname{type instance-variable1;
type iv2;
type methodname1(){ }
type methodname2(parameter-list)
{ }
}
-
7/29/2019 44648785-Java (1)
38/159
Object Class
Method Purpose1.)Object clone() - creates a new objectsame as the object being cloned.
2.)boolean equals(Object object)checkswhether one object is equal to another.
3.)void finalize() - called before an unusedobject is recycled.
-
7/29/2019 44648785-Java (1)
39/159
Object ClassMethod Purpose
4.)Class getClass() Obtains the class of anobject at run time.
5.) int hashCode() Returns the hashcodeassociated with the invoking object.
6.) void notify() - Resumes execution of athread waiting on the invoking object.
-
7/29/2019 44648785-Java (1)
40/159
7.) void notifyAll() - Resumes execution of all
threads waiting on the invoking object.
8.)String toString() Returns a string thatdescribes the object.
9.)void wait()10.)void wait(long milliseconds)
11.)void wait(long milliseconds, int nanoseconds)
waits on another thread of execution
Object ClassMethod Purpose
-
7/29/2019 44648785-Java (1)
41/159
ConstructorsA class contains constructors that are invoked to
create objects from the class blueprint. Constructor
declarations look like method declarationsexcept
that they use the name of the class and have no
return type.As with methods, the Java platform differentiates
constructors on the basis of the number of
arguments in the list and their types. we cannotwrite two constructors that have the same number
and type of arguments for the same class, because
the platform would not be able to tell them apart.
Doing so causes a compile-time error.
-
7/29/2019 44648785-Java (1)
42/159
You don't have to provide any constructors for your
class, but you must be careful when doing this. The
compiler automatically provides a no-argument,
default constructor for any class without constructors.
This default constructor will call the no-argument
constructor of the superclass. In this situation, the
compiler will complain if the superclass doesn't havea no-argument constructor so you must verify that it
does. If your class has no explicit superclass, then it
has an implicit superclass of Object, which does have
a no-argument constructor.You can use access modifiers in a constructor's
declaration to control which other classes can call the
constructor.
-
7/29/2019 44648785-Java (1)
43/159
Rules for Constructors:-1.) Constructors can use any access modifier,
including private.
2.) the constructor name must match the
name of the class.3.)constructors must not have a return type.
4.)A method will have a return type but
constructor will not have any return type.
-
7/29/2019 44648785-Java (1)
44/159
E.g:- Constructor
1.)class Foo
{
Foo()
{ }
}
-
7/29/2019 44648785-Java (1)
45/159
2.)class Foo
{
int size;
String name;Foo(String name,int size)
{
this.name=name;
this.size=size;
}
}
-
7/29/2019 44648785-Java (1)
46/159
Method Overloading
When a class has more than one methodwith same name but with different
parameters we call it as Method
Overloading.
-
7/29/2019 44648785-Java (1)
47/159
Method Overriding
When a method in the subclass has the samename and type signature as a method in the
super class than the method in the subclass is
said to be as over ridden method.
-
7/29/2019 44648785-Java (1)
48/159
ArraysAn array is used to store a collection of data.It is a collection of homogeneous elements.
Array is used to store a fixed size sequential
collection of elements of the same type.
-
7/29/2019 44648785-Java (1)
49/159
PackagesA Package is a container for a group of classesthat are used to keep the class name space
compartmentalized. They are stored in a
hierarchical manner and are explicitly imported
into new class definitions.
-
7/29/2019 44648785-Java (1)
50/159
PackagesHierarchy of Packages in Java:-
Java
Lang Util IO AWT
-
7/29/2019 44648785-Java (1)
51/159
Packages
1.)When the programs are with in the package tocompile we have to specify at that package level
a.)javac *.java
b.)Java class name(where main method exists)
2.) When main method is outside the package
Compile with in the package but run or execute
the program outside the package.
3.)To create the package
javac d . Clsname .java
While compiling:- java pkgname.clsname
-
7/29/2019 44648785-Java (1)
52/159
Abstract Methods
A Method with complete body is called as ConcreteMethod, with out body is called as Abstract
Method. Methods which are incomplete are called
as Abstract Methods.
A class which contains Abstract Methods
must be declared as Abstract which is a keyword in
Java. By using Abstract methods we cannot create
any objects only references can be created.
-
7/29/2019 44648785-Java (1)
53/159
Abstract Methods
Notation:-abstract class A
{
abstract void m1();
void m2()---- Concrete Method
{ }
}
-
7/29/2019 44648785-Java (1)
54/159
InterfacesIn Interfaces all the methods must be Abstract
Methods. Interfaces are syntactically similar to
classes but all the methods are declared with out
body.
Interfaces are declared by using Interface keyword.Once the interfaces are defined any number of
classes cam implement that interface.
By default all the methods in interface are public,
abstract.
By default all the variables in interface are static,
final.
-
7/29/2019 44648785-Java (1)
55/159
InterfacesJava allows only single inheritance for class
extension, but multiple extensions for interfaces.
E.g:-
Public class Newclass extends Baseclass
implements Int1,Int2
.. Intn
An interface can inherit other interfaces using the
extends keyword such an interface is called as a
subinterface.
E.g:- interface iface3 extends iface1,iface2.ifacen
-
7/29/2019 44648785-Java (1)
56/159
Interfaces
E.g:-Interface iface1
{
void method1();
void method2();
}
Class A implements iface1
{public void method1(){}
public void method2(){}
}
-
7/29/2019 44648785-Java (1)
57/159
Differences - Interfaces and Abstract Classes
1.)All the methods in interface are abstract
methods where as abstract classes can
contain both abstract methods and concrete
methods.
2.) In interfaces all the variables are by default
public, static and final where as in abstract
classes we have to declare explicitly.
3.)In interfaces all methods are by defaultpublic and abstract where as in abstract
classes we have to explicitly declare the
methods as abstract.
-
7/29/2019 44648785-Java (1)
58/159
Exception Handling
An Exception is an abnormal condition thatdisturb the normal program flow execution.
Difference between Error and Exception is
Error signify drastic failures which cannot behandled by the programmer.
E.g:- Stack Overflow
-
7/29/2019 44648785-Java (1)
59/159
Exception Handling
Throwable
Error Exception
Checked Unchecked
-
7/29/2019 44648785-Java (1)
60/159
Exception
CheckedExceptions UncheckedExceptionsIOException NullPointerException
ClassNotFound ArrayIndexOutOfBounds
CloneNotSupported ArithMeticExceptionNoSuchMethod ClassCastException
NoSuchFieldException
SQLException
-
7/29/2019 44648785-Java (1)
61/159
Exception HandlingDifferent types of exceptions available in Java
are :-
1) ArithmeticException
ex:- division by zero
2)IOException :- which are frequently occured at
Input Output Operations time.
3) ArrayIndexOutofBounds:-Occurs when you
are trying to access the element whose index is
greater than length of our array.
-
7/29/2019 44648785-Java (1)
62/159
Exception Handling
4) NullPointerException:-Occurs when you aretrying to perform operations on the values not
yet initialized.
5) StringIndexOutofBounds:- Same as
ArrayIndexOutofBounds
6) FileNotFoundException:- If you are trying toaccess the file which is not available.
-
7/29/2019 44648785-Java (1)
63/159
Exception Handling7)NumberFormatException:- Occurs when we
are trying to assign value to the variable which is
of different type.
8)ClassNotFoundException:- If the accesing classis not available in the current directory.
9)NoSuchMethodException:- Occurs when you
call the method which is not available in the
current class.
-
7/29/2019 44648785-Java (1)
64/159
Exception HandlingException Handling in Java is managed by Fivekeywords:-
1.)try
2.)catch3.)throw
4.)throws
5.)finally
-
7/29/2019 44648785-Java (1)
65/159
INNER CLASSESInner classes are also called as Nested classes. It is a classwhich is declared in another class.
Some properties ofInner classes are:-
1.)We can use the classname only with in the defined scope,the name of the inner class must be different from the outer
class.
2.)the inner class can use both class and instance variables
of enclosed classes and final local variables of enclosingblocks.
-
7/29/2019 44648785-Java (1)
66/159
INNER CLASSES
3.)the inner class can be defined as abstract.
4.)the inner class can have any access specifier.
5.)the inner class can act as an interface
implementer.
6.)Same type of variables can be called from
both inner and outer classes.
-
7/29/2019 44648785-Java (1)
67/159
Applets
Applets are small applications that areaccessed on an Internet server, transported
over the Internet, automatically installed,
and run as a part of a web document.
Applets are created to distribute Java code
they are default GUI's. They will be loaded as
documents which can be executed eitherusing the Browser or AppletViewer utility.
A l t
-
7/29/2019 44648785-Java (1)
68/159
AppletsLife Cycle of an Applet:-
Init()
Start()
paint()
Stop()
destroy()
-
7/29/2019 44648785-Java (1)
69/159
AppletsWhen applet is loaded for the first time the init()method is going to be invoked from there the
flow will be transferred to the start() which
executes the paint() if exists.If Applet got focus the start() is going to be
executed, the stop() is going to be executed when
ever the focus lost.
If Applet is terminated the Stop() and destroy()are going to be executed.
-
7/29/2019 44648785-Java (1)
70/159
Applets
1.)init()- The init() is invoked after the applet iscreated. If a subclass of Applet has an initialization
to perform, it should override this method. It is the
first method called in every Applet.
2.)start()- The start() is invoked after the init(). It is
also called when user returns to the Web page
containing the applet after surfing the pages.
3.)stop()- The stop() is invoked when user leaves
the page.
-
7/29/2019 44648785-Java (1)
71/159
Applets4.)destroy()- the destroy() is invoked when the
browser exits normally to inform the applet
that it is no longer needed and should release
any resources it has allocated.
Applets are Event Driven. The
execution of an Applet will not start with main
method.
-
7/29/2019 44648785-Java (1)
72/159
Applets
Two types of applets are:-1.)Applet Class(which uses AWT)
2.)Swing Class(JApplet)
AWT-stands for Abstract WindowToolkit. AWT components can be
decorated directly over Frame or Applet.
Two types of Executable programs in Javaare:-
1.)Java Applications(standalone)
2.)Java Applets(Distributed)
-
7/29/2019 44648785-Java (1)
73/159
Applets
To Load Applet:-
1.)Applets dont need a main method.
2.)Applets must be run under an applet viewer
or a Java compatible browser.3.)User I/O is not accomplished with Java's
Stream IO Classes.Instead,applets use the
interface provided by the AWT.
-
7/29/2019 44648785-Java (1)
74/159
Hierarchy of Applets and SwingObject
Component
Container
Frame Applet
Window
JAppletJFrame
Panel
-
7/29/2019 44648785-Java (1)
75/159
Applets
The HTML Applet Tags are:-1.)codebase
2.)code
3.)alt4.)name
5.)width, height
6.)align
7.)vspace, hspace
8.)
-
7/29/2019 44648785-Java (1)
76/159
Applet Display Methods1.)update()
2.)paint()
3.)setBackground()
4.)setForeground()
5.)getBackground()
6.)getForeground()
The default foreground color is black,
background color is light gray.
E t H dli d D l ti
-
7/29/2019 44648785-Java (1)
77/159
Event Handling and DelegationAn event is an unexpected external happening in the context of
hardware.Forexample when we press a key the electronic deviceinside the keyboard interrupt the system to send the keycode .
So that the system respond immediately by halting whatever it
was doing.
In this EventDrivenProgramming, the user control the
sequence of operations that the application executes.In eventdriven application the program will construct the various GUI
Components displayed those components and then enters into
a tightly loop weighting for user events to request an operation.
In java all the events are objects which describes the state
change in a source , the java.awt.event package defines a set of
event classes for the respective event type through this
package ,the objects of various event classes are constructed
when ever the user activates the respective GUI components.
-
7/29/2019 44648785-Java (1)
78/159
Event Handling and Delegation
The Programmer has to handle these generated events for
example when the user clicks on the button, the JVM constructs
an object of an action event class in which it stores all the details
like when and where the event is generated.
If we donot handle this generated event then the event issimply ignore .In GUI program the generated events are handled
with the concept of event delegation.
-
7/29/2019 44648785-Java (1)
79/159
EventDelegation:
The process of assigning an object to handle the events is calledevent delegation,the event handling objects are called listeners.
for example to inform a button component that it should
delegate action event to some listener, we call the add
actionListener method of button class by passing a reference of
the desired listener.
every component class in awt has addlistener method to
each event type that the component generates.
when a button with actionlistener is clicked then the
listener receives an action event object and executes its actionperformed method .there are two ways of delegating an event
to the listener
1)delegating an event to an external object
2)delegating to some object
h l d l h
-
7/29/2019 44648785-Java (1)
80/159
The Delegation Event Model has two parts:-
1.)Sources and Listeners.
Event Sources are:-
1.)Button
2.)Checkbox
3.)Choice4.)List
5.)Menu Item
6.)Scrollbar
7.)Text Components8.)Window
E t t d i t f A il bl
-
7/29/2019 44648785-Java (1)
81/159
Event types and interfaces Available
An Event is an object that describes a state change in a Source. A source is an
Object that generates an Event. A Listener is an object that is notified when anevent occurs.
java.awt.event package contains the following
classes for the respective event type.
1)ActionEvent
2)TextEvent3)ItemEvent
4)WindowEvent
5)KeyEvent
6)FocusEvent
7)AdjustmentEvent
8)MouseEvent9)Component Event
10)Container Event
11)Input Event
12)MouseWheelEvent
the following are the interfaces available
-
7/29/2019 44648785-Java (1)
82/159
the following are the interfaces available
in java.awt.event package to handle the respective event types
i.e
1)ActionListener2)TextListener
3)ItemListener
4)WindowListener
5)KeyListener
6)FocusListener
7)AdjustmentListener
8)MouseListener
9)MouseMotionListener
10)Component Listener11)Container Listener
12)MouseWheelListener
13)WindowFocusListener
-
7/29/2019 44648785-Java (1)
83/159
the following are the respective methods that are declared
in the respective interfaces
1)ActionListener----->(Buttons,TextField,TextArea,List)
public void actionPerformed(ActionEvent ae)
2)TextListener----->(TextFields,TextArea)
public void textChanged(TextEvent te)
3)ItemListener------>( Checkbox,CheckboxGroup)
public void itemStateChanged(ItemEvent ie)
4)WindowListener------>(Frames)
public void windowOpened(WindowEvent we)
public void windowClosed(WindowEvent we)public void windowClosing(WindowEvent we)
public void windowActivated(WindowEvent we)
public void windowDeactivated(WindowEvent we)
public void windowIconified(WindowEvent we)
public void windowDeiconified(WindowEvent we)
5)keyListener-------->(Buttons)public void KeyPressed(KeyEvent ke);
public void keyReleased(KeyEvent ke);
public void KeyTyped(KeyEvent ke);
6)FocusListener >(TextField TextArea Frames)
-
7/29/2019 44648785-Java (1)
84/159
6)FocusListener-------->(TextField,TextArea,Frames)
public void FocusGained(FocusEvent fe);
public void FocusLost(FocusEvent fe);
7)AdjustmentListener-------->(ScrollBar)
public void adjustmentValueChanged(AdjustmentEvent ae);8)MouseListener------------>
public void mousePressed(MouseEvent me);
public void mouseRelease(MouseEvent me);
public void mouseClicked(MouseEvent me);
public void mouseEntered(MouseEvent me);
public void mouseExited(MouseEvent me);9)MouseMotionListener--------->(ScrollBar)
public void mouseMoved(MouseEvent me);
public void mouseDragged(MouseEvent me);
10)ComponentListener--------->
public void componentResized(ComponentEvent ce);
public void componentMoved(ComponentEvent ce);public void componentShown(ComponentEvent ce);
public void componentHidden(ComponentEvent ce);
11)ContainerListener >
-
7/29/2019 44648785-Java (1)
85/159
11)ContainerListener--------->
public void containerAdded(ContainerEvent ce);
public void containerRemoved(ContainerEvent ce);
12)MouseWheelListener------------>public void mouseWheelMoved(MouseWheelEvent mwe);
13)WindowFocusListener------>
public void windowGainedFocus(WindowEvent we)
public void windowLostFocus(WindowEvent we)
-
7/29/2019 44648785-Java (1)
86/159
Layouts
1.)Flow Layout2.)Border Layout
3.)Card Layout
4.)Grid Layout5.)Grid Bag Layout
6.)Box Layout
-
7/29/2019 44648785-Java (1)
87/159
Layout Managers
A layout manager is a Java object associated with aparticular component.The layout manager controls
the components contained with in it.
Border Layout is the default Layout manager for a
Frame.
FlowLayout is the default layout manager for a
Panel.
1)Flow Layout
-
7/29/2019 44648785-Java (1)
88/159
1)Flow Layout:
This layout manager is the simplest layout manager
in the awt,as the name says it will layout all the GUIelements in a flowing.Which is similar to word processor
arranges words in a paragraph.
the setLayout method of the container class is usedto set the respective layout for the container.the
constructors of this flowlayout class are
1)FlowLayout() ---->default alignment is center
2) BorderLayout:
-
7/29/2019 44648785-Java (1)
89/159
2) BorderLayout:
This layout manager will divide the entire
space of the container into five zones i.eNorth,South,East,West,Center.
This Layout manager is the default layout
manager for the frame class,this border layout
sizes its individual component so that
automaticaly expand to fill the space available
for them.The add method of the container
class is use to add the individual componentsby specifiying the respective position such as
-
7/29/2019 44648785-Java (1)
90/159
f.add("North",b1); where
f-> Frame Objectb1->button Component
So that button b1 is added at the north
of the frame this BorderLayout can deal with
only five components i.e for component
located against four edges of the container,
and one located centrally an occupies theentire space of the center of the container.
-
7/29/2019 44648785-Java (1)
91/159
3)GridLayout:This enforces a gridbag layout for all the
components of a container.we specify the number of
gridrows and gridcolumns to the constructor of thisgridlayout class such as
f.setLayout(new GridLayout(2,2));
All the components will be added to the
container with respect to the specific grid dimensionso that the components are visible as matrix form, all
the individual components will be added to the
container with add methods such as
f.add(b1);f.add(b2); etc.......
-
7/29/2019 44648785-Java (1)
92/159
GridLayout :-
GridLayout(int rows,int cols);
GridLayout(int rows,int cols,int hs,int vs);
add(Component);
-
7/29/2019 44648785-Java (1)
93/159
Box layout :-public static Box createVerticalBox();
public static Box createHorizontalBox();
public static void createVerticalGlue();
public static void createHorizontalGlue();
-
7/29/2019 44648785-Java (1)
94/159
Card Layout
By using Card layout many screens orcomponents can be displayed but only
one at a time by selecting that particular
component.First(container),previous(container),
Next(container),last(container)
Swing
-
7/29/2019 44648785-Java (1)
95/159
SwingSwings are GUI(Graphical User Interface) based
Application. Look and feel is the concept of Swing
and the appearance of the Swing application is
same in different platforms.
AWT applications appearance is different indifferent platforms because Java depends on OS
level to overcome this problem Netscape and other
Scientists developed a set of classes called as
JFC(Java Foundation Classes)
java awt Graphics methods
-
7/29/2019 44648785-Java (1)
96/159
java.awt.Graphics methodsdrawLine(x1,y1,x2,y2);
drawRect(x,y,w,h)& fillRect(x,y,w,h)drawOval(x,y,w,h);&fillOval(x,y,w,h);
drawRoundRect(x,y,w,h,xarc,yarc);&
fillRoundRect(x,y,w,h,xarc,yarc);
draw3DRect(x,y,w,h,boolean raised);fill3DRect(x,y,w,h,boolean raised);
drawArc(x,y,w,h,stangle,total angle);
fillArc(x,y,w,h,stangle,total angle);
drawPolyline(x[],y[],int n);drawPolygon(x[],y[],int n);& fillPolygon(x[],y[],int n);
drawString(String,x,y);
setColor(Color);
j l
-
7/29/2019 44648785-Java (1)
97/159
java.awt.Component classpublic void setSize(w,h);
public void setBounds(x,y,w,h);
public void setVisible(boolean);
public setTitle(String);
public void setBackground(Color);
public void setForeground(Color);
public Color getBackground();
public Color getForeground();
public void setPreferredSize(Dimension);
public Dimension getPreferredSize();
public void setEnabled(boolean);
public int isEnabled();
-
7/29/2019 44648785-Java (1)
98/159
IconIcon is an interface implemented
in a class ImageIcon.
Icon i1=new ImageIcon("imagepath");
Ad l
-
7/29/2019 44648785-Java (1)
99/159
Adapter classesMouseAdapter
MouseMotionAdapter
ComponentAdapter
ContainerAdapter
KeyAdapterWindowAdapter
FocusAdapter
javax swing
-
7/29/2019 44648785-Java (1)
100/159
javax.swingBoth swing and awt packages are used to create the forms.AWT
follows Event delegation model.awt methods internally call the native methods . Native
methods which are written in other languages like c and c++.They
are system dependent and awt components are heavy weight
components . It requires more Memory ,Resources and more
processing time. Look & feel of awt components are different forHeterogeneous operating systems. look means appearance and
feel means interaction with user.
For the above reasons java soft people provided another api
that is JavaFoundationClasses(JFC). It is system independent. JFCis an extension to awt. So it is not replacement of awt. JFC
contains so many packages.
JFC contains :--->
-
7/29/2019 44648785-Java (1)
101/159
JFC contains : >
1) javax.swing:-->(x - means extension)To develop components like buttons ,
menus etc, to access windows like Jframe,
Jpanel etc2.)javax.event :- To access various events
like mouse,keyboard,etc..
3.)java.awt:- to access various layouts likeflow,grid,border etc..
F t f JFC
-
7/29/2019 44648785-Java (1)
102/159
Features of JFC
1) JFC components are light -weight components . They
use less System resourses.
2) JFC components have same look & feel on all
platforms
By using javax.swing.plaf package the programmer
can change the look & feel of components.
3) JFC offers a rich set of components with lot of
features.
4) JFC does not replace awt ,it is an extension.
javax.swing components follow the model-view-control
-
7/29/2019 44648785-Java (1)
103/159
javax.swing components follow the model view control
model --> represents state of the component.
view --> How the component is represented graphically
control-> Control view & model.
1) model stores the data that defines the state of the
button or text present in the text field.2) view creates visual representation of the component
from the data in the model.
3) control deals with the users interaction with the
components and modifies the model or the view inresponse to user action.
-
7/29/2019 44648785-Java (1)
104/159
JTabbedPane :-
JTabbedPane();JTabbedPane(int orientation);
JTabbedPane.TOP,BOTTOM,LEFT,RIGHT
SwingConstants. TOP,BOTTOM,LEFT,RIGHT
addTab(String label, Icon obj,
Component, String tooltiptext);
insertTab(String label, Icon obj,Component,String tooltiptext, int index);
-
7/29/2019 44648785-Java (1)
105/159
Annonymous Inner classes
new xxxxListener()obj.addxxxxListener(new xxxAdapter()
{
methods...});
Multi Threaded Programming
-
7/29/2019 44648785-Java (1)
106/159
Multi Threaded ProgrammingA Thread is a small process with in a program.
To create a thread either we have to extendthe Thread Class or implement the Runnable
Interface.
Methods in Thread class are:-1.)getName
2.)getPriority
3.)isAlive()4.)join
Multi Threaded Programming
-
7/29/2019 44648785-Java (1)
107/159
Multi Threaded ProgrammingMethods in Thread class are:-
5.)run
6.)sleep
7.)start
S t
-
7/29/2019 44648785-Java (1)
108/159
Syntax
java.lang.Thread class|
public static Thread currentThread();
public void setName(String);public String getName();
public static void sleep(long ms) throws
InterruptedException
S t
-
7/29/2019 44648785-Java (1)
109/159
Syntax
Thread();Thread(String tname);
Thread(Object obj,String tname);
public void start();
public void run();
public boolean isAlive();public void join() throws
InterruptedException
Syntax
-
7/29/2019 44648785-Java (1)
110/159
Syntax
>>>>> thread priorities :
Thread.MIN_PRIORITY 1
Thread.NORM_PRIORITY 5 (default)
Thread.MAX_PRIORITY 10
public void setPriority(int);
public int getPriority();
Threads
-
7/29/2019 44648785-Java (1)
111/159
Threads
A thread is a process or execution of a task,Performing only onetask is called a Single Thread . In multitasking there are 2 types.
1) Process based multitasking:- Executing more than oneprogram
-----------------------------------------
simultaneously is called Process based Multitasking.
2) Thread based Multitasking:-
-----------------------------------------
Executing the different parts of the same programsimultaneously is called Thread based Multitasking.
Round Robin
-
7/29/2019 44648785-Java (1)
112/159
Round Robin
Executing the first program after the secondprogram is called as Round Robin System.
Threads are useful in two ways:-
-------------------------------------------1) creation of animation and games.
2) Threads are used in an internet server to serve several
clients simultaneously.
Important Points1) A thread is a sequential flow of control with in a program Every
-
7/29/2019 44648785-Java (1)
113/159
1) A thread is a sequential flow of control with in a program . Every
program has at least one thread that is called the primaryThread.
2) Applications having only one thread is called single thread model.
3) The currentThread () method retrieves the reference of the
currentthread.
4) Multithreaded applications have more than one thread.
5) The Thread class is used to create and manipulate the threads in a
program.
6) You can use the Thread class or the runnable interface to
implement the threads.
Important Points
-
7/29/2019 44648785-Java (1)
114/159
Important Points7) A thread can have the following states.
a) New Thread : When an instance of Thread class is created,thethread enters into the newthread state.
b) Runnable : When the start() method is invoked,the thread
enters into the runnable state.
c) NotRunnable : The thread is said to be in not runnable state if
it is in
* Sleeping.
* Waiting.* Being blocked by another thread.
d) Dead : A thread can be either die naturally or killed. A natural
death when the loop in the run() method is complete.
Important Points
-
7/29/2019 44648785-Java (1)
115/159
p1) The start() method of the Thread class is used to start the thread.
2) The run() method contains the code which the thread executes.
3) A thread can be put to sleep using the sleep() method.
4) The threads are scheduled based on the priorities.
5) The synchronized keyword is used to ensure that no threads
access the same object simultaneously.
6) The methods wait(), notify(), notifyAll() are used for inter-threadcommunication.
7) Mutex : It is an object that is locked till a thread completes
execution.
-
7/29/2019 44648785-Java (1)
116/159
JDBC
JDBC
-
7/29/2019 44648785-Java (1)
117/159
JDBCJDBC stands for Java DataBase Connectivity
PROCEDURE FOR ESTABLISHING THE DATABASECONNECTION:-
1) Loading(Registering) the driver software into the
memory
2) Establishing the connection from the front endapplication to the server.(Database)
3) Creating the statements corresponding to the
connection generated.
4) Execute the created statements
5) Closing all the statements.
-
7/29/2019 44648785-Java (1)
118/159
Types of Drivers in JDBC are:-
1.)Jdbc-Odbc Bridge driver2.)Native API Partly Java Driver
3.)Jdbc-Net Pure Java Driver
4.)Native Protocol Pure Java Driver
Database connection
-
7/29/2019 44648785-Java (1)
119/159
1) java.lang.Class class
public static void forName("classname")
throws java.lang.ClassNotFoundException;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
>>>> DriverManager class
public static Connection
getConnection("url",["uname"],"[pwd]")throws
SQLException
uniform resource locator :"jdbc:odbc:datasourcename"Connection
cn=DriverManager.getConnection("jdbc:odbc:oradsn1",
"scott","tiger");
Java.sql package
-
7/29/2019 44648785-Java (1)
120/159
q p g1.)Driver Manager
2.)Connection3.)Statement
4.)Resultset
5.)Resultsetmetadata6.)Databasemetadata
7.)Prepared Statement
8.)Callable Statement
Explanation
-
7/29/2019 44648785-Java (1)
121/159
ExplanationODBC API is a specification that is accessible to everyone as part of
this specification. Microsoft design the functions like sqlConnect ,sqldisconnect, sqlparse and sqlexecute. These functions can be used
by the programmer to deal with different databases.
So many companies has provided the implementation ofODBC
API.These implementations are known as ODBC drivers.On windows we can get the files with the extension .DLL (Dynamic
Link Library) which contains the implementation of functions.
JDBC is an open specification which can be implemented
by any one.The implementation of JDBC API is known as JDBC driver.
All most all the JDBC driver vendors supplies a set of classes as part
of JAR file
Explanation
-
7/29/2019 44648785-Java (1)
122/159
A Java programmer need not learn different set of APIs to write
the programs to deal with different databases.
As part of JDBC API specification java soft has specify differentinterfaces like
Java.sql.driver
Java.sql.conncection
Java.sql.statement
Java.sql.prepared Statement
Java.sql.blob
Java.sql.callable Statement
==================================
And a set of classes like DriverManager==================================
Java.sql.Date
Java.sql.Time
Java.sql.TimeStamp , Java.sql.Types
Explanation
-
7/29/2019 44648785-Java (1)
123/159
p a at oAny one can provide the implementation of above interfaces
ex :Oracle Corp has provided the implementation of thoseinterfaces to access oracle.
A java programmer needs to know the following information to
access a specific Database.
a) The name of class that provides the implementation of
java.sql.Driver interface.b)The format of jdbc URL
NOTE :we can obtain the information from the documents
provided by JDBC Driver vendor
Classes12.jar is a JDBC Driver provided by oracle
corporation as part of oracle
PARSING
-
7/29/2019 44648785-Java (1)
124/159
PARSINGThe DataBase Servers are responsible for PARSING the sql
statements submitted by the client.PARSING :
Breaking up the sql statement into multiple pieces(tokens) for
analyzing whether the statement follows the sql syntax or not. And
checking the availability of different database objects used in sql
statement.
PREPARED STATEMENT :-
Prepared Statement stmt = con.preparedStatement(insert into
tablename Values(?,?);Stmt.setInt(1,1);
Stmt.setInt(2,1);
Stmt.ExecuteUpdate();
PREPARED STATEMENTP d S dS (i i
-
7/29/2019 44648785-Java (1)
125/159
Prepared Statement stmt = con.preparedStatement(insert into
MyTab Values(?,?);
Stmt.SetInt(1,1);Stmt.SetInt(2,1);
Stmt.ExecuteUpdate();
PROCEDURE FOR USING PREPARED STATEMENT
1) prepared statement stmt =
con.preparedstatement(deleted from mytab where col1=?);
2.)Set the values of parameter using
Stmt.setInt(1,1); method
3)To execute the statement using executeUpdate(); or by using
executeQuery() method.Eg:- Prepared Statement stmt = con.preparedStatement(insert
into emp(empno,ename) values(?,?);
Stmt.SetInt(1,1);
Stmt.SetString(2,Sone); Stmt.executeUpdate();
Explanation
-
7/29/2019 44648785-Java (1)
126/159
Explanation
*) To get the information about a table we can use an interfaceResultSetMetaData
*) To execute the select statements we can use executeQuery(). It
is not recommeneded to use executeUpdate().
1) ExecuteQuery must be used for executing select
statements and the return value is a Resultset object which can beused to fetch the rows from the database.
2) ExecuteUpdate has to be used for the execution of non-select
statements and the return value is a integer.The return value
gives the number of rows affected or changed or modified.ex :A ResultSet r1= Stmt.executeQuery(Select * from emp);
A JDBC programmer can access only one row at a time from the
ResultSet when the ResultSet is created it will be pointing to
before first row.
-
7/29/2019 44648785-Java (1)
127/159
SERVLETS
Servlets
-
7/29/2019 44648785-Java (1)
128/159
Servlets are used to dynamically extend the
functionality of a web server. Every Servlet is a classin Java. Server side applets are called as Servelts.
They need to be deployed in a Web Server or
Application Server.
Servlets are small programs that
are designed to execute on the server side of a Web
Connection. They are platform independent.
Server side programming can be develped usingcomponents like Servlets and JSPs.
Servlets
-
7/29/2019 44648785-Java (1)
129/159
ServletsLife Cycle of a Servlet:-
1.)init()
2.)service()
3.)destroy().
Servlets need a Web server todeploy the Servlets. Apache Tomcat is used to
deploy the Server side components which is a
Web server to maintain Web Components of java.
Web applications must be created to represent
Servlets.
Servlets
-
7/29/2019 44648785-Java (1)
130/159
ServletsThe two important packages that are required to
build Servlets are:-
1.)javax.servlet
2.)javax.servlet.http.
The above two packages contains the classes and
interfaces that are required to develop Servlets in
Java.
javax.servlet package
-
7/29/2019 44648785-Java (1)
131/159
The javax.servlet package includes the following
interfaces:-Interfaces Description
1.)Servlet Declares life cycle methods for a Servlet.
2.)ServletConfig Allows Servlets to get initialization parameters
3.)ServletContext Enables Servlets to log events and accessinformation about their environment.
4.)ServletRequest Used to read data from a client request.
5.)ServletResponse Used to read data from a client response.
6.)SingleThreadModel Indicates that the Servlet is thread safe.
javax.servlet package
-
7/29/2019 44648785-Java (1)
132/159
j p gThe javax.servlet package includes the following
classes:-Classes Description
1.)GenericServlet Implements the Servlet and ServletConfig
interfaces.
2.)ServletInputStream Provides an Input Stream for readingrequests from a client.
3.)ServletOutputStream Provides an Output Stream for writing
responses to a client
4.)ServletException Indicates a Servlet error occurred.
5.)UnavailableException Indicates a Servlet is Unavailable.
javax.servlet.http package
-
7/29/2019 44648785-Java (1)
133/159
The javax.servlet.http package includes the
following interfaces:-Interfaces Description
1.)HttpServlet Request Enables Servlets to read data
from an Http request.
2.)HttpServletResponse Enables Servlets to write datato an Http response.
3.)HttpSession Allows session data to be read
and written.
4.)HttpSessionBindingListener Informs an object that it is
bound to or unbound from
a session.
javax.servlet.http package
-
7/29/2019 44648785-Java (1)
134/159
The javax.servlet.http package includes the
following classes:-Classes Description
1.)Cookie Allows state information to be
stored on a client machine.
2.)HttpServlet Provides methods to handle Httprequests and responses.
3.)HttpSessionEvent Encapsulates a session change
event.
4.)HttpSessionBindingEvent Indicates when a listener is
bound to or unbound from a
value, or that a session
attribute changed.
Servlets
-
7/29/2019 44648785-Java (1)
135/159
Servlets
1.)Session Tracking(i)Cookies
(ii)Http Session
(iii)URL Rewriting
(iv)Hidden form fields2.)Request Dispatcher
(i)include
(ii)forward
Java Server Pages(JSP)
-
7/29/2019 44648785-Java (1)
136/159
Client1 Client1W
E
B
SE
R
V
E
RClient2
JSPjspInit()
_jspService()
jspDestroy()
JSP(Java Server Pages)
-
7/29/2019 44648785-Java (1)
137/159
Life Cycle of JSP:-
1.)JSP is translated into a Servlet.2.)Translated Servlet is compiled.
3.)Loads into memory the compiled code.
4.)Creates object of the Servlet
5.)Executes jspInit()
6.) Executes _jspService()
7.)Finally executes the jspdDestroy()
Java Server Pages(JSP)1 )Scripting Elements of JSP are:
-
7/29/2019 44648785-Java (1)
138/159
1.)Scripting Elements of JSP are:-
a.)Scripletsb.)Declarations
c.)Expressions
2.)Directives
a.)Page Directiveb.)include Directive
c.)Taglib Directive
Java Server Pages(JSP)Default Objects in JSP:
-
7/29/2019 44648785-Java (1)
139/159
Default Objects in JSP:-
1.)HttpServletRequest Request
2.) HttpServletResponse Response
3.)Page Context PageContext
4.)HttpSession Session5.)ServletConfig Config
6.)ServletContext Context
7.)Object Page8.)Throwable Exception
9.)JSPwriter Out
Java Server Pages(JSP)
-
7/29/2019 44648785-Java (1)
140/159
JSP actions:-
1.)jsp:actionname2.)jsp:forward
3.)jsp:include
4.)jsp:useBean5.) jsp:setProperty
6.) jsp:getProperty
7.) jsp:plugin
8.)jsp:param
-
7/29/2019 44648785-Java (1)
141/159
Remote Method Invocation
Remote Method InvocationRMI is a Specification to enable one JVM to invoke
-
7/29/2019 44648785-Java (1)
142/159
RMI is a Specification to enable one JVM to invoke
methods in an object of other JVM.The two JVMs may be in the same system or in
different systems.
RMI server can be implemented as Middle tier
of 3-tier architecture, that enables us to invoke
distributed components among network systems.
RMI ClientRegisters
remote objects
in RMI registryDatabase
RMI Server(Middle Tier)
Searches for Remote Objects
Remote Method InvocationDi t ib t d C t f RMI
-
7/29/2019 44648785-Java (1)
143/159
Distributed Components of RMI:-
1.)RMI Server2.)RMI Client
1.)RMI Server:- RMI Server is an application to
register remote objects in RMI Registry.
RMI Registry is a service in Java to maintain
remote objects with unique name.
2.)RMI Client:-RMI Client is an application to searchremote objects in RMI Registry. If search found then
remote methods will be invoked.
Remote Method Invocation
-
7/29/2019 44648785-Java (1)
144/159
RMI Architecture:-
1.)Skeleton/Stub Layer2.)Remote Reference Layer
3.)Transport Layer
RMI Architecture:-
-
7/29/2019 44648785-Java (1)
145/159
RMI Client RMI Server
Client Application
Stub
Remote Reference
Layer
Transport Layer
Server Application
Skeleton
Remote Reference
Layer
Transport Layer
Look up
Explanation
-
7/29/2019 44648785-Java (1)
146/159
1.)The client request will be received by stub,
which is represented to the server application atclient side.
2.)Stub requests will be interpreted by Remote
Reference Layer3.)The request will be sent to the remote network
system through transport layer
4.)Client requests will be received by the Skeleton
at server side and executes the original method.
ServerSideProgramming
-
7/29/2019 44648785-Java (1)
147/159
(i)Creating Remote Interface:-
(a)Create one interface as sub interface of Remote there are nomethods in the Remote Interface.
(b)Declare all Remote methods(which will be invoked from any
network system) in the interface and each method must throw
Remote Exception.
(ii)Create Implementation Class:-(a)Create a class as subclass ofUnicastRemoteObject
implementation of Remote Interface .URO belongs to
java.rmi.server.*;(b)Invoke Superclass constructor from implementation class(URO
is superclass)
(c)Define all Remote Interface methods in the class.
ServerSideProgramming
-
7/29/2019 44648785-Java (1)
148/159
(iii)Create Server Application:-
(a) Create a class to register remote object in Rmi Registry.Naming Class:-to Register
Public static void rebind(url,remoteobject);
url-rmi:://hostname[:port]/bindname
Port-1099(default,optional)
To Compile:-
1.)javac *.java
2.)rmic implclass
3.)start rmiregistry
4.)java serverapplication
ClientSideProgramming
-
7/29/2019 44648785-Java (1)
149/159
g g(i) Create RMI Client application to search remote objects
and to invoke remote methods.
RMI Specifications1)C t O I t f
-
7/29/2019 44648785-Java (1)
150/159
1)Create One Interface
2)Give the Implementation for that interface.3)Binding
4)create client Application
Rules For Creating Interfacea) Our Interface must extends
java.rmi.RemoteInterface.
b) declare all the Business Logic methods .
c) All the Business logic methods Should throws
java.rmi.RemoteException
Rules While Implementing the Interface
-
7/29/2019 44648785-Java (1)
151/159
Rules While Implementing the Interface
a) our implementation class should extendsjava.rmi.server.UnicastRemoteObject
b) Should provide non-argument constructorwhich throws java.rmi.RemoteException
c) Should implements all the Business logic
methods declared in our remote interface
-
7/29/2019 44648785-Java (1)
152/159
Enterprise JavaBeans
ExplanationEJB components are server side components written entirely in the
-
7/29/2019 44648785-Java (1)
153/159
EJB components are server-side components written entirely in the
Java programming language
EJB components contain business logic only - no system-level
programming & services, such as transactions, security, life-cycle,
threading, persistence, etc. are automatically managed for the EJB
component by the EJB server.
EJB architecture is inherently transactional, distributed, portablemulti-tier, scalable and secure.
EJB components are fully portable across any EJB server and any OS.
EJB architecture is wire-protocol neutral--any protocol can be
utilized like IIOP, JRMP, HTTP, DCOM, etc.
Rapid application developmentBroad industry adoption
Application portability
Protection ofIT investment
EJBContainer:-
-
7/29/2019 44648785-Java (1)
154/159
It contains set of applications to interact with our service
object.Which provides a runtime environment for our EJBComponents in the form of frameWork.
Here FrameWork is nothing but libraries.The only difference
is Libraries are used with in our application where as in frame work
they are used our application.
so FrameWork has to Know our application specification.so comming to the EJB EjbContainer is the FrameWork and
application is nothing but EJBComponents.
-> In EJB we are provide with different Components Like
.Session Bean
.Entity Bean
.Message Driven Beans
RemoteInterface:-
-
7/29/2019 44648785-Java (1)
155/159
it contains all our Bussiness Logic Methods
which throwsjava.rmi.RemoteException;
it should extends javax.ejb.EJBObject
HomeInterface:-
it contains life cycle methods which should
throws
java.rmi.RemoteException,javax.ejb.CreateException;
it should extends javax.ejb.EJBHome
BeanClass:-
it Sh ld i l t f
-
7/29/2019 44648785-Java (1)
156/159
it Should implements one of our
EJBComponents that is(SessionBean,EntityBean) or
MessageDrivenBean)should not implement our
remote or home interface Should provide the
definition for all our Business Logic Methods
.Should give the corresponding definition for
the life cycle methods define in home interface.
Enterprise JavaBeans
-
7/29/2019 44648785-Java (1)
157/159
There are three kinds of Enterprise Beans:
(i)Session Beans,(ii)Entity Beans, and
(iii)Message-Driven Beans.
A message-driven bean combines features of a
session bean and a Java Message Service (JMS)
message listener, allowing a business component
to receive JMS. A message-driven bean enables
asynchronous clients to access
the business logic in the EJB tier.
Entity Bean is a Java class which implements an
Enterprise Bean interface and provides the
-
7/29/2019 44648785-Java (1)
158/159
p p
implementation of the business methods.
There are two types:
Container Managed Persistence (CMP) and
Bean-Managed Persistence (BMP).
Session Bean is used to represent a workflow on
behalf of a client.
There are two types:Stateless and
Stateful.
Stateless bean is the simplest bean. It doesn't
maintain any conversational state with
-
7/29/2019 44648785-Java (1)
159/159
maintain any conversational state with
clients between method invocations.
Stateful bean maintains state between
invocations.