You are on page 1of 12

Question :Write a program to create a database and create connectivity

code of jdbc odbc program?


Code:
import java.sql.*;
public class db
{
Connection e;
ResultSet r;
Statement s;
Public db()
{
connect();
}
public void connect ()
{
try
{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
Connection c = DriverManager.getConnection(“jdbc:odbc:dbl”);
Statement s = c.createStatement();
String sql = “select * from table1”;
r=s.executeQuery(sql);
while(r.next())
{
String fname = r.getString(“Fname”);
String lname = r.getString(“Lname”);
String age = r.getString(“Age”);
System.out.println(fname+””+lname+””+age);
}
}
Catch(Exception e)
{
}
}
Public static void main(String args[])
{
new db();
}

Question:Write a program to create three buttons and change


background colors to push any button at a time ?
Code:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<APPLET CODE = “jj.class” width = 500 height=500>
</APPLET>*/
Public class jj extends Applet implements
Action Listener
{
Button b1,b2,b3;
String str ;
public void init()
{
b1=new Button(“RED”);
b2=new Button(“GREEN”);
b3=new Button(“BLUE”);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
add(b1);
add(b2);
add(b3);
}
public void action Performed(ActionEvent e)
{
str= e.getActionCommand();
if(str.equals(“RED”))
setBackground(Color.red);
if(str.equals(“BLUE”))
setBackground(Color.blue);
}
}

Question:Write a program to show applet life cycle states?


Code:
import java.awt.*;
import java.applet.*;
/*<applet code = “program.class” width=300 height=300>
</applet>*/
public class program extends Applet
{
Font f = new Font (“TimesRoman”,Font.ITALIC,30);

public void start ()


{
System.out.println(“call to start method”);
}

public void init()


{
System.out.println(“call to stop”);
}
Public void destroy()
{
System.out.println(“call to destroy”);
}
public void paint (Graphic g)
{
g.setColor(Color.yellow);
g.setFont(f);
g.drawString(“Hello OOPS”,15,13);
}
}

Questions:Write a program of Thread implementation by


extending Thread?
Code:
class square extends Thread
{
public void run()
{
System.out.println(“Display square of numbers”);
for(int I = 1;i<=10;i++)
System.out.println(“Square of “+i+ “is” +(i*i)));
}
}
class cube extends Thread
{
public void run()
{
System.out.println(“Displaying cube of numbers”);
for(int i=1:i<=10;i++)
System.out.println(“cube of ” +i+ “is” +(i*i*i));
}
}
class thread
{
public static void main(String args[])
{
Thread t1=new square();
Thread t2=new square();
t1.start();
t2.start();
}
}

Questions:Write a program for Buffered Reader to


read characters from the console.
Code:
import java.io*;
class BRRead{
public static void main (String args[])
throws IOException
{
char c;
BufferedReader br =new
BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter characters,’q’ to quit.”);
do {
c = (char)br.read();
System.out.println(c);
}while(c !=’q’);
}
}
Question:Write a program to copy a file called first.txt to a file
called Second.txt?
Code:
import java.io.*;
class CopyFile{
public static void main (String args[]) throws IOException
{
int i ;
FileInputStream fin;
FileOutputStream fout;
try{
// open input file
try{
fin = new FileInputStream(args[0]);
}catch(FileNotFoundException e){
System.out.println(“Input File Not Found”);
return ;
}
try{
fout= new FileOutputStream(args[]);
}catch(FileNotFoundException e){
System.out.println(“Errpr Opening Output File”);
return ;
}
}catch(ArrayIndexOutOfBoundException e){
System.out.println(“Usage: CopyFile From TO”);
return;
}
try{

do{
i =fin.read();
if (i!=-1) fout.write(i);

}while(i!= -1);
}catch(IOException e){
System.out.println(“File Error”);
}
fin.close();
fout.close();
}
}
OBJECT ORIENTED
PROGRAMMING AND
METHODOLOGY
(BCSP-305)

Submitted to: – Submitted by:-


Mr.Yogesh Kothyari Aashish Rawat
Roll No-191190101001
Branch :- C.S.E (2nd Year)
OBJECT ORIENTED
PROGRAMMING AND
METHODOLOGY
(BCSP-305)

Submitted to: – Submitted by:-


Mr.Yogesh Kothyari Mukund Mukhiya
Roll No-191190101013
Branch :- C.S.E (2nd Year)
OBJECT ORIENTED
PROGRAMMING AND
METHODOLOGY
(BCSP-305)

Submitted to: – Submitted by:-


Mr.Yogesh Kothyari Kanika Sanwal
Roll No-191190101009
Branch :- C.S.E (2nd Year)
INDEX

S.NO PROGRAM DATE SIGN


1. Write a program to create a database and
create connectivity code of jdbc odbc
program

2. Write a program to create three


buttons and change background colors
to push any button at a time
3. Write a program to show applet life
cycle states
4. Write a program of Thread
implementation by extending Thread
5. Write a program for Buffered
Reader to read characters from the
console
6. Write a program to copy a file called
first.txt to a file called Second.txt
OBJECT ORIENTED
PROGRAMMING AND
METHODOLOGY
(BCSP-305)

Submitted to: – Submitted by:-


Mr.Yogesh Kothyari Desh Deepak Kohli
Roll No-191190101006
Branch :- C.S.E (2nd Year)

You might also like