You are on page 1of 6

INDEX SN. 1. 2. 3. 4.

Program
Write a program to copy the content of one file to another. Write a program to display record of a table product_id, product_name, product_catogries, product_price in a GUI. Servlet programming

Date

Signature

MultiThreading Program

Que1:/* @author BOSS */ import java.io.*; public class File_copy { public static void main(String[] arg) throws FileNotFoundException, IOException { FileInputStream dis; FileOutputStream dos; File f=new File("first.txt"); File f1=new File("second.txt"); dos=new FileOutputStream(f); dis=new FileInputStream(f); String str="this is a test file"; byte b = 0; dos.write(str.getBytes()); dos.close(); dos=new FileOutputStream(f1); try { while((b=(byte)dis.read())!=-1) { dos.write(b); } } catch(FileNotFoundException e) { System.out.println("file not found"); } dis.close(); dos.close();

} } Que2:/* * @author Sachin */ import java.sql.*; import java.util.*; import java.awt.*; import java.applet.*; import java.awt.event.*;

import java.util.logging.Level; import java.util.logging.Logger; public class Connection_Demo extends Applet implements ActionListener { TextField tp_id,tp_name,tp_cat,tp_price; Label lp_id,lp_name,lp_cat,lp_price; Button bt; public void init() { tp_id= new TextField(); lp_id=new Label("product_id"); add(lp_id); add(tp_id); tp_name= new TextField(); lp_name=new Label("product_name"); add(lp_name); add(tp_name); tp_cat= new TextField(); lp_cat=new Label("product_categories"); add(lp_cat); add(tp_cat); tp_price= new TextField(); lp_price=new Label("product_price"); add(lp_price); add(tp_price); bt=new Button("show"); add(bt); bt.addActionListener(this); } public void actionPerformed(ActionEvent e) { Connection conn; Statement stmt; int id,p_price; String p_id,p_cat,p_name; try { Class.forName("org.apache.derby.jdbc.ClientDriver") ; conn=DriverManager.getConnection("jdbc:derby://localhost:1527/Sachin","sachin","sachin"); stmt=conn.createStatement(); ResultSet rs = rs=stmt.executeQuery("select * from app.PRODUCT"); while(rs.next()) { id=rs.getInt(1); p_name=new String(rs.getString(2)); p_cat=new String(rs.getString(3)); p_price=rs.getInt(4); tp_id.setText("id"); tp_name.setText(p_name); tp_cat.setText(p_cat);

} } catch (SQLException ex) { Logger.getLogger(Connection_Demo.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(Connection_Demo.class.getName()).log(Level.SEVERE, null, ex); } } }

Q3:-Servlet Program Config file--<?xml version="1.0" encoding="ISO-8859-1"?> <web-app> <servlet> <servlet-name>TestServlet</servlet-name> <servlet-class>TestServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>TestServlet</servlet-name> <url-pattern>/test</url-pattern> </servlet-mapping> </web-app>

Java file:--import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class TestServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html><body><h1>hello world</h1></body></html>"); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request, response); } }

Q4. Threading program //C:\java class t1 extends Thread { public void run() { for(int i=0;i<=5;i++){ System.out.println("Thread t1"+i); try{ sleep(1000); }catch(Exception e) { } System.out.println("Exit from t1"); } }}

class t2 extends Thread { public void run() { for(int j=0;j<=5;j++) {System.out.println("Thread no 2="+j); try{ sleep(1000); }catch(Exception e) { } }} } class t3 extends Thread { public void run() { for(int k=0;k<=10;k++) { System.out.println("Thread no. 3 "+k); try{ sleep(1000); }catch(Exception e) {} }} } public class a7 { public static void main(String args[]) { t1 t=new t1(); t.start(); t2 t5=new t2(); t5.start(); t3 t6=new t3(); t6.start(); }}

You might also like