Basic java part_ii


Published on

Published in: Technology, Art & Photos
  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Basic java part_ii

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

    Clipping is a handy way to collect important slides you want to go back to later.