JAVA & J2EE Laboratory


CONTENTS SL No 1 Program Title a) Write a JAVA Program to demonstrate Constructor Overloading and Method overloading. b) Write a JAVA Program to implement Inner class and demonstrate its Access Protections. a) Write a JAVA Program to implement Inheritance. b) Write a JAVA Program to implement Exception Handling (Using Nested try catch and finally). a) Write a JAVA Program to create an Interface and implement it in a class. b) Write a JAVA Program to create a class (extending Thread) and use methods Thread class to change name, priority, ---- of the current Thread and display the same. a) Write a JAVA Program to create a Scrolling Text using JAVA Applets. b) Write a JAVA Program to pass parameters to Applets and display the same. Write a JAVA Program to insert data into Student DATA BASE and retrieve info base on particular queries(Using JDBC Design Front end using Swings). Write a JAVA Program to implement Client Server (Client requests a file, Server responds to client with contents of that file which is then display on the screen by Client – Socket Programming). Write a JAVA Program to implement a simple Client Server Application using RMI. Write a JAVA Servlet Program to implement a dynamic HTML using Servlet (user name and password should be accepted using HTML and displayed using a Servlet). Write a JAVA Servlet Program to Download a file and display it on the screen (A link has to be provided in HTML, when the link is clicked corresponding file has to be displayed on Screen) a) Write a JAVA Servlet Program to implement RequestDispatcher object (use include() and forward() methods). b) Write a JAVA Servlet Program to implement and demonstrate get() and Post methods(Using HTTP Servlet Class). Write a JAVA Servlet Program to implement sendRedirect() method(using HTTP Servlet Class). Write a JAVA Servlet Program to implement sessions (Using HTTP Session Interface). BMSIT 1 Page No.





6 7 8 9


11 12

Department of MCA

JAVA & J2EE Laboratory




a) Write a JAVA JSP Program to print 10 even and 10 odd number. b) Write a JAVA JSP Program to implement verification of a particular user login and display a welcome page. Write a JAVA JSP Program to get student information through a HTML and create a JAVA Bean Class, populate Bean and display the same information through another JSP.

Department of MCA



JAVA & J2EE Laboratory


OVERVIEW OF JAVA AND J2EE Java is a open source technology developed by Sun Microsystems. It is pure object oriented language incorporating object oriented features. Java is a programming language As a programming language, Java can create all kinds of applications that could create using any conventional programming language. Java is a development environment As a development environment, Java technology provides you with a large suite of tools: a compiler, an interpreter, a documentation generator, a class file packaging tool,and so on. Java is an application environment Java technology applications are typically general-purpose programs that run on any machine where the Java runtime environment (JRE) is installed. The Java Virtual Machine is a system that loads, verifies and executes java bytecodes . The java virtual machine is an imaginary machine that is implemented by emulating software on a real machine. The JVM provides the hardware platform specifications to which you compile all Java technology code. This specification enables the Java software to be platform-independent because the compilation is done for a generic machine known as the JVM. A bytecode is a special machine language that can be understood by the Java Virtual Machine (JVM). The bytecode is independent of any particular computer hardware, so any computer with a Java interpreter can execute the compiled Java program, no matter what type of computer the program was compiled on Generally, the java developer writes the java program and stores the program in a .java file. The java compiler translates this java program file into a .class file consisting of bytecodes. The bytecodes comprise the instruction set for the java virtual machine.The format of the bytecode is as follows: <opcode><…parameters> The length of the opcode is one byte long(hence name bytecode).At present Java Virtual machine has about 220 bytecode instructions. The java virtual machine modules are usually written n C,C++ or in Assembly language for an operating system. Some Features of Java 1) The Java Virtual Machine The Java Virtual Machine is an imaginary machine that is implemented by emulating software on a real machine. The JVM provides the hardware platform specifications to which you compile all Java technology code. This specification enables the Java software

Department of MCA



class file is then interpreted by the Java interpreter that converts the bytecodes into the machine language of the particular computer Task Tool to use Output Write the program Any text editor File with . The first step in creating a Java program is by writing your programs in a text editor.class. vi. no matter what type of computer the program was compiled on. The . there should be a way to deallocate that memory block in order for other programs to use it again. The JRE runs code compiled for a JVM and performs class loading (through the class loader). Phases of a Java Program The following figure describes the process of compiling and executing a Java program. After creating and saving your Java program. This file is stored in a disk file with the extension . emacs. In Java. The bytecode is independent of any particular computer hardware. The output of this process is a file of Java bytecodes with the file extension . However.JAVA & J2EE Laboratory 07MCA41 to be platform-independent because the compilation is done for a generic machine known as the extension Compile the program Java Compiler File with . code verification (through the bytecode verifier) and finally code execution. etc. after using that allocated memory. so any computer with a Java interpreter can execute the compiled Java program.class extension (Java bytecodes)Run the program Java Interpreter Program Output Department of MCA BMSIT 4 . 2) A bytecode is a special machine language that can be understood by the Java Virtual Machine (JVM).java. the programmer is freed from the burden of having to deallocate that memory themselves by having what we call the garbage collection thread. The garbage collection thread is responsible for freeing any memory that can be freed. This happens automatically during the lifetime of the Java program. This can be difficult at times since there can be instances wherein the programmers forget to deallocate memory and therefore result to what we call memory leaks. C++ and other languages the programmer is responsible for this. compile the program by using the Java Compiler. Examples of text editors you can use are notepad. 3) Java is portable : provides same API functions or library system calls on each system . In C. making platform independent 4)Garbage Collection Many programming languages allows a programmer to allocate memory during runtime. Code security is attained in Java through the implementation of its Java Runtime Environment (JRE).

It used java. 5: JDBC – Java Database Connectivity It helps to create database application by making use of SQL package .*. By using the above packages. JBuilder. It is used to invoke the methods of an object existing in separate computer.It contains following packages a) Java. 2: Threads It helps to create multithreaded applications 3: Applets A java applet is a small program embedded in web page and it will be run when that page is browsed in web browser.awt. button . graphics can be drawn. It contains Javax. To draw applet. border shapes.swing package. blinks etc.event. Textfield .Particular database driver must be installed in the system 6: Socket Programming It helps to create distributed application by implementing networking Concepts. and GUI components like textarea. it is alternative for socket programming Department of MCA BMSIT 5 .net package 7: RMI – Remote Method Invocation It is used for inter-process communication between java virtual machines. Notepad. advanced layouts .JAVA & J2EE Laboratory 07MCA41 Requirement for writing Java Programs Editors : Eclipse. NetBeans Java Development Kit ver 1. applet package must be imported 4: Swings It contains advanced GUI components like progress basr.4 and above Java Runtime Environment Java has following topics Java helps to create standalone application by using the following topics 1: AWT –Abstract Window Toolkit : It helps to create Graphical User Interface by using built in packages and classes .* b) Java.

Dynamic Hypertext Markup Language It helps to create Interface for web application by using built in tags 2: XML-Extensible Markup LANGUAGE 07MCA41 3: Java script It helps to validate client information before sending the information to the server for processing 4: SERVLETS – It is a server side programming language. performs some task and return the result to the client 3 servlet is preferred than other server sided programs because of a) less start up cost b)continuous connection between server and client c)platform independent 4 All servlet programs is a java program and html tags are embedded in it 5 Servlet is of 2 types Generic servlet and http servlet a) Http servlet runs only on http protocol b) Generic Servlet runs on any protocol 6) Webserver like tomcat server is required to run servlet Servlet program is a java program which is saved as .java file and it is compiled After compiling . tomcat server. Next open the Browser give the path like http://localhost:8080/examples/servlet/servletname Department of MCA BMSIT 6 . and configuring the server is also required. 5: JSP –Java Server Pages. Servlet 1 A servlet is a mini server side program which is loaded by web server and executed in the web browser 2 A servlet accesses request from the client.This technology helps to create server side application. class file has to be copied to C:\Tomcat\webapps\examples\WEBINF\classes. . Care has to be taken that tomcat server is running.JAVA & J2EE Laboratory J2EE has following topics J2EE helps to create web application by using following topics 1: DHTML.Tools required to run JSP are jsdk. server is required to run the servlet. Any server is required to run JSP. Here html programs are embedded in java program .

It is a server sided programming language in which java codes are embedded in HTML tags . SevletContext. session id. There are5 types of JSP tags 1) Comment tag This tag is used for commenting the statements <%-This is a comment --%> 2) Declaration tag This tag is used for declaring java declaration statements that define variables.collects the header information. used to send information about error.content lengthetc Classes are Servlet. language.JAVA & J2EE Laboratory 07MCA41 The package used in javax. ServletOutputStream JSP JSP stands for Java Server Pages.jsp Any web server like tomcat is required to run any server sided pages . ServletResponse. extracts the path and query information from the user SRP.It is used for getting outputstream directed at the client. status to the client SC-It allows you to find out the information about the the environment in which client is running like coding format. objects and methods <%! Declarations %> Department of MCA BMSIT 7 . ServletStub SRQ-It gets the input stream from the client.servlet and it contains 4 interfaces and 3 classes Interfaces are ServletRequest. connection. JSP is a advanced form of servlet where java classes are created auomatically whenever jsp pages are executed on web server All java pages are saved with an extension of .

html” %> c) taglib : It specifies the file that contains the tag library <%@ taglib =”abc.tld” %> 4) Expression tag This tag is used to evaluate the java expressions whose result replaces the expression when jsp virtual engine resolves jsp tags <%! Datatype variable name %> 5) Scriptlet tag This contains commonly used java control statements and loops <% control statements or loops %> All jsp pages should be executed on web server with some port number JSP pages should be saved in web apps folder of tomcat server Path should be as : http://localhost:portnumber/examples/jsp/filename.jsp Department of MCA BMSIT 8 .JAVA & J2EE Laboratory 07MCA41 3) Directive tag This commands the JSP virtual engine to perform a specific task such as importing java package required by the object and methods used in the declaration statement There are 3 commonly used directive tags a) Import : used to import java packages <%@ page import = “java. %> b) Include : used to insert a specific file in to the JSP program <%@ include file =”abc\temlate.*” .sql.

JAVA & J2EE Laboratory Installation of Tomcat server 07MCA41 PATH SET FOR WEB APPLICATION Remote Method Invocation Concept  It is used for inter-process communication for between java virtual machines  It is used to invoke the methods of an object existing on a separate computer  It also supports to create java objects  It also supports passing of objects either by reference or by copying rather than transfer of control to different computer  It is alternative for socket programming Features  Objects calling the methods must use remote interface  Methods are called as remote methods and remote methods are defined by remote interfaces  Object that uses a remote interface is called server  Object that calls remote methods is called client  Remote object => object associated with methods that can be called form other computer  Remote Interface => interface that defines remote methods for remote object Department of MCA BMSIT 9 .

Remote  There is no method declarations in java.rmi.RemoteException  Remote objects must implement remote interface  Remote object registry is a mechanism by which client can get reference of remote object Execution Path  Client Program  Server Program  Interface Program  Compile client program  Compile Interface program  Type rmic remote interface name  Type start rmi registry  Run server program  Run client program 1) It is a way for inter-process communication between java virtual machines 2) It invokes the methods of an object existing on separate computer Department of MCA BMSIT 10 .Remote  This interface is used to identify remote objects  Methods declared in Remote interface must have java.JAVA & J2EE Laboratory 07MCA41 Diagram Client Server Stub Object -method1 -method2 Package  Remote interface uses/extends builtin interface called java.rmi.rmi.

rmi.UnicastRemoteObject . they are class files which acts like a proxy for client and server respectively and they are responsible for marshalling at client side and demarshalling at server side Packages used are java .server. surfing the Web. "I just read a great article! Type in this URL and check it out. the following diagram shows the steps that brought that page to your screen: Your browser formed a connection to a Web server. requested a page and received and you get a call from a friend who says. Remote Interface is an interface that declares the remote methods for a remote object." So you type that URL into your browser and press return. java. no matter where in the world that URL lives. Department of MCA BMSIT 11 .rmi.rmi package .htm. Remote objects must implement the remote interface directly or indirectly 5) The object that uses remote interface is called a server and the object that call remote method is called client 6) Server and client cannot directly communicate hence proxies called stub and Skelton is used.JAVA & J2EE Laboratory 07MCA41 3) Objects that want their methods to be called remotely must use remote interface which defines remote methods 4) Remote object is an object associated with the methods that can be called from java virtual machine . the page pops up on your screen.howstuffworks.Naming Any client –server application using RMI must have following 4 programs 1) Client program 2) Server program 3) Interface program 4) Implementation program The Basic Process IN WEB APPLICATION Let's say that you are sitting at your computer. It's at http://www. And magically. java. At the most basic level possible.

The network allows all of the computers to communicate with one another. In this way. So what is "the Internet"? The Internet is a gigantic collection of millions of computers. here are the basic steps that occurred behind the scenes: • The browser broke the URL into three parts:  The protocol ("http")  The server name ("www. all linked together on a computer network.) • The server then sent the HTML text for the Web page to the browser. Department of MCA BMSIT 12 .htm") • The browser communicated with a name server to translate the server name "www. (Cookies may also be sent from server to browser in the header for the page." (Note that cookies may be sent from browser to server with the GET request -.JAVA & J2EE Laboratory 07MCA41 If you want to get into a bit more detail on the process of getting a Web page onto your computer screen. every computer on the Internet is connected to every other computer on the Internet.) • Following the HTTP protocol. and the largest ISPs maintain fiber-optic "backbones" for an entire nation or region. Backbones around the world are connected through fiber-optic lines. The business can then connect its LAN to an ISP using a high-speed phone line like a T1 line.htm. • The browser then formed a connection to the server at that IP address on port the browser sent a GET request to the server. undersea cablessatellite. DSL or cable modem that talks to an Internet service provider (ISP). ISPs then connect to larger" into an IP Address. A home computer may be linked to the Internet using a phone-line modem. asking for the file "http://www.000 bits per second. which it uses to connect to the server machine.5 million bits per")  The file name ("web-server.howstuffworks. (We'll discuss ports later in this article.howstuffworks.see How Internet Cookies Work for details. while a normal phone line using a modem can typically handle 30. A computer in a business or university will usually have a network interface card (NIC) that directly connects it to a local area network (LAN) inside the business.000 to 50.) • The browser read the HTML tags and formatted the page onto your screen. A T1 line can handle approximately 1.

Your Telnet application will want to talk to the Telnet server. also known as a client. Those machines that provide services (like Web servers or FTP servers) to other machines are servers. to service your request. For example. It is possible and common for a machine to be both a server and a client. A server machine may provide one or more services on the Internet. Your machine.JAVA & J2EE Laboratory 07MCA41 Clients and Servers In general. Therefore. so clients direct their requests to a specific software server running on the overall server machine. Department of MCA BMSIT 13 . an e-mail server and an FTP server. it is a user machine. it will most likely want to talk to the Web server on the server machine. if you are running a Web browser on your machine. all of the machines on the Internet can be categorized as two types: servers and clients. When you connect to Yahoo! at to read a page. on the other hand. For example. for use on the Internet. but for our purposes here you can think of most machines as one or the other. Yahoo! is providing a machine (probably a cluster of very large machines). and so on. a server machine might have software running on it that allows it to act as a Web server. Clients that come to a server machine do so with a specific intent. And the machines that are used to connect to those services are clients. Yahoo! is providing a is probably providing no services to anyone else on the Internet.. your e-mail application will talk to the e-mail server.

JAVA & J2EE Laboratory 07MCA41 IP Addresses To keep all of these machines straight.EXE ( and . but many places now either omit it or replace it with a different host name that indicates a specific area of the site. which is 28 possibilities per octet.61. For" domain names. If you are working on a Windows machine.137 The four numbers in an IP address are called octets because they can have values between 0 and 255. rather than for each customer.69. On a UNIX "encarta" is designated as the host name instead of "www. IP stands for Internet protocol. but on most large servers it is -. The host name is created by the company hosting the domain. and these addresses are 32-bit numbers. an IP address is all you need to talk to a server. the IP address alone is not sufficient. A home machine that is dialing up through a modem often has an IP address that is assigned by the ISP when the machine dials in." A typical IP address looks like this: 216. with the command WINIPCFG. "www" is a very common host an ISP only needs one IP address for each modem it supports.116." • • • Department of MCA BMSIT 14 . normally expressed as four "octets" in a "dotted decimal number. in your browser. including your current IP address and hostname. .keep reading for details Domain Names The name www. On some servers. As far as the Internet's machines are concerned. NeuLevel and Public Interest Registry) manage the other domains (like .org). type nslookup at the command prompt. in encarta. you can view a lot of the Internet information for your machine. VeriSign creates the top-level domain names and guarantees that all names within a top-level domain are unique.msn. For example. the domain name for Microsoft's Encarta may be different the next time the machine dials in. you can type the URL http://209. A server has a static IP address that does not change very often. That IP address is unique for that session -. each machine on the Internet is assigned a unique address called an IP address.66 and arrive at the machine that contains the Web serve" domain are managed by the registrar called VeriSign. Every machine on the Internet has a unique IP address. VeriSign also maintains contact information for each site and runs the "whois" database. This way. along with a machine name. (For more information on IP addresses. display the IP address of the machine. VeriSign also manages ". and you can use the command hostname to learn the name of your machine. Other registrars (like RegistryPro.EXE for Windows 2000/XP).com actually has three parts: The host name ("www") The domain name ("xyz") The top-level domain name ("com") Domain names within the ".

There are also central name servers that use data supplied by VeriSign to map domain names to IP addresses. to name a few. in the case of" into the command line. For example. Simply type a name like "www.howstuffworks. On a UNIX Most individual companies.howstuffworks. These servers are simple databases that map names to IP addresses. each with a unique IP address. if a server machine is running a Web server and an FTP server.htm" into your browser. and a separate query to that name server. meaning that they provide services to other machines on the Internet. the Web server would typically be available on port 80. All of these are provided by server one for each service that is available on the the name server for the "com" top-level domain will know the IP address for the name server that knows host names. may deliver the actual IP address for the HowStuffWorks server machine. Here are some common port numbers: • • • • • • echo 7 daytime 13 qotd 17 (Quote of the Day) ftp 21 telnet 23 smtp 25 (Simple Mail Transfer. So here it is: The Internet is made up of millions of machines. operated by the HowStuffWorks ISP. If you type the URL "http://www. For example. FTP servers." passes it to a domain name server. and the domain name server returns the correct IP address for www. You have heard of many of these servers: e-mail servers.JAVA & J2EE Laboratory 07MCA41 Name Servers A set of servers called domain name servers (DNS) maps the human-readable names to the IP addresses. and the command will query the name servers and deliver the corresponding IP address to you. ISPs and universities maintain small name servers to map host names to IP addresses. Each of the most well-known services is available at a well-known port number.howstuffworks. Many of these machines are server machines. and the FTP server would be available on port 21. your browser extracts the name "www. Gopher servers and Telnet servers. Ports Any server machine makes its services available to the Internet using numbered ports. meaning e-mail) Department of MCA BMSIT 15 . A number of name servers may be involved to get the right IP address. Clients connect to a service at a specific IP address and on a specific Web servers. and they are distributed all over the Internet. you can access the same service using the nslookup command.

the browser sends a GET request to the server. Then. • Department of MCA BMSIT 16 . "www.htm") • The browser communicates with a name server to translate the server name. asking for the file " for example.see How Internet Cookies Work for details. the browser simply assumes that the server is using the well-known port 80.howstuffworks. which it uses to connect to that server machine. If you were to set up your own machine and load Web server software on it. and if a firewall is not protecting the port.yyy." into an IP address. you could put the Web server on port")  The file name ("web-server.yyy. and would have to be included for someone to reach your server. The browser breaks the URL into three parts:  The protocol ("http")  The server name (" if your machine were known as xxx. (Cookies may also be sent from server to browser in the header for the page. The ":918" explicitly specifies the port number. a Web server to be on port 80.htm.) • The server sends the HTML text for the Web page to the browser.) • The browser reads the HTML tags and formats the page onto your screen. • Following the HTTP protocol." (Note that cookies may be sent from browser to server with the GET request -.howstuffworks. When no port is specified. you can connect to the port from anywhere on the Internet and use the service. Note that there is nothing that forces. or any other unused port.JAVA & J2EE Laboratory • • • • • • 07MCA41 time 37 nameserver 53 nicname 43 (Who Is) gopher 70 finger 79 WWW 80 If the server machine accepts connections on a port from the outside world. someone on the Internet could connect to your server with the URL http://xxx. • The browser then forms a connection to the Web server at that IP address on port 80. if you wanted

double breadth. } double result() { return(length*breadth).JAVA & J2EE Laboratory 07MCA41 PROG1A PROGRAM TO DEMOSTRATE CONSTRUCTOR OVERLOADING class rectangle { double length. breadth=5. System. } } class overload { public static void main(String args[]) { rectangle r1=new rectangle().println("area of rectangle2=" +vol).5. } rectangle(double l. vol=r2. rectangle r2=new rectangle(10.out. breadth=b.5.5).result().5.result().out.println("area of rectangle1=" +vol). double vol=r1. rectangle() { length=10.5.double b) { length=l. } } Department of MCA BMSIT 17 . System.

75 area of rectangle2=57.75 Department of MCA BMSIT 18 .java C:\LJAVA>java overload area of rectangle1=57.JAVA & J2EE Laboratory 07MCA41 OUTPUT: C:\LJAVA>javac overload.

JAVA & J2EE Laboratory 07MCA41 PROG1A: PROGRAM TO DEMONSTRATE METHOD OVERLOADING class demo { void test() { System.out.14f).out.3. d. double d2=d.println("no parameters"). } double test (double d) { System.test(3.println("a="+ a +"\t" +"b="+b). } } Department of MCA BMSIT 19 b) { System. return d. d.println("d="+d). d. } } class prog1a { public static void main(String args[]) { demo d=new demo().float f) { System. } void test(int a.println("a="+ a +"\t" +"f="+f).test(10.20).test(10.test().56).out. } void test(int a.

java C:\LJAVA>java prog1a No parameters a=10 b=20 a=10 f=3.14 d=3.JAVA & J2EE Laboratory 07MCA41 OUTPUT: C:\LJAVA>javac prog1a.56 Department of MCA BMSIT 20 .

} String readlabel() { return label.JAVA & J2EE Laboratory 07MCA41 PROG1B: PROGRAM TO DEMONSTRATE INNER CLASS AND ACCESS PROTECTIONS class parcel { class contents { private int i=10. System. } public static void main(String args[]) { parcel p=new parcel().value() +" " + "items to" + " " + dest). } } public void ship(String dest) { contents c=new contents(). p.out. private int value() { return i. p. } } class destination { private String label.ship("mysore"). } } Department of MCA BMSIT 21 . destination(String whereto) { label=whereto.ship("blore").println("shipped" +" " + c.

java C:\LJAVA>java parcel shipped 10 items to mysore shipped 10 items to blore Department of MCA BMSIT 22 .JAVA & J2EE Laboratory 07MCA41 OUTPUT: C:\LJAVA>javac parcel.

age=45.display(). f.display().println(" ").name="chethan".println(" "). f. } } class inherit { public static void main(String args[]) { father f=new father()."datta".usn=12. int age.println("name=" +name). f. System. s. void show() { System.JAVA & J2EE Laboratory 07MCA41 PROG2A: PROGRAM TO IMPLEMENT INHERITANCE class father { String name. s. void display() { System.out. } } class son extends father { int usn.println("usn=" +usn).out. s. System. System. son s =new son(). s. } } Department of MCA BMSIT 23 .show().out.println("age="+age).

java C:\LJAVA>java inherit name=datta age=45 name=chethan age=17 usn=12 Department of MCA BMSIT 24 .JAVA & J2EE Laboratory 07MCA41 OUTPUT: C:\LJAVA>javac inherit.

} } } Department of MCA BMSIT 25 . } } catch(Exception g) { System. System.println("a="+a). c[43]=99. try { if(a==1) a=a/(a-a).println(g).println("error="+e). } finally { System.length.out.JAVA & J2EE Laboratory 07MCA41 PROG2B: PROGRAM TO DEMONSTRATE EXCEPTION HANDLING class expdemo { public static void main(String args[]) { try { int a=args. if(a==2) { int c[]={1}.out.println("the statement executes").out. } } catch(Exception e) { System. int b=42/a.out.

ArithmeticException: / by zero The statement executes Department of MCA BMSIT 26 .JAVA & J2EE Laboratory 07MCA41 OUTPUT: C:\LJAVA>javac C:\LJAVA>java expdemo java.lang.

} } OUTPUT: C:\LJAVA>javac inter.0 area of circle=314.float y) { return(pi*x*x).println("area of rectangle=" +rect.0)).out. } } class circle implements Area { public float compute(float x.JAVA & J2EE Laboratory 07MCA41 PROG3A: PROGRAM TO CREATE INTERFACE AND IMPLEMENT CLASS interface Area { final float pi=3.compute(10.14f.float y) { return(x*y).0 Department of MCA BMSIT 27 . circle cir=new circle().out.20)). System.float y). } class rectangle implements Area { public float compute(float x.println("area of circle=" +cir. float compute(float x. } } class inter { public static void main(String args[]) { rectangle rect=new rectangle().java C:\LJAVA>java inter area of rectangle=200.compute(10. System.

println("Third thread is alive : "+ob3.out.println("First thread is alive : "+ob1.println("Second thread is alive : "+ob2.getPriority()).JAVA & J2EE Laboratory 07MCA41 PROG3B: PROGRAM TO CREATE CLASS FOR EXTENDING THREADS class Mythread extends Thread { Mythread(String ss) { super(ss).println("No.getPriority()).getPriority()).println(this. Thread ob3 = new Mythread("Third"). start().out.isAlive()).activeCount()).out. try Department of MCA BMSIT 28 . ob2.println("Priority of First thread "+ob1.println("Priority of Third thread "+ob3.setPriority(1). System.sleep(1000). System.out.isAlive()). System.i--) { System.out.} System.println(getName()+" : "+i).setPriority(3).out.of Threads alive "+ob1. }} catch(InterruptedException e){System. System.isAlive()).getName()+" exiting"). System. Thread.out. } } class ExtendThread { public static void main(String ab[]) { Thread ob1 = new Mythread("First").println(this.println("Priority of Second thread "+ob2. Thread ob2 = new Mythread("Second").out.i>0. System.setPriority(9). System. } public void run() { try{ for(int i=5.out.out.getName()+" interrupted"). ob1. ob3.

out.of Threads alive "+ob3. } System. System.isAlive()).join(). 07MCA41 } catch(InterruptedException e) { System.out. System.out.println("First thread is alive : "+ob1.out.out.JAVA & J2EE Laboratory { ob1.println("No.isAlive()). ob2.join().getPriority()).join().out.println("New Priority of Second thread " C:\LJAVA>java ExtendThread First thread is alive : true First : 5 Second : 5 Third : 5 Second thread is alive : true Third thread is alive : true No.getPriority()).out.isAlive()). System.println("New Priority of First thread "+ob1. System. ob3.println("Third thread is alive : "+ob3.getPriority()).println("New Priority of Third thread "+ob3.of Threads alive 5 Priority of First thread 5 Priority of Second thread 5 Priority of Third thread 5 Third : 4 Second : 4 First : 4 Third : 3 Second : 3 First : 3 Third : 2 Second : 2 First : 2 Third : 1 Second : 1 First : 1 Department of MCA BMSIT 29 .activeCount()).println("Second thread is alive : "+ob2. System. System.out.println("Main thread interrupted"). } } OUTPUT: C:\LJAVA>javac ExtendThread.

JAVA & J2EE Laboratory Third exiting Second exiting First exiting First thread is alive : false Second thread is alive : false No.of Threads alive 2 Third thread is alive : false New Priority of First thread 1 New Priority of Second thread 3 New Priority of Third thread 9 07MCA41 Department of MCA BMSIT 30 .

substring(1.Thread. msg=msg.) { repaint().sleep(100).msg. ch=msg. import java. } } catch(InterruptedException e) { System.lang.JAVA & J2EE Laboratory 07MCA41 PROG4A: PROGRAM TO CREATE SCROLLING TEXT USING APPLETS import java. t. for(. public class scroll extends Applet implements Runnable { Thread t=null. } public void run() { try { char ch. public void init() { t=new Thread(this). String msg="good morning".*. } } public void paint(Graphics g) { Department of MCA BMSIT 31 .println("error").awt.*. import java.applet. t.length()).out.start()..charAt(0). msg=msg+ch.*.

java Department of MCA BMSIT 32 .10).drawString(msg. } } /*<applet code="scroll.50.JAVA & J2EE Laboratory C:\LJAVA>appletviewer scroll.class" width=200 height=200> </applet>*/ 07MCA41 OUTPUT: C:\LJAVA>javac scroll.

class" width=100 height=100> <param name="message" value="goodmorning"> </applet>*/ public class pardemo extends Applet { String msg. import java.20).java Department of MCA BMSIT 33 .JAVA & J2EE Laboratory 07MCA41 PROG4B: PROGRAM TO PASS PARAMETERS TO APPLETS AND DISPLAY import java. } public void paint(Graphics g) { g.*.10.awt. } } OUTPUT: C:\LJAVA>javac pardemo. /*<applet code="pardemo. public void init() { msg=getParameter("message").java C:\LJAVA>appletviewer pardemo.applet.*.drawString(msg.

JdbcOdbcDriver"). c. b2=new JButton("retrieve"). } public static void main(String x[]) throws ClassNotFoundException { Class.setLayout(new FlowLayout()).jdbc.*.add(t1).forName("sun. b1=new JButton("add"). c.awt. import java.odbc. c. import javax. public class test4 extends JFrame { private JButton b1.add(b2). t1=new JTextField(10).event. setSize(400. import java.*. private JTextField t1. Container c=getContentPane().*.add(b1).JAVA & J2EE Laboratory PROG5: 07MCA41 Java Program to insert data into Student database and retrieve info based on particular queries (using import java.*.l2.swing.addWindowListener(new WindowAdapter() Department of MCA BMSIT 34 . Design front end using Swings). import java.*. public test4() { l1=new JLabel("Enter name"). private JLabel l1. t2=new JTextField(10).b2.lang. c.*. test4 app=new test4().add(l2).awt.add(l1). b1. demo5. app. import java.add(t2).addActionListener(handler). c. c.*.t2. ButtonHandler handler=new ButtonHandler(). l2=new JLabel("Enter age"). import java. show().addActionListener(handler).400).sql. c.

t2. if(x. cn=DriverManager.?)".next()) Department of MCA BMSIT 35 . ResultSet rs. "RecordSaved"). rs=st. 07MCA41 ResultSet rs.setString(1. } catch (SQLException t) { System.JAVA & J2EE Laboratory { public void WindowClosing(WindowEvent e1) { System.getConnection("jdbc:odbc:ds"). ps. ps. cn=DriverManager. } }).getActionCommand().getText()).getText()).println(t).prepareStatement(creat). } private class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { String x=e. Statement st.createStatement(). st=cn. cn.getConnection("jdbc:odbc:ds").showMessageDialog(null. PreparedStatement ps = cn. } } if(x.equals("retrieve")) { try { Connection cn.exit(0). ps.setString(2. while(rs. String creat = "insert into abc values(?. JOptionPane.executeQuery("select * from abc"). ps.close().close().out.equals("add")) { try { Connection cn.executeUpdate().t1.

out.getString(2)+"\t").close().print("Name:" +rs.println("\n").JAVA & J2EE Laboratory 07MCA41 { System. System. System.out. rs.getString(1)+"\t").println("age:" +rs.out. } st. cn.close(). } catch (SQLException i) {} } } } } Department of MCA BMSIT 36 .close().

java C:\>java demo5 Department of MCA BMSIT 37 .JAVA & J2EE Laboratory 07MCA41 OUTPUT C:\>javac demo5.

InputStream is. System.out.println(inputline). try { ss=new ServerSocket(90). System. } catch(Exception g) Department of MCA BMSIT 38 . String inputline=new String(). byte bt[]=new byte[20].JAVA & J2EE Laboratory 07MCA41 PROG6: PROGRAM TO IMPLEMENT CLIENT SERVERUSING SOCKET PROGRAMMING SERVER PROGAM… import java. public class server { public static void main(String args[])throws IOException { ServerSocket ss=null.println("connected to------------------"+cs).out.getInputStream().accept().*.out. Socket System. is=cs. inputline=new String(bt) is. import java.println("---------------------").exit(1). } catch(Exception e) { System.println("server connected"). System. System. } try { cs=ss.out.*.

flush().readLine())!=null) { out. } PrintWriter out=new PrintWriter(cs.. if(f.close()..getOutputStream()).getLocalHost().exists()) { BufferedReader d=new BufferedReader(new FileReader(inputline)). Socket cs=null. in=new BufferedReader(new InputStreamReader(cs. out."+cs).println(line). } cs.. System. File f=new File(inputline).out. out.exit(1).println("file send to client successfully").println("client running is connected to..*. import java. & J2EE Laboratory { System. OutputStream os.getInputStream())). import java.flush().90).. Department of MCA BMSIT 39 . } else { String line="file doesnot exists". try { cs=new Socket(InetAddress. String line..out.*.println(line).println("---------------------"). while((line=d. } System. ss.out. System. } } CLIENT PROGRAM….io.. 07MCA41 public class client { public static void main(String args[])throws IOException { BufferedReader in=null.close().

os=cs.168.3. String s=stdin.println(userinput).po rt=90.readLine().. byte bt[]=s.out.port=1269.localport=90] [B@8d107f prog1a.println("enter the filename"). os.. } } OUTPUT: C:\LJAVA>javac server. } void test(int a.println("no parameters").localport=1269] enter the filename prog1a.out.Socket[addr=bmsit-8eb8fe932/192...close().JAVA & J2EE Laboratory 07MCA41 } catch(Exception e) {} BufferedReader stdin=new BufferedReader(new InputStreamReader(System.getBytes().close().java file send to client successfully C:\LJAVA>java client client running is connected to.readLine())!=null) System. } Department of MCA BMSIT 40 .getOutputStream()..out.println("a="+ a +"\t" +"b="+b).3.write(bt) class demo { void test() { System. while((userinput=in. b) { System.out. String userinput.1. cs. C:\LJAVA>java server server connected connected to------------------Socket[addr=/192.1..

56).test(10. } double test(double d) { System.14f).test(10.20). } } class prog1a { public static void main(String args[]) { demo d=new demo().out. } } 07MCA41 Department of MCA BMSIT 41 .JAVA & J2EE Laboratory void test(int a. double d2=d.println("d="+d).out.test(). return d.println("a="+ a +"\t" +"f="+f).float f) { System.test(3. d. d.3. d.

*.*.*.rmi.rmi. int y) throws RemoteException { return x+y. public class AddServerImpl extends UnicastRemoteObject implements AddServerIntf { public AddServerImpl() throws RemoteException{ } public int add(int x. import java.JAVA & J2EE Laboratory 07MCA41 PROG7: IMPLEMENT SIMPLE CLIENT SERVER USING RMI…… Interface import**. } } Server import java.*. public interface AddServerIntf extends Remote { public int add(int x. import java.rmi.*. } Implements import java. import java. public class AddServer { public static void main(String arg[]) { Department of MCA BMSIT 42 .io. int y) throws RemoteException.server. import java.

.parseInt(arg[0]).parseInt(arg[1]).rmi.add(x. System."). } catch(Exception e) { System.println("First no is "+arg[0])... System. int y=Integer.println("second no is "+arg[1]).JAVA & J2EE Laboratory try { AddServerImpl server=new AddServerImpl(). Naming.out.println(e). public class AddClient { public static void main(String arg[]) { try { AddServerIntf client=(AddServerIntf)Naming.y)).io..*.println("SUM= "+client.println(e).*. int x=Integer. } } } Client 07MCA41 import java.out.out.out. import java.out.server).lookup("registerme").rebind("registerme"... System. } } } OUTPUT Store all the above file in a folder as Lab7 Open Command Prompt C:\Documents and Settings\Administrator>cd\ Department of MCA BMSIT 43 . System. } catch(Exception e) { System.println("server is running.out.

.JAVA & J2EE Laboratory C:\>cd Lab7 C:\Lab7>javac *. Open another Command Prompt C:\Documents and Settings\Administrator>cd\ C:\>cd Lab7 C:\Lab7>java AddClient 5 19 First no is 5 second no is 19 SUM= 24 07MCA41 Department of MCA BMSIT 44 C:\Lab7>rmic AddServerImpl C:\Lab7>start rmiregistry C:\Lab7>java AddServer server is running...

http. return .JAVA & J2EE Laboratory 07MCA41 PROG8: JAVA SERVLET PROGRAM TO ACCEPT THE USERNAME AND PASSWORD FROM A DYNAMIC HTML Index.pname.*.value=="" || document.*.html <html> <head><title>demo8</title></head> <body bgcolor=orange> <form method="post" name="form1" action="http://localhost:8080/examples/servlet/demo8"> <center><b><br><br> Enter User Name : <input type="text" name="uname" size="10"><br> Enter Password : <input type=password name="pname" size="10"><br><br> <input type=button value="Submit" onclick="validate()"> </center> <script type="text/javascript"> function validate() { if(document. import javax.servlet.submit(). } </script> </form> </body> </html> demo8.form1.value=="") { alert("Fields cannot be blank").*.java import java.form1.form1. public class demo8 extends HttpServlet { Department of MCA BMSIT 45 . } import javax.uname.

println("<html>").html Department of MCA BMSIT 46 . out. String str1=request. } } Store the Index.setContentType("text/html").println("<body>").println("Password is "+str1).1\webapps\ROOT And the demo8.ServletException { response. out.HttpServletResponse response)throws IOException.println("</html>").println("User Name is "+str+"<br>"). out. out.getParameter("pname"). out.JAVA & J2EE Laboratory 07MCA41 public void doPost(HttpServletRequest request.println("</body>"). String str=request. out.1\webapps\examples\WEB-INF\classes Start Tomcat Open the Browser and give path as http://localhost:8080/8.getWriter().html in C:\Program Files\Apache Group\Tomcat 4.getParameter("uname").class in C:\Program Files\Apache Group\Tomcat 4. PrintWriter out=response.

JAVA & J2EE Laboratory 07MCA41 After clicking on Submit Department of MCA BMSIT 47 .

http. import import javax.html <html> <head><title>File Download</title> <script type="text/javascript"> function validate() { if(document. public class filedown extends HttpServlet Department of MCA BMSIT 48 .*.servlet.*.JAVA & J2EE Laboratory 07MCA41 PROG9: JAVA SERVLET PROGRAM TO DOWNLOAD A FILE AND DISPLAY IT ON THE SCREEN filedown.form1.value=="") alert("First click on browse and select the file") import java.*. } </script> </head> <body bgcolor="lightblue"> <form name="form1" method="get" action="http://localhost:8080/examples/servlet/filedown"> <p><center><br><br><h1>File Downloand Program</h1><br><br> <h3>Click on Browse and select the file</h3><br><br> <input type="file" name="f1" size="40" ><br><br> <input type=button value="Click to start downloading" onclick="validate()"> </center></p> </form> </body> </html> filedown.submit(). else document.

JAVA & J2EE Laboratory


{ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException { response.setContentType("text/html"); PrintWriter out=response.getWriter(); String fname = request.getParameter("f1"); File f = new File(fname); if(f.exists()) { out.println("<html>\n<head><title>Javaservlet</title></head>\n"+"<body>\n"+ <p><hr size='3' style='color:red'/><font size=5pt face=verdana color=blue>Download Completed<br>FileName:"); out.println(f.getName()); out.println("<hr size='2' style='color:green'>"); out.println("Contents of the File is:<br>"); out.println("<hr size='2' style='color:green'/><br>"); BufferedReader in = new BufferedReader(new FileReader(f)); String buf=""; while((buf = in.readLine())!= null) { out.write(buf); out.flush(); out.println("<br>"); } in.close(); out.println("<hr size='3' style='color:red'></font></p></body>\n</html>"); } else out.println("<h1>File Doesnot Exists\n"); } } Store the filedown.html in C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT And the filedown.class in C:\Program Files\Apache Group\Tomcat 4.1\webapps\examples\WEB-INF\classes Start Tomcat Open the Browser and give path as http://localhost:8080/filedown.html

Department of MCA



JAVA & J2EE Laboratory



Department of MCA



JAVA & J2EE Laboratory 10a.html


<html> <head><title>demo10a</title></head> <body bgcolor=lightblue> <form action=http://localhost:8080/examples/servlet/demo10a method="post"> <p><center><br><br><h1>Request Dispatcher Implementation</h1><br><br> <input type="hidden" name="decider" value="forward"> <input type=submit value="forward"> </form> <form action=http://localhost:8080/examples/servlet/demo10a method="post"> <center><br> <input type="hidden" name="decider" value="include"> <input type=submit value="include"> </form> </body> </html> import*; import javax.servlet.*; import javax.servlet.http.*; public class demo10a extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { public void doPost(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException { String decider=request.getParameter("decider"); RequestDispatcher rd=null; if("forward".equals(decider)) { rd=request.getRequestDispatcher("reg10a"); rd.forward(request,response); } else if("include".equals(decider)) { rd=request.getRequestDispatcher("reg10a"); rd.include(request,response); } PrintWriter out=response.getWriter(); out.println("<br><center>Hai.... i am a demo10a to demonstrate request dispatcher"); } }

Department of MCA



class in C:\Program Files\Apache Group\Tomcat 4. import javax.class and reg10a. out.*.println("<body bgcolor=pink>").servlet.JAVA & J2EE Laboratory 07MCA41 reg10a.servlet. out. import javax.1\webapps\examples\WEB-INF\classes Start Tomcat Open the Browser and give path as http://localhost:8080/ out.HttpServletResponse response)throws IOException.1\webapps\ROOT And the demo10a.println("</html>").getWriter().servlet.http.*. public class reg10a extends import java.http.println("<center><h2>Hai.html Department of MCA BMSIT 52 . out.. } } Store the 10.*. this is regservlet</center></h2>")..html in C:\Program Files\Apache Group\Tomcat 4.println("</body>").HttpServlet implements javax. out.println("<html>").Servlet { public void doPost(HttpServletRequest request.ServletException { PrintWriter out=response.

JAVA & J2EE Laboratory 07MCA41 When click on forward Department of MCA BMSIT 53 .

JAVA & J2EE Laboratory 07MCA41 When clicked on include Department of MCA BMSIT 54 .

ServletException { response. import response)throws IOException.*.getParameter("typevalue"). if(type. String type=request. PrintWriter out=response.equals("first")) out.*.println("<center><h2>Request send to the first page").setContentType("text/html"). import javax.servlet. public class demo11 extends HttpServlet { public void doGet(HttpServletRequest request. } } Department of MCA BMSIT 55 .getWriter().java import java.JAVA & J2EE Laboratory PROG11: 07MCA41 JAVA SERVLET PROGRAM TO IMPLEMENT SENDREDIRECT() METHOD.http.html <html> <head><title>demo11</title></head> <form action="http://localhost:8080/examples/servlet/demo11"> <p><center><br><br><h1>Implementation of sendRedirect()</h1><br><br> <select name="typevalue"> <option>first</option> <option>second</option> </select> <input type=submit value=submit> </center> </form> </html> demo11. else response.*. demo11.sendRedirect("http://localhost:8080/examples/servlet/second").

HttpServletResponse response)throws out.html in C:\Program Files\Apache Group\Tomcat 4.setContentType("text/html").class in C:\Program Files\Apache Group\Tomcat 4. } } Store the demo11.html Department of MCA BMSIT 56 . import javax. import javax.servlet.1\webapps\ROOT And the demo11.println("<center><h2>Request send to the second page"). public class second extends HttpServlet { public void doGet(HttpServletRequest request.ServletException { import java.1\webapps\examples\WEB-INF\classes Start Tomcat Open the Browser and give path as http://localhost:8080/demo11.servlet. PrintWriter out=response.*.*.JAVA & J2EE Laboratory 07MCA41 second.*.class and second.http.getWriter().

JAVA & J2EE Laboratory 07MCA41 Department of MCA BMSIT 57 .

else ival=new Integer(ival.counter". out. out.servlet.JAVA & J2EE Laboratory 07MCA41 PROG12: JAVA SERVLET PROGRAM TO IMPLEMENT SESSIONS.ServletException { response.println("session id="+id). session.HttpServletResponse response)throws IOException. out. } } Store the demo12.getAttribute("sessiontest.getId().class in Department of MCA BMSIT 58 . import java.setContentType("text/html").println("<body>").println("<html>").*.servlet.*. out. demo12. if(ival==null) ival=new Integer(1). PrintWriter out=response.*.println("<br>"). String id=session.*. import javax.util.println("</html>").getSession(true).println("session="+session). out.counter").setAttribute("sessiontest. out. out.println("</body>").println("you have visited the page "+ival+" times").ival).println("<br>"). HttpSession session=request. public class demo12 extends HttpServlet { public void doGet(HttpServletRequest request. Integer ival=(Integer)session.getWriter(). import import java. out.intValue()+1).

JAVA & J2EE Laboratory 07MCA41 C:\Program Files\Apache Group\Tomcat 4.1\webapps\examples\WEB-INF\classes Start Tomcat Open the Browser and give path as http://localhost:8080/examples/servlet/demo12 Department of MCA BMSIT 59 .

1\webapps\ROOT Department of MCA BMSIT 60 .n. n++. Procedure • Write a jsp program • Copy the jsp program in root directory of tomcat server • Start the tomcat server and then run the program 13a.println(i+" ").JAVA & J2EE Laboratory 07MCA41 PROG13a: JAVA JSP PROGRAM TO PRINT 10 EVEN AND 10 ODD NUMBERS.println("<br><h2>Even Numbers : <br>"). %> <% out.jsp <html> <body bgcolor=orange> <%! int i. i+=2. j=1. while(n<=10) { out. n++.jsp in C:\Program Files\Apache Group\Tomcat 4. } %> </body> </html> Store the demo13a. } out. i=0.println("<br><br><h2>Odd Numbers : <br>").n=1.println(j+" ").n=1. while(n<=10) { out.j. j+=2.

JAVA & J2EE Laboratory Start Tomcat Open the Browser and give path as http://localhost:8080/13a.jsp 07MCA41 Department of MCA BMSIT 61 .

%> welcome. Department of MCA BMSIT 62 .html <html> <head><title>13b</title></head> <form action="http://localhost:8080/13b.password=null.equals("Ritesh") && password.jsp"). 13b.getParameter("pwd"). %> <% if(username.println("<center><h2>Invalid username or password"). %> <% username=request.jsp <% out.jsp <%! String username=null.equals("12345")) { response.JAVA & J2EE Laboratory 07MCA41 PROG13b: JAVA JSP PROGRAM TO IMPLEMENT VERIFICATION OF A PARTICULAR USER LOGIN AND DISPLAY A WELCOME PAGE. password=request.getParameter("uname").jsp"> <p><center><br><br><h1>Verification of a particular User login</h1><br><br> User Name : <input type=text name="uname" size=10><br> password : <input type=password name="pwd" size=10><br><br> <input type=submit value=Submit> </form> </html> 13b.sendRedirect("http://localhost:8080/welcome.println("<center><h2>Welcome Ritesh<br>"). } else out.

%> 07MCA41 Store the 13b.html.html Department of MCA BMSIT 63 .JAVA & J2EE Laboratory out.1\webapps\ROOT Start Tomcat Open the Browser and give path as http://localhost:8080/13b.jsp and welcome.println("You are now Logged in"). 13b.jsp in C:\Program Files\Apache Group\Tomcat 4.

JAVA & J2EE Laboratory 07MCA41 Department of MCA BMSIT 64 .

JAVA & J2EE Laboratory 07MCA41 Department of MCA BMSIT 65 .

Student"/> <jsp:setProperty name="stud" property="*"/> <jsp:forward page="display.html <html> <head><title>Student Information</title></head> <body bgcolor=orange> <form action ="first. jsp program .jsp" method = "post"> <center><h1>Student Information</h1> <h3> Enter the USN : <input type = "text" name = "usn"/><br> Student Name : <input type = "text" name = "sname"/><br> Total Marks : <input type = "text" name = "smarks"/><br> <input type ="submit" value ="DISPLAY" /></h3> </center> </form> </body> </html> first.jsp"/> </body> </html> display.jsp <html> <body> <jsp:useBean id="stud" scope="request" class="beans. Procedure • Writa a html program . POPULATE BEAN AND DISPLAY THE SAME INFORMATION THROUGH ANOTHER JSP. servlet program • Create a folder and copy all the programs in that folder • Compile the servlet program and get the class file • Create WEB-INF folder inside a folder and copy servlet program in WEB-INF folder • Start the tomcat server and then run the program StudInfo.JAVA & J2EE Laboratory 07MCA41 PROG14: JAVA JSP PROGRAM TO GET STUDENT INFORMATION THROUGH A HTML AND CREATE A JAVA BEAN CLASS.jsp Department of MCA BMSIT 66 .

} public void setusn(String en) { usn=en. public String usn. } public String getusn() { return usn. } } Department of MCA BMSIT 67 .getsmarks()). public int smarks. public class Student { public String sname. } public int getsmarks() { return package beans. } public String getsname() { return sname.%></h3> </body></html> Student. public void setsname(String e) { sname = e.Student"/> <h2>Entered Student Information</h2><br><br><h3> Student Name : <jsp:getProperty name="stud" property="sname"/><br> USN : <jsp:getProperty name="stud" property="usn"/><br> Total Marks : <%out.JAVA & J2EE Laboratory 07MCA41 <html> <body bgcolor="pink"> <jsp:useBean id="stud" scope="request" class="beans.print(stud. } public void setsmarks(int m) { smarks = m.

jsp and display.html 07MCA41 Department of MCA BMSIT 68 .html.class in the beans folder Start Tomcat Open the Browser and give path as http://localhost:8080/LAB14/StudInfo.1\webapps Store StudInfo.jsp in LAB14 Create subfolders under LAB14 as WEB-INF\classes\beans Store the Student. first.JAVA & J2EE Laboratory Create a folder as LAB14 in C:\Program Files\Apache Group\Tomcat 4.

JAVA & J2EE Laboratory 07MCA41 Department of MCA BMSIT 69 .

write a java program to demonstrate inner class 11. 2. what are thread and how do you create threads? 24. write a java program to pass parameter to an applet 20. getcodebase(). what is audioclip interface 23. event source . what is java? What are the features of java write a java program demonstrating access specifies write a java program demonstrating different operators write a java program demonstrating conditional operators write a java program for type casting write a java program to access a variable declared outside and inside main function 7. getdocumentbase(). 6. what is final variable. final class. write a java program demonstrating wrapper class 9. write a java program for status window. event listener interface 30. 5. what is exception handling and give an program example 17. what is try and catch block 15. Write a java program to implement all thread methods 25. what is a super class ? give program example 10.JAVA & J2EE Laboratory 07MCA41 Proposed Viva-Voce questions 1. 3. what is reader writer problem 28. write a java program for each of the swing components 32. event class. what is producer and consumer problem 27. what are the 2 key swing features 33. what is the difference between abstract class and interface and write the program for the same 13. what is event. what is finally block 16.showdocument() 21. what is jdbc and explain different jdbc drivers 35. write a java program to showcase simple and multilevel inheritance 12. 4. what is an applet and explain applet life cycle 19. what is appletcontext()? 22. what is overloading and overriding and give an program example 14. Explain thread synchronization with an example 26. write a java program to access the method by creating a object of a class 8. give an overview of j2ee 34. final method 18. write a java program for adapter class and inner class 31. explain the JDBC process Department of MCA BMSIT 70 . what is event delegation model 29.

Explain different types of bean with an example 07MCA41 Department of MCA BMSIT 71 . what is metadata 38. write a java program for user session and cookies 50. what is servlet and explain life cycle of servlet 39. write a java program for forward. explain JSP tags 48. what is session objects 51. write a java program for database application 37. how do you handle http request and http response 43. what is a cookie and write a java program to handle cookie 44. explain servlet API 40. what is MVC architecture 47. what is EJB 53. what is RMI? Explain RMI process 52. write a servlet program to pass the parameter 42.JAVA & J2EE Laboratory 36. request dispatcher 49. What are the 2 types of servlet 41. what is JSP and what are the advantages of JSP 46. send direct. write a java program for session tracking 45.

Sign up to vote on this title
UsefulNot useful