basic java part_ii
DESCRIPTION
TRANSCRIPT
![Page 2: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/2.jpg)
2
Java Beans+ Component architecture, a reusable software component written in Java programming language.
+ Components (JavaBeans) are reusable software programs that you can develop and assemble easily to create sophisticated applications.
+ Used for using & building components in Java.
+ Doesn’t alter the existing Java language.
![Page 3: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/3.jpg)
3
Features of Java Bean
Independent Reusability Secure Bean Bridge Interface Etc.
![Page 4: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/4.jpg)
4
Basic Bean Concepts Properties Introspection Customization Events Persistence Methods
![Page 5: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/5.jpg)
5
Java Beans : Properties
• Simple Properties
• Indexed Properties
• Bound Properties
• Constrained Properties
![Page 6: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/6.jpg)
6
Java Beans : Introspection
• Introspection allows a builder tool to analyze how Beans work. They adhere to specific rules called design patterns for naming Bean features.
![Page 7: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/7.jpg)
7
Java Beans : Customization
• Customization allows a user to alter the appearance and behavior of a Bean.
• Beans support customization by using property editors.
![Page 8: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/8.jpg)
8
Java Beans : Events
+ Events are used by Beans to communicate with other Beans.
+ Beans fire events.
+ The Bean receiving event is called a listener Bean.
![Page 9: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/9.jpg)
9
Java Beans : Persistence
+ Beans use Java object serialization, to save and restore state that may have changed as a result of customization.
![Page 10: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/10.jpg)
10
Java Beans : Methods
+ Identical to Java classes.
![Page 11: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/11.jpg)
© 2004 VeriSign, Inc.
Applet
![Page 12: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/12.jpg)
12
Introduction
+ Java Application vs Java Applets+ Running Java Applet
+ Using Browser+ Using Appletviewe
+ Java includes classes.
![Page 13: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/13.jpg)
13
Applet Class
+ All applets are subclass of the Applet class.+ Applet Class is present in the ‘java.applet’ package. + Applet must import java.applet and java.awt.+ Applets contain a single default class.
![Page 14: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/14.jpg)
14
Creating, Running and executing an Applet
import java.applet.Applet;import java.awt.Graphics; public class FirstApplet extends Applet {
public void paint(Graphics g){
g.drawString(“Welcome to the World of Applets!!”, 10, 50);}
}
![Page 15: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/15.jpg)
15
Viewing In Applet
+ Write a HTML file, and view it in browser
+ Include a commented applet tag in the java program and view it in appletviewer.
![Page 16: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/16.jpg)
16
Activities In An Applet
Creation
Initialization
Starting
Stop
Destroy
![Page 17: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/17.jpg)
17
Paint() Method
+ Paint is how an applet displays something on the screen. This can be anything from a text, a line, background color or an image.
+ public void paint(Graphics g)
{
g.drawString( String message, int x, int y);
}
![Page 18: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/18.jpg)
18
Repaint() Method
+ Whenever your applet needs to update the information displayed in its window, it simply calls repaint().
+ The repaint() method is defined by the AWT.
+ It causes the AWT run-time system to execute a call to your applet’s update() method, which, in its default implementation, calls paint()
![Page 19: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/19.jpg)
19
HTML Applet Tag
<APPLET[CODEBASE = codebaseURL]CODE = appletFile[ALT = alternateText][NAME = appletInstanceName]WIDTH = pixels HEIGHT = pixels[ALIGN = alignment][VSPACE = pixels][HSPACE = pixels]>[< PARAM NAME = attributeName VALUE = AtrributeValue>]..</APPLET>
![Page 20: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/20.jpg)
20
Passing Parameters to Applets
+ The Applet tag in HTML allows you to pass parameters to your applet. To retrieve a parameter, use the getParameter() method.
![Page 21: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/21.jpg)
21
Important Methods
+ getDocumentBase( )+ Returns the path of the document file as url.
+ getCodeBase( )+ Returns the path of .class file as url
![Page 22: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/22.jpg)
22
Applet Context
+ Methods Of Applet Context+ Void showDocument(URL url)
+ Void showDocument(URL url String where) + AudioClip getAudioClip(URL url)
+ AudioClp getAudioClip(URL url, String name) + Image getImage(URL url)
+ Image getImage(URL url, String name)
![Page 23: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/23.jpg)
23
Applet Context (Contd…)
+ Enumeration getApplets().
+ Applet getapplet(String name)
![Page 24: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/24.jpg)
24
Security Restrictions applied on Applets
+ Cannot read or write files on the user system.+ Cannot communicate with an Internet site but only with the one that
served the web page including the applet. + Cannot run any programs on the reader’s system. + Cannot load any programs stored on the user’s system.
![Page 25: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/25.jpg)
25
File Name Filters
+ FilenameFilter+ public boolean accept(File dir, String name)
+ Sample Program
![Page 26: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/26.jpg)
26
+ RandomAccessFile Class+ This class provides the capability to perform I/O to specific locations
within a file. + The name randomaccess is due to the fact that data can be read or
written to random locations within a file instead of a continuous stream of information.
+ An argument ‘r’ or ‘rw’ is passed to the RandomAccessFile indicating read-only and read-write file access.
![Page 27: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/27.jpg)
© 2004 VeriSign, Inc.
Java Thread
![Page 28: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/28.jpg)
28
Thread
+ Benefits + User and Kernel Threads+ Multithreading Models+ Solaris 2 Threads+ Java Threads
![Page 29: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/29.jpg)
29
![Page 30: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/30.jpg)
30
![Page 31: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/31.jpg)
31
![Page 32: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/32.jpg)
32
![Page 33: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/33.jpg)
33
MultiThread Models
+ Many-to-One
Many User-Level Threads Mapped to Single Kernel Thread.
Used on Systems That Do Not Support Kernel Threads.
![Page 34: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/34.jpg)
34
![Page 35: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/35.jpg)
35
![Page 36: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/36.jpg)
36
![Page 37: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/37.jpg)
37
![Page 38: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/38.jpg)
38
![Page 39: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/39.jpg)
39
![Page 40: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/40.jpg)
40
Java Thread
+ Java Threads May be Created by:+ – Extending Thread class+ – Implementing the Runnable interface
![Page 41: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/41.jpg)
41
Extending Thread Class
class Worker1 extends Thread
{
public void run() {
System.out.println(“I am a Worker Thread”);
}
}
![Page 42: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/42.jpg)
42
Creating the Thread
public class First
{
public static void main(String args[]) {
Worker runner = new Worker1();
runner.start();
System.out.println(“I am the main thread”);
}
}
![Page 43: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/43.jpg)
43
Runnable Interface
public interface Runnable
{
public abstract void run();
}
![Page 44: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/44.jpg)
44
Implementing Runnable
class Worker2 implements Runnable
{
public void run() {
System.out.println(“I am a Worker Thread”);
}
}
![Page 45: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/45.jpg)
45
Creating the Threadpublic class Second
{
public static void main(String args[]) {
Runnable runner = new Worker2();
Thread thrd = new Thread(runner);
thrd.start();
System.out.println(“I am the main thread”);
}
}
![Page 46: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/46.jpg)
46
Java Thread Management
+ suspend() – suspends execution of the currently running thread.+ • sleep() – puts the currently running thread to sleep for a+ specified amount of time.+ • resume() – resumes execution of a suspended thread.+ • stop() – stops execution of a thread.
![Page 47: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/47.jpg)
47
![Page 48: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/48.jpg)
48
Life Cycle of a Thread
new Threadnew Thread
runnablerunnable
blockedblocked
deaddead
start( )
stop( )
sleep( )
suspend( )
resume( )
notify( )
wait( )
![Page 49: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/49.jpg)
49
What is Multithreading?
+ A thread is a smallest unit of executable code that performs a particular task.
+ Java supports multithreading. + An application can contain multiple threads. + Each thread is specified a particular task which is executed
concurrently with the other threads. + The capability of working with multiple thread is called
Multithreading.
![Page 50: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/50.jpg)
50
What is Multithreading? (Contd…)
+ Multithreading allows you to write efficient programs that makes the maximum use of CPU, by keeping the idle time to a minimum.
+ It is a specialized form of multitasking.+ Multitasking is running multiple programs simultaneously, with each
program having at least one thread in it. + These programs are executed by a single processor.
![Page 51: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/51.jpg)
51
Thread Scheduling and Setting the Priorities (Contd…)
+ It is the programmer, or the Java Virtual Machine or the operating system that makes sure that the CPU is shared between the threads.
+ This is called scheduling of threads.+ Every thread in Java has its own priority. + This priority is in the range:
+ Thread.MIN_PRIORITY &+ Thread.MAX_PRIORITY
![Page 52: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/52.jpg)
52
Thread Scheduling and Setting the Priorities (Contd…)
+ By default, a thread has a priority of Thread.NORM_PRIORITY, a constant of 5.
+ Every new thread that is created, inherits the priority of the thread that creates it.
+ The priority of the thread can be adjusted with the method called setPriority( ).
+ This takes an integer as an argument. + This value has to be within the range of 1 to 10, else, the method throws
an exception called as IllegalArgumentException.
![Page 53: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/53.jpg)
53
Daemon Threads
+ A Java program is terminated only after all threads die. + There are two types of threads in a Java program:
+ User threads+ Daemon threads
+ The threads that are created by the Java Virtual Machine on your behalf are called daemon threads.
+ Java provides garbage collector thread that reclaims dynamically allocated memory.
![Page 54: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/54.jpg)
54
Daemon Threads (Contd…)
+ This thread runs as a low priority thread + The garbage collection is marked as a daemon thread.+ Thread class has two methods that deal with daemon threads.
+ public void setDaemon(boolean on)+ public boolean isDaemon( )
![Page 55: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/55.jpg)
55
Thread Synchronization
+ It may so happen that more than one thread wants to access the same variable at the same time
+ One thread tries to read the data while the other tries to change the data. + What we need to do is, allow one thread to finish its task completely
(changing the value) and then allow the next thread to read the data. + This can be attained with the help of synchronized( ) method. + This method tells the system to put a lock around a particular method.
![Page 56: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/56.jpg)
56
InterThread Communication
+ Necessary to avoid polling + Methods
+ wait()+ notify()+ notifyAll()
![Page 57: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/57.jpg)
© 2004 VeriSign, Inc.
JDBC
![Page 58: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/58.jpg)
58
JDBC
+ Overview of JDBC and its design goals+ Key API classes+ Some examples
![Page 59: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/59.jpg)
59
What is JDBC?
+ JDBC is a Java™ API for executing SQL+ statements+ It’s deliberately a “low level” API+ But it’s intended as a base for higher level APIs+ And for application builder tools+ It’s influenced by existing database APIs+ Notably the XOPEN SQL CLI+ And Microsoft’s ODBC
![Page 60: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/60.jpg)
60
![Page 61: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/61.jpg)
61
Types of JDBC technology drivers
+ JDBC-ODBC Bridge+ Native API Partly+ Net Protocol Fully+ Native Protocol Fully
![Page 62: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/62.jpg)
62
JDBC-ODBC bridge
+ JDBC API access via one or more ODBC drivers+ ODBC native code and in many cases native database client code
must be loaded on each client machine+ (e.g) Microsoft ODBC-Drivers
![Page 63: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/63.jpg)
63
native-API partly
+ JDBC calls into calls on the client API for Oracle, Sybase, Informix, DB2, or other DBMS
+ this style of driver requires that some binary code be loaded on each client machine
+ Native Module of dependent form of H/W like .dll or .so.+ (e.g) OCI driver for local connection to Oracle
![Page 64: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/64.jpg)
64
net-protocol fully
+ JDBC API calls into a DBMS-independent net protocol which is then translated to a DBMS protocol by a server
+ able to connect to many different databases+ (e.g) III party Driver using protocol depends on the vendor
![Page 65: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/65.jpg)
65
native-protocol fully
+ JDBC technology calls into the network protocol used by DBMSs directly
+ a direct call from the client machine to the DBMS server+ It is independent from H/W because this driver is %100 java.+ (e.g) thin driver for local/global connection to Oracle
![Page 66: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/66.jpg)
66
![Page 67: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/67.jpg)
67
![Page 68: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/68.jpg)
68
![Page 69: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/69.jpg)
69
![Page 70: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/70.jpg)
70
![Page 71: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/71.jpg)
71
![Page 72: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/72.jpg)
72
![Page 73: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/73.jpg)
73
![Page 74: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/74.jpg)
74
![Page 75: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/75.jpg)
75
![Page 76: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/76.jpg)
76
![Page 77: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/77.jpg)
77
![Page 78: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/78.jpg)
78
![Page 79: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/79.jpg)
79
Seven Basic Steps in Using JDBC
+ Load the Driver+ Define the Connection URL+ Establish the Connection+ Create a Statement Object+ Execute a Query+ Process the result+ Close the Connection
![Page 80: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/80.jpg)
80
+ Three types of statement objects are available+ Statement : executing Simple Query+ PreparedStatement : for executing pre-compiled SQL Statement + CallableStatement : for executing data base stored Procedure
![Page 81: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/81.jpg)
81
![Page 82: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/82.jpg)
82
![Page 83: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/83.jpg)
83
![Page 84: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/84.jpg)
84
![Page 85: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/85.jpg)
85
JDBC Transaction
![Page 86: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/86.jpg)
86
JDBC Transaction
![Page 87: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/87.jpg)
87
Learnings from this Session
+ Tell me few responsibility of DriverManager+ What are the three different Statements?+ What is ResultsetMetaData?+ What is DatabaseMetaData?+ Write a Simple prg to create your own SQL> prompt and we can run
any SELECT query.
![Page 88: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/88.jpg)
© 2004 VeriSign, Inc.
Networking in Java
![Page 89: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/89.jpg)
89
Types Of Network Programming
Two general types are :+ Connection-oriented programming + Connectionless Programming
![Page 90: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/90.jpg)
90
Connection-oriented Networking
The client and server have a communication link that is open and active from the time the application is executed until it is closed. Using Internet jargon, the Transmission control protocol os a connection oriented protocol. It is reliable connection - packets are guaranteed to arrive in the order they are sent.
![Page 91: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/91.jpg)
91
Connection-less Networking
The this type each instance that packets are sent, they are transmitted individually. No link to the receiver is maintained after the packets arrive. The Internet equivalent is the User Datagram Protocol (UDP). Connectionless communication is faster but not reliable. Datagrams are used to implement a connectionless protocol, such as UDP.
![Page 92: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/92.jpg)
92
Common Port Numbers
Port Number Service
21 FTP
23 Telnet
25 SMTP
80 Http (Web)
110 POP
143 IMAP
443 HTTS (SSL)
![Page 93: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/93.jpg)
93
![Page 94: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/94.jpg)
94
![Page 95: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/95.jpg)
95
URI, URL, URLConnection and HttpURLConnection
+ URI -Universal Resource Identifier -For parsing+ URL -Universal Resource Locator -For fetching+ URLConnection -Finer control of the transfer+ HttpURLConnection -Subclass specific to HTTP
![Page 96: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/96.jpg)
96
URL
+ URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet.
+ http://www.abc.com/
Protocol Identifier Resource Name
![Page 97: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/97.jpg)
97
URL(contd…)
+ Contrustors Of URL are:+ URL(String urlspecifier)
+ Constructor that allows to break up the URL into its component parts are:
+ URL(String protocolName, String hostname, int port, String path)+ URL(String protocolName, String hostname, String path)
![Page 98: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/98.jpg)
98
URL(contd…)
+ java.net.url consists of the following methods:+ openConnection( )
– This method establishes a connection and returns a stream.
+ getContent( )– This method makes a connection and reads addressed
contents.+ getFile( )
– This method returns the filename part of the URL.
![Page 99: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/99.jpg)
99
URL(contd…)
+ getHost( )– This method returns only the host name part from the URL.
+ getPort( )– This method returns the port number part from the URL.
+ getProtocol( )– This method returns the name of the protocol of the URL.
![Page 100: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/100.jpg)
100
URL(contd…)
+ URLConnection Class+ If we have an active HTTP connection to the web, the URLConnection
class encapsulates it. + It is an abstract class. + Its objects can be created from a single URL. + The URLConnection constructor is protected, hence to create a
URLConnection, we have to first open the connection using the openConnection( ) method.
![Page 101: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/101.jpg)
101
URL(contd…)
+ This class supports several methods so as to modify the defaults, query and modify the current settings for a URLConnection object.
+ The methods are:
+ connect( )
– To open a communication link.
+ getDate( )
– To get the value of the date.
![Page 102: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/102.jpg)
102
URL(contd…)
+ getExpiration( )
– To get the date of expiration of the URL.
+ getInputStream( )
– To get the InputStream that can be used to read the resource.
+ getLastModified( )
– To get the date last modified.
+ getURL( )
– To get the URL used to establish a connection.
![Page 103: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/103.jpg)
103
Inside java.net
+ java.net package consists of the following classes:
+ Socket
+ InetAddress
+ ServerSocket
+ DatagramSocket
+ DatagramPacket
![Page 104: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/104.jpg)
104
Inside java.net (Contd…)
+ InetAddress Class+ Eases finding of addresses of the Internet. + Summarizes Internet IP addresses.
+ The static getByName method returns an InetAddress object of a host.
+ getLocalHost method to get the address of your localhost.
![Page 105: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/105.jpg)
105
Inside java.net (Contd…)
+ Socket Class+ Java programs connect to the network using a socket. + The socket class helps in establishing client connections. + It is this socket that helps establishing connections and developing
applications between the client and server.
![Page 106: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/106.jpg)
106
Inside java.net (Contd…)
+ Socket class has eight constructors that create sockets. + They in turn connect to the destination host and port. + The port number of the machine to which the socket is connected is
obtained by the getPort( ) method. + The local port number is obtained using the getLocalPort( ) method.
![Page 107: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/107.jpg)
107
Inside java.net (Contd…)
+ The local IP address is obtained using the getLocalAddress( ). + The input and output streams are accessed using the
getInputStream( ) and getOutputStream( ) methods. + The socket is closed using the close( ) method.+ The string representation of the object is written using the toString( )
method.
![Page 108: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/108.jpg)
108
Inside java.net (Contd…)
+ The method to switch from the default Java socket implementation to a custom socket implementation is defined using the setSocketImplFactory( ) method.
![Page 109: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/109.jpg)
109
Inside java.net (Contd…)
+ ServerSocket Class+ The TCP server socket is implemented using the ServerSocket class. + There are three constructors specifying the port to which the server socket is to
listen for incoming connection requests. + The address of the host to which the socket is connected is returned using
getInetAddress( ) method. + The local port on which the server socket listens for incoming connection is
returned using the getLocalPort( ) method. + The socket’s address and port number is returned as a string using the toString( )
method.
![Page 110: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/110.jpg)
110
Inside java.net (Contd…)
+ DatagramSocket Class+ This class is used to implement the client and server sockets using the User
Datagram Protocol (UDP) protocol. + This class provides three constructors.
+ The default constructor creates a datagram socket. This is used by client applications. In this case no port number is specified.
+ The second constructor creates a datagram socket using a specified port. This is generally with the server applications.
+ The third constructor allows an Internet Address to be specified in addition to the port.
![Page 111: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/111.jpg)
111
Inside java.net (Contd…)
+ The datagrams are sent and received using the send( ) and receive( ) methods respectively.
+ The local port and Internet address of the socket is returned using the getLocalPort( ) method and getLocalAddress( ) method respectively.
![Page 112: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/112.jpg)
112
Inside java.net (Contd…)
+ DatagramPacket Class
+ This class encapsulates the datagrams that are sent and received using objects
of class DatagramSocket.
+ There are two different constructors, one for datagrams that are received from
the datagram socket and the other for creating datagrams that are sent over the
datagram socket.
![Page 113: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/113.jpg)
113
Inside java.net (Contd…)
+ There are about eight access methods provided such as:+ getAddress( ) and getPort( ) for reading the destination IP address and port
of the datagram.
+ getLength( ) and getData( ) for getting the number of bytes of data in the datagram and reading the data into a byte array buffer.
+ setAddress( ), setPort( ), setLength( ) and setData( ) to allow the datagram’s IP address, port, length and data values to be set.
![Page 114: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/114.jpg)
© 2004 VeriSign, Inc.
JNDI
![Page 115: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/115.jpg)
115
Overview of the Architecture
+ The JNDI architecture consists of the JNDI API and the JNDI SPI. + The JNDI API allows Java applications to access a variety of
naming and directory services.+ The JNDI SPI is designed to be used by arbitrary service providers
including directory service providers.
![Page 116: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/116.jpg)
116
JNDI Architecture
![Page 117: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/117.jpg)
117
JNDI Architecture
![Page 118: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/118.jpg)
118
Composite NameSpace
![Page 119: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/119.jpg)
119
Lookup Process
![Page 120: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/120.jpg)
120
Lookup Process
![Page 121: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/121.jpg)
121
Mapping Directory To Schema
![Page 122: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/122.jpg)
© 2004 VeriSign, Inc.
RMI
![Page 123: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/123.jpg)
123
What is Distributed System?
![Page 124: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/124.jpg)
124
![Page 125: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/125.jpg)
125
![Page 126: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/126.jpg)
126
![Page 127: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/127.jpg)
127
![Page 128: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/128.jpg)
128
![Page 129: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/129.jpg)
129
![Page 130: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/130.jpg)
130
![Page 131: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/131.jpg)
131
![Page 132: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/132.jpg)
132
![Page 133: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/133.jpg)
133
![Page 134: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/134.jpg)
134
![Page 135: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/135.jpg)
135
![Page 136: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/136.jpg)
136
![Page 137: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/137.jpg)
137
![Page 138: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/138.jpg)
138
![Page 139: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/139.jpg)
139
![Page 140: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/140.jpg)
140
![Page 141: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/141.jpg)
141
![Page 142: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/142.jpg)
142
![Page 143: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/143.jpg)
143
![Page 144: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/144.jpg)
144
RMI Registry
![Page 145: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/145.jpg)
145
RMI Communication
![Page 146: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/146.jpg)
146
![Page 147: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/147.jpg)
147
![Page 148: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/148.jpg)
148
![Page 149: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/149.jpg)
149
![Page 150: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/150.jpg)
150
![Page 151: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/151.jpg)
151
![Page 152: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/152.jpg)
152
![Page 153: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/153.jpg)
153
![Page 154: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/154.jpg)
154
UnicastRemoteObject
+ The server typically extends class+ java.rmi.server.UnicastRemoteObject+ The constructor of this class throws a RemoteException+ Therefore, so should the constructor of any specialization.
![Page 155: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/155.jpg)
155
UnicastRemoteObject
+ Most arguments and results+ are converted to a sequence of bytes;+ the bytes are sent over the net+ therefore the class should implement the java.io.Serializable interface+ a clone of the argument/result is constructed on the other side.+ The effect is pass by object value, rather than by object reference.
![Page 156: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/156.jpg)
156
![Page 157: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/157.jpg)
157
![Page 158: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/158.jpg)
158
![Page 159: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/159.jpg)
159
![Page 160: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/160.jpg)
160
![Page 161: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/161.jpg)
161
![Page 162: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/162.jpg)
162
![Page 163: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/163.jpg)
163
RMI Issues
+ Concurrency -If there are multiple clients, the server may field multiple calls at the same time. So use synchronization as appropriate.
+ Argument passing - Arguments are usually passed by value, not reference.+ Proxy and Skeleton generation- Proxy and Skeleton classes are
automatically derrived from the server class+ Lookup - Objects are usually found via a registry
![Page 164: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/164.jpg)
164
RMI Issues
+ The proxy and the server share an interface. This interface must extend java.rmi.remote.
+ Every method in the interface should be declared to throw java.rmi.RemoteException
+ RemoteExceptions are thrown when network problems are encountered,
+ or when server objects no longer exist.
![Page 165: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/165.jpg)
165
Learning from this session
+ Tell me the Default port of RMI+ Remote+ UniCastRemoteObject+ RmiRegistry+ Stub & Skeleton
![Page 166: Basic java part_ii](https://reader034.vdocuments.net/reader034/viewer/2022042623/54540feab1af9f99228b4847/html5/thumbnails/166.jpg)
© 2004 VeriSign, Inc.
Thank You