You are on page 1of 11

Layout Manager The layout manager classes are a set of classes that implement the java.AWT.

Layo ut Manager interface and help to position the component in the container. The basic layout manager includes: 1. Flow layout 2. Border layout 3. Grid layout 4. Grid Bag layout 5. Card Layout 1.FLOW LAYOUT: - The flow layout class is a simple layout manager that works lik e word processor. Components are displayed with their preferred size in the orde r in which they are added to the container. The flow layout lays out components line wise from left to right. When the line of component is filled, flow layout creates a new line and continues laying out component on the next line. //Prog for flowlayout

2.BORDER LAYOUT: - The border layout class enables specification, ie; where on t he border of a container each component should be placed. With border layout the placement of component is specified as being, North, South, East, West. The bor der layout resizes the center component to fill the remaining center space. //Prog for borderlayout

3.GRID LAYOUT:- The grid layout class lays out components in a way very similar to a spreadsheet in rows and columns. Specifying the number of rows and columns in the grid creates the grid layout. The components in grid are resized to fit t heir cell. All components in a grid layout are of the same size. //Prog for gridlayout

4.GRIDBAG LAYOUT:- The gridbag layout divides a container into a grid of equally sized cells. We can specify the location of each component in this layout by sp ecifying its x and y coordinates. The upper left corners of the coordinates are specified by grid x and y respectively. Similarly gridwidth and gridheight speci fy the width and height of the component. We can adjust the size of the componen

ts when its size is less than the display area . the mode of adjustment is speci fied by fill.

5.CARD LAYOUT:- The card layout allows only one of its component to be visible a t a time. The cardlayout considers each of its components as card. A card layout is controlled by a combo box. The state of the combo box determines which panel is displayed by the cardlayout . using the card layout the user has the option to view the following : 1. The first component 2. The last component 3. The previous component 4. The next component 5. Any component by specifying its name

///////////////////////////////////////////////////////////// EVENT HANDLING In any interactive environment the program should be able to respond to actions performed by the user. These actions can be, mouse click, keypress or selection of a menu item. The basis of event-driven programming is tying events to decide that responds to those events. Common terms of event handling : LISTENER: A Listener is an object that implements a specific Event listener . An EventList ener interface defines one or more methods that are to be invoked by the event s ource in response to each specific event type handled by the interface. EVENT SOURCE: An EventSource is an object that originates from events. ADAPTER CLASS: An Adapter class includes all methods specified by the corresponding interface b ut not providing any funtionality. Interface ---------1. ActionListener Description -------------Defines one method to receive active events

2. ItemListener Defines 1 methods to recognize when the state of an item changes . 3 KeyListener typed. Defines 3 methods to recognize when a key is pressed,released or

4. MouseListener Defines 5 methods to recognize when the mouse is clicked , enters a component,exits a Component, is pressed or is released. 5. MouseMotionListener Defines 2 methods to recognize when the mouse is dragged or moved. 6.WindowListener Defines 7 method to recognize when window is ac tivated, closed , deactivated,op

ened, or quit.

///////////////////////////////////////////////////////////////////////////

MouseListener & MouseMotion Listener The "MouseListener" is supported by the following methods : 1. The mouseClicked ( ) function is executed when mouse is clicked inside the ap plet window. 2. The mousePressed ( ) funtion is executed when mouse is pressed for sometime b eing . 3. The mouseReleased ( ) function is executed when mouse is released. 4. The mouseEntered( ) function is executed when is entered inside the applet wi ndow. 5. The mouseExited( ) function is executed when mouse is exited from applet wind ow. The "mouse MotionListener" is supported by the following methods : 1. The mouseMoved( )function is executed when mouse is moved inside the applet w indow. 2. The mouseDragged( ) function is executed when mouse is clicked and dragged in side the applet window. Note :- The methods of both class takes "MouseEvent" object as argument. The Mou seEvent class is supported by the function called getX( ),getY( ). Adapter Class By using the Adapter class some specific function of the class can be declared w here as using the Listener interface we have to define the body of all the funct ions of the interface. //////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////// Swing The earlier versions of Java were released with some simple libraries. JDK1.2 wa s introduced with a new set of packages , the Java Foundation Classes or JFC , t hat includes an improved user interface called the Swing components. The Java Foundation Classes (JFC) were developed to address the shortcom ing of AWT. The JFC visual component extend the AWT container classes. The metho ds contained in the component and container classes that AWT programmes are fami liar with ,are still valid for JFC visual classes. JFC1.2 consists of 5 major packages :1.Swing 2. Pluggable Look & Feel (PL&F) 3. Drag & Drop 4. Accessibility 5. 2D Swing components facilitate efficient graphical user interface (GUI) development . These components are a collection of lightweight visual components. Swing comp onents contain a replacement for the heavy weight AWT components as well as comp lex user-interface components such as trees & tables. The major difference between lightweight and heavy weight components is that light weight components can have transparent pixels while heavy weight comp

onents are always opaque. Lightweight components can be non-rectangular while he avy weight component are always rectangular. Jcomponent The Jcomponent class is the root of the visual component class hierarchy in the JFC. The visual components are known as the "J" classes. The functionality conta ined in the Jcomponent class is available to all the visual components in the JF C. The Jcomponent class is at the top of the hierarchy of all visual components contained in the JFC. Containers JFC has components called container. The main functionality of container is to h old components. The advantage of container is that other containers can be added to them. The simplest of JFC container component is the Jpanel class. It provid es a light weight replacement for the AWT panel class. /////////////////////////////////////////////////////////////////////// JDBC[Java Data Base Connectivity] JDBC is a set of java APIs used for executing SQL statements .The API consist of set of classes and interfaces to enable programmer to write pure java database application . JDBC is a software layer that allows developers to write real client server proj ects in java.JDBC doesnot concern itself with specific DBMS function .JDBC API[ application Programming Interface] defines how an application opens a connectio n ,communicates with a database,execute SQL statements and retrieves query resul ts. Java And JDBC java programs are secure,robust,automatically downloaded from the network and ja va is a good language to create database application to interact with different types of databases. Some Of The Advantages Using Java: 1.easy and economical 2.Continued uses of already installed database. 3.development time is short. 4.Installation and version control simplified. JDBC does the following 3 things: 1.Establish connection with a database. 2.Send SQL statements. 3.Process The Results. JDBC Vs ODBC 1.ODBC Cannot uses directly with Java because it uses C interface. 2.ODBC makes use of pointer which has been totally removed from java. 3.ODBC mixes simple and advance features together and has complex option for sim ple queries.But JDBC is designed to keep things simple while allowing advanced c apabilities when required. 4.ODBC requires manual installation of the ODBC driver managerand driver on all clients machines. JDBC drivers are written in Java code is automatically install able. JDBC Driver MODEL: 1.Two Tier Model: In this Model java application or applets interact directly with the database. 2.Three Tier Model: A middle tier is introduced in this model which is used for various purpose.Some of the Functions Of Middle tier are: i)Connection Of SQL statement from the client an handelling it over to the database. ii)Recieving result from database to the Client.

iii)Maintaining Control over accessing and updation of the data. Some Common Terms In JDBC: Connection: A Connection interface is a session in a specific Database Engine. Driver: Every connection must implement the driver interface.The Driver interface is use d to create connection Object. ResultSet: ResultSet interface provide methods for the retrieval of data returned by a SQL statement execution. Statement: The method of the statement interface are used to execute SQL Statements and ret rieve data into the ResultSet. ////////////////////////////////////////////////////////////////////// Java Networking Introduction to Networking A network is a set of computers and peripherals which are connected together. Ne tworkig enables sharing of resources and communication. Protocols Communication between computers in a network or a different network requires cer tain set of rules called protocols. Java networking is done using TCP/IP protoco ls. Some of the different kind of protocols available are HTTP(enables interacti on with the internet),FTP(enables transfer of files between computers), SMTP(pro vides e-mail facility) & NNTP(acts as a bulletin board for sharing news). Socket Sockets can be understood as a place used to plug in just like electric sockets. Here TCP/IP acts as protocol for communication & IP addresses are the addresses of the sockets. Client/Server A computer which requests for some service from another computer is called a cli ent. The one that processes the request is called a server. Internet Address Every computer connected to a network has a unique IP address. An IP address is a 32 bit number which has 4 numbers separated by periods. Domain Naming Service (DNS) It is very difficult to remember a set of numbers (IP address) to connect to the Internet. The DNS is used to overcome this problem. It maps 1 particular IP add ress to a string of characters. For Ex.www.rediff.com TCP/IP(Transmission Control Protocol/Internet Protocols) Sockets are used for data communication using this protocol. There are 2 kinds o f sockets in Java :a server and a client. Socket Class A socket object establishes connection between the client and the server. Server Socket Class The server socket object waits for the client to make a connection. An object of this class registers itself as having an interest in client connections. URL URL stand for Uniform Resource Locator and it points resource files on the Inter net. The URL helps in locating such files using their address on the Net.Java pr ovides URL class that provides an API to access information across the Internet. Components of URL The URL is the host name, port number and actual file path, the protocols may be

http, smtp, nntp, ftp or gopher. Ex of URL : (http://www.freeway.com.80/root/html files/index.html) //////////////////////////////////////////////////////////////////////////////// //////////////////// RMI(Remote Method Invocation) The Distributed Object System is a technology that combines networking and objec t oriented programming. Networks make distributed computing possible. A distributed syst em cannot be established without a network that connects nodes and allows the ex change of data. Distribute Object technologies The distributed object technologies aims at location transparency, thus making it easy to access and use an object node (called remote object) located anywhere on a network. Location transparency involves the following functions: i) Locating and loading remote classes. ii) Locating remote objects and providing a reference to them. iii) Enabling remote method calls, including passing of the reference to remote objects as arguments and accepting returns values. iv) Notifying program of network failures and other programs. RMI for distributed computing RMI is a simple method used for developing and deploying distributed object appl ications in a Java environment. Creating a distributed object application using RMI is as simple as writing a stand-alone Java application. Remote Method Invocation(RMI) enables a programmer to create distributed Java ap plication , in which the methods of remote Java objects can be called from other Java Virtual Machines running either on the same host or on different hosts sca ttered across a network. The java.rmi and java.rmiserver packages contain the interfaces and classes that defines the functionality of the Java RMI system. These packages and interfaces provide the building blocks for creating server-side and client-side object stu bs. RMI ARCHITECTURE RMI architecture consists of 4 layers: //////////////////stop here ////////////////////////////////////// The application, Stubs/skeleton, Remote reference and the Transport Layer. The RMI Layers

The RMI system implements a 4 layer model, which can be categorized as following : i) The Application Layer :- This layer contains the actual implementation of the client and server application. It is in this layer that high level calls are ma de to access and export remote objects. ii) The Proxy Layer :- This layer contains the client stub and server skeleton o bjects. The application layer communicates with this proxy layer directly. All c alls to remote objects and manipulating of parameters and return objects are don e through these proxies. iii) The Remote Reference Layer (RRL) :- The RRl handles packaging of a method c all and its parameters and its return values for transport over the network. The RRl uses a server-side and the client-side component to communicate via the network layer.

iv) The Transport Layer :- The transport layer sets up connections, manages exis ting connections and handles remote objects residing in its address space. CREATING RMI APPLICTAIONS To create an application that uses RMI, one needs to use the classes and interfa ces defined by the java.rmi package. To create an RMI application, the following steps need to be followed: 1. Defines am Interface for the Remote Classes. 2. Impliment the Interface in a server-side application. 3. Bind Objects to a Registry Service. 4. Create Stubs and Skeletons classes. 5. Create and compile the client program to Access the Remote Objects. 6. Install files on the Client and Server Machines. 7. Start the RMI Registry. //////////////////////////////////////////////////////////////////// Servlets Originally, Web sites were comprised of only static HTML documents stored in the server s file system. There was no way for the client to transmit information to the server in order to customize the information returned or stored data in a d atabase. The introduction of CGI breathed life into the static world wide web. CGI provided a mechanism for true two way communication between the client and t he server. Java Servlets are likely to succeed as the most popular Internet development tec hnology. Java Servlets are small platform independent Java Program that can be u sed to extend the functionality of the Web Server in a variety of ways. A Servlet is a server-side software component, written in Java that dynamically extend the functionality of a server. Similar to the manner in which applets ru n in a Java- enabled browser on the client, servlets execute on Java enabled We b Server. A Servlets work is done behind the servers on the server and only the results of t he servelets processing are returned to the client (usually in the form of an HT ML page). JSDK ( Java Servlet Development Kit The following software is required to develop and deploy servlets :1) Java Development Kit (JDK) 2) Java Servlet Development Kit (JSDK) 3) Servlet Enabled Web Server Before creating any servlet, it is necessary to install Java Soft s, Java Servlet Development Kit 2.0 (JSDK).JSDK can be easily downloaded from the Java Soft site http://jserv.javasoft.com . For the Servlet to find the Servlet package one need to make the following setti ngs. Assuming JSDK2.0 is installed in C drive : PATH = c:\jsdk2.0\bin; SETCLASSPATH = c:\jsdk2.0\lib\jsdk.jar Life Cycle of a Java Servlet A java servlet has a lifecycle that defines how the servlet is loaded an d initialized, how it receives and responds to request and how it is taken out o f service. In code, the servlet lifecycle is defined by the javax.servlet.servle t interface.

How a servlet is initialized :After the servlet engine loads the servlet, the engine must initialize t he servlet. Initialization is a good time for a servlet to read any persistent d ata it may have stored, initialized JDBC database connections and establish refe rences to other costly resources. How a servlet handles request :After the servlet is initialized it is ready to handle the request from a client . Each client request that is made for a servlet is done via a servlet object (o f type servlet request). The response send by servlet to client is represented b y a servlet response object (of type servlet response). When the client makes a request, the servlet engine passes both the serv let request object and the servlet response object to the servlet. The object ar e passed as parameter to the service() method, defined in the service interface which the servlet implement. Creating servlets A Servlet is like any other Java program -basically a class. To create a servlet class , that class must be subclassed either from the Generi c servlet class or some other subclass of the Generic Servlet Class. The Http Servlet ABSTRACT CLASS The Http Servlet class is an abstract class that simplifies writing HTTP servle ts. It extends the generic Servlet base class and provides a framework for handl ing HTTP protocols. Becouse it is an abstract class , servlet writers must subcl ass it and override at least one method. The method normally overridden are :1) doGet() 2) doPost() The Http Servlet request interface The Http servlet request interface encapsulates information of the request made to a servlet. This interface gets information from the client to the server for use in service() method. It allows HTTP protocol specified information to be acc essed from the service() method. The HTTP servlet response interface The HTTP servlet response interface encapsulates information of the response set by a servlet to a client. This interface allows a servlet service() method to m anipulate Http protocol specified header information and return data to its clie nt. RUNNING SERVLET Just like Java Applets require a Web Browser to run in , so also Java Servlets r equire a special environment , within which they can be executed . This special environment is nothing but some Java enabled software which can understand and w ork with the HTTP protocol. This environment should be able to accept an HTTP re quest and route a response back to the client. This environment can be found in SunMicro system ServletRunner software, which is part of the JSDK. /////////////////////////////////////////////////////// JSP A JSP is simpler to create than a java servlet bcoz a JSP is written in HTML ra ther than with the java programming lang. There are 3 methods that are automatic ally called when a JSP is requested and when the JSp terminates normally.These a re the jspInt(),jspDestroy() and service() methods. The jspInt() method in java is identical to init() method in java servle t and in applet.The jspInt() method is called first when the JSp is requested an d is used to initialise object & variables that are used throughout the life of the JSP.

The jspDestroy() method is identical to the destroy() method in java ser vlet.The jspDestroy() method is automatically called when the JSP terminates nor mally.It isn't called if the JSp server crashes. The service() method is automatically called and retrieves a connection to HTTP. JSP Tags:A JSP program consist of a combination of HTML tags and JSP tags.JSP tags define java codeis to be executed before the output of the JSP program is sent to the browser. A JSP tag begins with <% ,which is followed by java code & ends with %>.There is also an Extendable MarkUp Language. Language (XML) version of JSp tags, which are formatted as <jsp:tagID> </JSP:ta gID> There are 5 types of JSP Tags. *Comment Tag:-A Comment atg open with <%-- & closes with --%>,and is fol lowed by a comment that usually describes that functionality of statements that followed by the comment tag. *Declaration Statement Tag:-A Declaration statement tag opens with <%! a nd ends with %> & is followed by a java declaration statement that defines vari ables,objects & methods that are available to the other component of the JSP Pro gram. *directive Tag:-A directive tag opens with <%@ and commands the java vir tual machine to perform a specific task,such as importing a java package require d by object and methods used in a declartaion statement.The directive tag closes with %> *Expression tag:-An expression tag opens with <%= and is used for an exp ression statement whose result replaces the expression tag when the JSP virtual engine resolves JSP tags.An expressi on tags closes with %> *Scriplet Tag:-A scriplet tag opens with <% and contains the commonly us ed java control statement & loops.A Scriplet tag tag closes with %> Tomcat JSP programs are executed by JSP virtual machine that runs on a web server.There fore,you'll need to have access to a JSP virtual machine to run your JSP program . Alternatively you can use an integrated development envoirment such as JBuilde r that has a built-in-JSP virtual machine or you can download & install a JSP vi rtual machine. One of the most popular JSP virtual machine is tomcat,& it is downloadable at no charge from the apache website. RequestString: The browser generates a user requestString whenever the submit button is selecte d.The User requestString consist of the URL and the query string.

JDBC (Java Database Connectivity) JDBC is a set of Java APIs used for executing SQL statements. This API consists of set of classes and interfaces to enable programmer to write pure Java Databas e applications. JDBC is a software layer that allows developers to write real client-ser ver projects in Java. JDBC does not concern itself with specific DBMS functions.

JDBC API(Application Programming Interface) defines how an application opens a connection, communicates with a database executes SQL statement and retrives qu ery results. Java and JDBC Java programs are secure, robust, automatically downloaded from the network and Java is a good language to create database applications to interact with differe nt types of database. Some of the advantages of using Java : 1) Easy and economical 2) Continued usage of already installed database. 3) Development time is short. 4) Installation and version control simplified. JDBC does the following 3 things: 1) Establish connection with a database. 2) Send SQL statements. 3) Process the results. JDBC Vs ODBC 1) ODBC cannot be directly used with Java becouse it uses a C interface. 2) ODBC makes use of pointer which have been totally removed from Java. 3) ODBC mixes simple and advance feature together and has complex option fo r simple queries. But JDBC is designed to keep things simple while allowing adv anced capabilities when required. 4) ODBC requires manual installation of the ODBC driver manager and driver on all client machines. JDBC drivers are written in Java code is automatically i nstallable. JDBC driver model 1) Two tier model :- In this model Java application/ applets interact direc tly with the database. 2) Three tier model :- a middle tier is introduced in this model, which is used for various purpose. Some of the functions of the middle tiers are:i) Collection of SQL statements from the client and handling it over to the database. ii) Receiving result from database to the client. iii) Maintaining control over accessing and updation of the data. Connection :A connection interface is a session in a specific database engine. Driver :Every connection must implement the driver interface. The driver interfa ce is used to create connection objects. ResultSet ResultSet interface provides methods for the retrieval of data returned by a SQL statement execution. Statement The methods of the Statement interface are used to execute SQL statement and retrieve data into the result set. DriverManager The DriverManager class is used to load and unload the drivers and establishes c onnection with the database .

Java Beans A growing trend in the fields of software developed is the use of reusable compo nents i.e. elements of a program that can be used with more than one software pa ckage. Java Beans is an architecture and platform independent set of classes for creati ng and using Java software components. Beans are building blocks for creating ap plications. There can be visual beans like sliders, buttons, menulist and so on. Beans support the software component model which focuses on the use of componen ts and containers. Components:Components are specialized, self contained software entities that can be replica ted, customized and inserted into applications and applets. Containers:Containers are components that contain other components. Containers can be used as a framework for visually organizing components. Visual development tools allo w components to be dragged and dropped into a container, resized and positioned.

You might also like