Final Core Java
-
Upload
tornado2307 -
Category
Documents
-
view
249 -
download
0
Transcript of Final Core Java
-
8/13/2019 Final Core Java
1/48
C T GROUP OF INSTITUTIONS
JALANDHAR
BS-210 Core Java Programming
Lab Manual
BSc IT (4)
Computer Application
-
8/13/2019 Final Core Java
2/48
LIST OF EXPERIMENTS
1. Write a Program to Input a String and display it on screen.
2. Write a Program to compute the area of a circle using variables.
3. Write a Program to add two numbers using Command Line Arguments.4. Write a Program to check whether the given number is Even or Odd using if-else
statement.5. Write a Program to determine the season of a particular month .
6. Write a Program to display menu (Add, Sub. Mul, Div) using switch statement.
7. Write a Program to find the factorial of a given number using while statement.8. Write a Program to reverse a 5digit number and calculate sum of its digits using for
statement.
9. Write a Program to that uses continue to print a triangular multiplication for 1 to 4.
12 4
3 6 94 8 12 16
10. Write a Program to sort a list of 7 numbers in ascending order .11. Write a Program to generate a Floyd triangle using 2D array.
0
1 23 4 5
6 7 8 9
12. Write a Program to make a class and introduce methods and fields.
13. Write a Program to create a class using constructor statements.14. Write a Program to demonstrate the fundamentals of inner class.
15. Write a Program to inherit the property of one class into another.16. Write a Program to inherit the property of a base class in derived class using super
statement.
17. Write a Program to make a package.
18. Write a Program to handle Arithmetic exception using try - catch statement.19. Write a Program to implement nested try - catch statements.
20. Write a Program to create thread and control main thread.
21. Write a Program to create multiple threads.
22. Write a Program to display This is an Applet string on an applet.23. Write a Program to make a simple moving banner applet.
24. Write a Program to implement URL class on applet.
25. Write a Program to display IP address of a system.26. Write a Program to display hostname of a system.27. Write a Program to display protocol, hostname, port & file name of a system.
28. Write a Program for chatting using tcp/ip socket
29. Write a Program to set the AWT component controls.30. Write a Program to insert, delete, and update a table using JDBC-ODBC connection.
-
8/13/2019 Final Core Java
3/48
INTRODUCTION TO JAVA
Java language was developed by Sun Microsystem in the year 1991 as a part of greenproject.
GREEN PROJECT:
a research group was working to develop software to control consumer electronicsdevices, during this time they developed a device called " star 7"
for which the operating system was planned to be developed in "c++"
however one of the team member "James Gosling " was not very satisfy with the
performance of c++ hence he developed a new language for start he named it as "oak".he used to see an oak outside his office
in 1995 Sun Microsystem renamed this language as java.
FEATURES OF JAVA:
1) Object Oriented Programming
2) Platform Independent3) Robust
4) Reliable, Safe & Secure
5) Compiler and Interpreter6) Dynamic
7) Multithreaded
8) High perfomance
9) Portable10) Simple & Easy to learn
Object Oriented
o Object oriented throughout - no coding outside of class definitions,including main().
o An extensive class library available in the core language packages.Platform Independence
o The Write-Once-Run-Anywhereideal has not been achieved (tuning fordifferent platforms usually required), but closer than with other languages.
Robust
o Exception handling built-in, strong type checking (that is, all data must bedeclared an explicit type), local variables must be initialized.
-
8/13/2019 Final Core Java
4/48
Security
o No memory pointerso
Programs runs inside thevirtual machinesandbox.
o Array index limit checkingsecurity manager - determines what resources a class can access such as
reading and writing to the local disk
Compiler/Interpreter
o Code is compiled to bytecodes that are interpreted by a Java virtualmachines (JVM) .
o This provides portability to any machine for which a virtual machine hasbeen written.
o The two steps of compilation and interpretation allow for extensive codechecking and improved security.
Dynamic Binding
o The linking of data and methods to where they are located, is done at run-time.
o New classes can be loaded while a program is running. Linking is done onthe fly.
o Even if libraries are recompiled, there is no need to recompile code thatuses classes in those libraries.
This differs from C++, which uses static binding. This can result infragileclasses for cases where linked code is changed and memory pointers then
point to the wrong addresses.
High Performance
o Interpretation of bytecode slowed performance in early versions, butadvanced virtual machines with adaptive and just-in-time compilation and
other techniques now typically provide performance up to 50% to 100%
the speed of C++ programs.
Threading
o Lightweightprocesses, called threads, can easily be spun off to performmultiprocessing.
o Can take advantage of multiprocessors where availableo Great for multimedia displays.
http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Supplements/Chapter01/JVM.htmlhttp://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Supplements/Chapter01/JVM.htmlhttp://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Supplements/Chapter01/JVM.htmlhttp://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Supplements/Chapter01/JVM.html -
8/13/2019 Final Core Java
5/48
What is the Java Virtual Machine?
The JVM is the software that executes Java bytecode. A Java program, written in a file
with a .java extension, is compiled into class files that have a .class extension. The classfiles are written in bytecode. To execute these files, the computer uses the JVM to
interpret the bytecode.
A browser that is capable of executing Java applets has the JVM built into it. To run a
Java application, the Java Runtime Environment (JRE) must be installed. The JRE
contains the files in the Java Development Kit minus the development tools, only the filesnecessary to run a Java application are present.
The bytecode is the same for all platforms, but the JVM will be different on differentplatforms because it needs to execute programs using the native code of the machine it is
running on.
Development Tools: The development tools provide everything you'll need for
compiling, running, monitoring, debugging, and documenting your applications. As a
new developer, the main tools you'll be using are the javaccompiler, the javalauncher,
and the javadocdocumentation tool.
What is an Object
Object is instance of class, it contain data as well as behavior of the functions how to
manipulate that data.
What is a Class
Class is a collection of similar objects.
A class is a blueprint or prototype from which objects are created.
http://java.sun.com/docs/books/tutorial/java/concepts/object.htmlhttp://java.sun.com/docs/books/tutorial/java/concepts/class.htmlhttp://java.sun.com/docs/books/tutorial/java/concepts/class.htmlhttp://java.sun.com/docs/books/tutorial/java/concepts/object.html -
8/13/2019 Final Core Java
6/48
EXPERIMENT NO. 1
Aim : - Write a program to Input a String and display it on screen
Explanation:- This is a simple program in java to display strings.
Program :-
class first
{
public static void main(String str[])
{String s=String.valueOf(str[0]);
System.out.println("your input is----------> "+s);
}}
Output:-
Viva -Voice Questions:
1. What do you mean by object oriented programming.2. What is the difference between java and c++.3. What is class.4. What is object.
-
8/13/2019 Final Core Java
7/48
EXPERIMENT NO. 2
Aim :- Write a program to compute the area of a circle.
Explanation :-This program demonstrate the uses of datatypes and variables to compute
area of a circle.
Program :-
class radius{
public static void main(String str[])
{
int r;double a;
float pi=3.1416f;
r=Integer.parseInt(str[0]);a=pi*r*r;
System.out.println("Area of a circle is="+a);
}}
Output :-
Viva -Voice Questions:
1. What is datatypes.2.
What is variable.3. What is the difference between object and variable?
4. Why do I have to put an f after a floating point constant?
-
8/13/2019 Final Core Java
8/48
EXPERIMENT NO. 3
Aim -: Write a program to add two integer numbers using
command line argument.
Explanation -:This program enable the user to add two integer numbers using command
line
Program -:
class add
{public static void main(String str[])
{
int a,b,c;
a=Integer.parseInt(str[0]);b=Integer.parseInt(str[1]);
c=a+b;
System.out.println("Sum Is =- " + c);}
}
Output :-
Viva -Voice Questions:
1. What do you mean by command line argument programming.2. What java uses compiler , interpreter or both.3. Can I compile group of java files once?
-
8/13/2019 Final Core Java
9/48
EXPERIMENT NO. 4
Aim: - Write a program to check whether the given number is even
or odd using if-else statements.
Explanation :-This program demonstrate the simple use of if else by checking the
number using modulo operator.
Program :-class check
{
public static void main(String str[]){
int a;
a=Integer.parseInt(str[0]);
if(0==a%2){
System.out.println("given no. is="+a);System.out.println("Number is Even ");
}
else{
System.out.println("given no. is="+a);
System.out.println("Number is Odd ");
}} }
Output :-
Viva - Voice Questions:
1. What is reserve word and how many?.2. What is the difference between division and modulo operator.3. What is jvm4. What is jdk
-
8/13/2019 Final Core Java
10/48
EXPERIMENT NO. 5
Aim :- Write a program to determine which season a particular
month.
Explanation :-This program is uses the logical operator with ladder if else statement.
Program :-class season
{
public static void main(String str[])
{int a;String s;
a=Integer.parseInt(str[0]);
if(a==12||a==1||a==2)
s=Winter;else
if(a==3||a==4||a==5)
s=Spring;else
if(a==6||a==7||a==8)
s=Summer;else
if(a==9||a==10||a==11)
s=Autom;
else
s=Bogus Month;System.out.println(Enter month number is the :+s)
} }
Output :-
Viva -Voice Questions:
1. What is the difference between logical and bitwise operator.2. What is byte code3. What language is the Java compiler and JVM written in?
-
8/13/2019 Final Core Java
11/48
-
8/13/2019 Final Core Java
12/48
d=b/c;
System.out.println("division="+d);
break;}
default : {
System.out.println("Enter correct choice");}}
k++;
}while(k
-
8/13/2019 Final Core Java
13/48
EXPERIMENT NO. 7
Aim: - Write a program to find the factorial of a given number
while statement.
Explanation :- While statement is entry controlled loop statement 1stit evaluate
condition then body of the code is executed.
Program :-
class fact
{
public static void main(String str[]){
int num,fac=1,i=1;
num=Integer.parseInt(str[0]);
while(num>=i)
{fac=fac*i;
i++;
}
System.out.println(Factorial of a given no is=+fac);
}
}
Output :-
Viva -Voice Questions:
1. What is the difference between while and do while loop.2. What is the difference between break and continue statements.
-
8/13/2019 Final Core Java
14/48
-
8/13/2019 Final Core Java
15/48
EXPERIMENT NO. 8
Aim :-Write a program to reverse a 5digit number and calculate
sum of its digit using for loop.
Explanation :- forstatement is entry controlled loop statement 1stit evaluate condition
then body of the code is executed in this we can reverse any integer number..
Program :-
class rev{
public static void main(String str[])
{
int a,b,sum=0,rev=0;a=Integer.parseInt(str[0]);
for(;a>0;){
b=a%10;rev=rev*10+b;
sum=sum+b;
a=a/10;}
System.out.println("revers is "+rev);
System.out.println("sum of the digit "+sum);}
}Output :-
VivaVoice Questions:
1. What is the type casting.2. How many types we can convert data
-
8/13/2019 Final Core Java
16/48
EXPERIMENT NO. 9
Aim: -Write a program to that use continue to print a triangular
multiplication for 1 to 4.12 4
3 6 94 8 12 16
Explanation :-for statement is entry controlled loop statement 1stit evaluate condition
then body of the code is executed. This is the nesting of for statement with continue label.
Program :-class table
{
public static void main(String str[]){
huk:
for(int i=1;i
-
8/13/2019 Final Core Java
17/48
EXPERIMENT NO. 10
Aim:-Write a program to sort a list of 7 numbers in ascending
order
Explanation :-Thisprogram demonstrate the uses of array, how to initialize and how tocreate memory for array elements.
Program :-
class order{
public static void main(String str[])
{
int a[],n;a=new int[10];
for(int i=0;i
-
8/13/2019 Final Core Java
18/48
EXPERIMENT NO. 11
Aim :-Write a program to generate a pattern using 2D array.0
1 2
3 4 56 7 8 9
Explanation :-Thisprogram demonstrate the uses of 2D array, how to initialize and how
to create memory for array elements.
Program :-class pattern
{public static void main(String str[])
{int toD[][]=new int[4][];
toD[0]=new int[1];toD[1]=new int[2];
toD[2]=new int[3];
toD[3]=new int[4];int i,j,k=0;
for(i=0;i
-
8/13/2019 Final Core Java
19/48
EXPERIMENT NO. 12
Aim :-Write a program to make a class and introduce method and
field.Explanation :-This programtells the uses of creating class ,method and field.Program :-
class democlass{
public static void main(String str[])
{
demo obj=new demo();demo obj1=new demo();
obj.w=10;obj.h=20;
obj.l=30;
obj1.w=12;obj1.h=22;obj1.l=17;
obj.disp();
obj1.disp();}}
class demo
{int w,h,l;
void disp()
{System.out.println("volum is");
System.out.println(w+h+l);
}}Output-:
VivaVoice Questions:
1. What is class2. What is the difference between structured and object oriented programming.3. What is the difference between class and structure4. What are the access modifier.
-
8/13/2019 Final Core Java
20/48
EXPERIMENT NO. 13
Aim :-Write a program to creat a class using constructor.Explanation :-This program tells the uses of constructor ,how to use in classes.
Program :-
class democlass
{
public static void main(String str[])
{
System.out.println("object one is");demo obj=new demo();
int v=obj.vol();
System.out.println(+v);System.out.println("object two is");
demo obj1=new demo();
int k=obj1.vol();
System.out.println(+k);}
}
class demo{
int w,h,l;
demo(){
System.out.println("calling constructor");
System.out.println("volum is");w=10;
h=15;
l=20;
}int vol()
{
return(w*l*h);}
}
-
8/13/2019 Final Core Java
21/48
-
8/13/2019 Final Core Java
22/48
EXPERIMENT NO. 14
Aim :-Write a program to demonstrate the fundamental of innerclass.Explanation :-This program demonstrate the fundamentals of inner class.
Program :-
class innerclass
{
public static void main(String str[])
{outer obj=new outer();
obj.test();}
}class outer
{
int w=25;void test()
{
inner in=new inner();
in.disp();}
class inner{
void disp()
{
System.out.println("outer class data is"+w);}
}
}Output-:
-
8/13/2019 Final Core Java
23/48
Viva - Voice Questions:
1. What does it mean that a method or field is "static"?2. how many public class are possible in java3. What is the difference between jre and java?
-
8/13/2019 Final Core Java
24/48
EXPERIMENT NO. 15
Aim-: Write a program to inherit a property of one class to
another.
Explanation -:This program enable the user to inherite the property of a base class into
the derived class.
Program -:class inherit
{
public static void main(String str[]){
parent a=new parent();
child b=new child();a.i=10;a.j=20;
System.out.println("content of parent class");
a.show();System.out.println();
b.i=15;
b.j=25;
b.k=35;System.out.println("content of child class");
b.show();
b.showc();System.out.println();
b.sum();
}
}class parent
{
int i,j;void show()
{
System.out.println("i and j = "+i+" "+j);
}}
class child extends parent{
int k;
void showc(){
-
8/13/2019 Final Core Java
25/48
-
8/13/2019 Final Core Java
26/48
EXPERIMENT NO. 16
Aim-:Write a program to inherite a property of a base class in
derived class using super statement
Explanation -:This program enable the user to inherite the property of a base class into
the derived class using supper statement supper is the 1ststatement of constructor.
Program -:
class item
{int itemno;
String disc;
float rate;int qoh;
void disp()
{System.out.println("item class");
System.out.println("item no is"+itemno);
System.out.println("disc is"+disc);
System.out.println("reate is"+rate);System.out.println("quantity is"+qoh);
}
item(){
itemno=0;
disc=" ";
rate=0;qoh=0;
}
item(int n,String s,float r,int q){
itemno=n;
disc=s;rate=r;
qoh=q;
}}
-
8/13/2019 Final Core Java
27/48
-
8/13/2019 Final Core Java
28/48
-
8/13/2019 Final Core Java
29/48
EXPERIMENT NO. 17
Aim-:Write a program to make a package.
Explanation -:This program enable the user to make a own packageand uses the property
of a package class into the derived classes.
Program -:import huk.*;
class mypack
{public static void main(String str[])
{
pack obj=new pack("husain ullah khan",12398.45);obj.show();
}
}
Output:-
Viva
Voice Questions:
1. What is packages2. What is class libraries3. Why can't the compiler find my package?
-
8/13/2019 Final Core Java
30/48
EXPERIMENT NO. 18
Aim-:Write a program to handle Arithmetic exception using trycatch statement.
Explanation -:This program enable the user to handle the exception using try catch
statement.
Program -:class excep
{
public static void main(String str[]){
int i=0,j;try{
j=39/i;}
catch(Exception e)
{System.out.println(I am handling exception);
System.out.println(e);
}
}
Output:-
VivaVoice Questions:
1. what is exception .2. what are the advanteges of exception.3. What is the super class of exception.
-
8/13/2019 Final Core Java
31/48
EXPERIMENT NO. 19
Aim-: Write a program to implement nested try catch statement.
Explanation -:This program enable the user handle exception using multiple try catch
statements
Program -:class excep
{public static void main(String str[])
{
try{
int i=str.length;System.out.println(i);
int b=33/i;
int c[]={1};
}
catch(ArithmeticException e){
System.out.println(I am handling exception);
System.out.println(e);}
Catch(ArrayIndexOutOfBoundsException e)
{
System.out.println(I am handling exception);System.out.println(e);
} } }
Output:-
Viva - Voice Questions:
1. what are the keywords to handle exception.2. What is the difference between throw and throws.3. List any five exception name.
-
8/13/2019 Final Core Java
32/48
EXPERIMENT NO. 20
Aim-: Write a program to create Thread and control main thread.
Explanation -:This program enable the user to create thread and how to control the main
thread
Program -:class demoth
{public static void main(String str[])
{
int i=5;
Thread t=Thread.currentThread();System.out.println("current thread "+t);
t.setName("mythread ");
System.out.println("changed thread "+t);try{
for(;i>0;)
{System.out.println(i);
Thread.sleep(1000);
i--;} }
catch(Exception e)
{
System.out.println("interupted thread");} }
}
Output:-
Viva - Voice Questions:
1. Define thread2. How many types we can create threads3. What is the advanteg of threading
-
8/13/2019 Final Core Java
33/48
-
8/13/2019 Final Core Java
34/48
catch(Exception e)
{
System.out.println(name+"Interupted");}
System.out.println(name+"Exited");
}}
Output:-
Viva -Voice Questions:
1. what is the advanteg of multi threading programming2. what is thread model3. what are the methods in thread class
-
8/13/2019 Final Core Java
35/48
EXPERIMENT NO. 22
Aim-: Write a program to display This is an Applet string on an
applet.
Explanation -:This program demonstrate the user make internet programming using
Applet.
Program -:import java.awt.*;
import java.applet.*;
/*
*/public class app extends Applet
{String msg="This is an Applet";
public void init()
{
setBackground(Color.cyan);setForeground(Color.red);
start( );
}
public void paint(Graphics g){Font f=new Font("Monotype
Corsiva",Font.BOLD+Font.ITALIC,14);
g.setFont(f);g.drawString(msg,50,30);
}}
Output:-
-
8/13/2019 Final Core Java
36/48
-
8/13/2019 Final Core Java
37/48
-
8/13/2019 Final Core Java
38/48
EXPERIMENT NO. 23
Aim-: Write a program to make a simple moving banner applet.
Explanation -:This program demonstrate the user to make banner on an appletprogramming
Program -:import java.awt.*;
import java.applet.*;
/*
*/public class SimpleBanner extends Applet implements Runnable
{
String msg="A Simple Banner Applet";Thread t=null;
boolean stopflag;
public void init(){
setBackground(Color.cyan);
setForeground(Color.red);}
public void start()
{
t=new Thread(this);stopflag=false;
t.start();
}public void run()
{
char ch;
for(;;){
try
{
repaint();Thread.sleep(250);
ch=msg.charAt(0);msg=msg.substring(1,msg.length());msg+=ch;
if(stopflag)
break;}
catch(Exception e)
{
-
8/13/2019 Final Core Java
39/48
System.out.println("Exception :"+e);
}
}}
public void stop( )
{stopflag=true;t=null;
}
public void paint(Graphics g){
g.drawString(msg,50,30);
}
}
Output:-
VivaVoice Questions:
1. What is graphics class in applet?2. What are the advantages of applet?
-
8/13/2019 Final Core Java
40/48
EXPERIMENT NO. 24
Aim-: Write a program to implement URL class on applet.
Explanation -:This program enable the user to implement url on an appletProgram -:
import java.awt.*;
import java.applet.*;import java.net.*;
public class App1 extends Applet
{
public void start(){ AppletContext ac=getAppletContext();
URL u=getCodeBase();
Try
{ac.showDocument(new URL(u+"test.html"),"_parent");
}
catch(Exception e){
showStatus("URL not found");
} }}
Output:-
VivaVoice Questions:
1. what is url2. what is the difference between codebase and getcodebase method
-
8/13/2019 Final Core Java
41/48
EXPERIMENT NO. 25
Aim :- Write a program to display IP address of a system.
Explanation -:This is the simple network program to find ip address of a system
Program -:
import java.net.*;
public class ipadd{
public static void main(String args[])
{
try{
InetAddress i=InetAddress.getLocalHost( );
String s=i.toString( );System.out.println(s.substring(s.indexOf(/)+1));
}
catch(Exception e){
System.out.println(Exception : +e);
}
}}
Output:-
Viva
Voice Questions:
1. what is ip addressing scheme2. what is internet protocol3. what are the different classes of addressing scheme
-
8/13/2019 Final Core Java
42/48
-
8/13/2019 Final Core Java
43/48
EXPERIMENT NO. 27
Aim :- Write a program to display protocol, host name , port and
filename of a system.
Explanation -:This program enable the user to display protocol hostname, port and file
of a sysytem
Program:-
import java.net.*;
public class host{ public static void main(String args[])
{ try {
InetAddress i=InetAddress.getLocalHost( );
String s=i.toString( );
System.out.println(s.substring(0,(s.indexOf("/"))));
} catch(Exception e) {
System.out.println("Exception : "+e);
} } }
Output:-
Viva Questions:1. what is the difference between port and socket2. what is protocol
-
8/13/2019 Final Core Java
44/48
EXPERIMENT NO. 28
Aim :- Write a program for chatting using tcp/ip socket
Explanation -:This program enable the user to chat with tcp/ip socket
Program:-
import java.net.*;
import java.io.*;
public class ChatServer{
public static void main(String args[])
{
try{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));ServerSocket ss=new ServerSocket(2345);
Socket skt=ss.accept( );
BufferedReader skt_in=new BufferedReader(newInputStreamReader(skt.getInputStream( )));
PrintStream skt_out=new PrintStream(skt.getOutputStream( ));
while(true)
{System.out.println(skt_in.readLine( ));
skt_out.println(What is your name);
yourname=skt_in.readLine( );System.out.println(yourname);
String s=skt_in.readLine( );
System.out.println(s);
String myname=br.readLine( );skt_out.println(myname);
break;
}while(true)
{
String recv=skt_in.readLine( );
System.out.println(yourname+:+recv);
String send=br.readLine( );skt_out.println(send);
}
}catch(Exception e)
{
System.out.println(Exception :+e);}} }
-
8/13/2019 Final Core Java
45/48
// CLIENT
import java.net.*;
import java.io.*;public class ChatClient{
public static void main(String args[])
{try
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));Socket skt=new Socket(rungtaibm,2345);
BufferedReader skt_in=new BufferedReader(new
InputStreamReader(skt.getInputStream( )));PrintStream skt_out=new PrintStream(skt.getOutputStream( ));
while(true)
{
skt_out.println(hello can I connect);skt_out.println(skt_in.readLine( ));
String myname=br.readLine( );
skt_out.println(myname);skt_out.println(What is yours);
String yourname=skt_in.readLine( );
System.out.println(yourname);
break;}
while(true)
{String send=br.readLine( );
skt_out.println(send);
String recv=skt_in.readLine( );System.out.println(yourname +:+recv);
}
}
catch(Exception e){
System.out.println(Exception :+e);
}
}}
-
8/13/2019 Final Core Java
46/48
OUTPUT :
TCP Server
TCP Client
Viva - Voice Questions:
1. What is tcp/ip protocol2. In which layer tcp/ip protocol exist3. Is tcp/ip is connectinless or connectin oriented.4. What is the difference between ARP and RARP
-
8/13/2019 Final Core Java
47/48
EXPERIMENT NO. 29
Aim-:Write a program to set the awt component controls.
Explanation -:This program enable the user to make graphical user interface
Program -:
Import java.awt.*;Import java.applet.*;
Public class comp extends Applet
{
BorderLayout b1=new Borderlayout();Button b1,b2,b3,b4;
Label l1,l2;
Public void init()
{b1=new Button (ok);
b2=new Button (cancel);
b3=new Button (ok);b4=new Button (cancel);
l1=new label(are u sure ?);
l2=new label(are u sure?);setLayout(null);
b1.setBounds(20,20,100,20);
b2.setBounds(20,30,110,30);
b3.setBounds(20,40,120,40);
b4.setBounds(20,40,120,40);l1.setBounds(20,50,130,50);
l2.setBounds(20,60,140,60);Add(b1);Add(b2);Add(b3);Add(b4);Add(l1);Add(l2);
}}
Output-:
Viva - Voice Questions:
1. what is awt components.2. what is the difference betweem awt and swing component3. what is team class
-
8/13/2019 Final Core Java
48/48
EXPERIMENT NO. 30
Aim-:Write a program to insert, delete and update a table using
JDBC-ODBC connection .
Explanation -:This program enable the user to work with databaseProgram -:import java.sql.*;
import java.util.*;class badabase
{
Public static void main(String str[])
{Try
{
Resultset rs;
Class.forName(sun.jdbc.odbc.jdbcodbcDriver);String url=jdbc:odbc:huk;
Connection con;
Con=DriverManager.getconnection(url);Statement set=con.createstatement();
Rs=ser.executeQuery(Select * from db);
String ins=Insert into db values(husain,it,539);String del=Delet form db where name =huk;
preparedStatement set=con.preparedstatement(ins);
set.getString(1,huk);
set.executeupdate();con.commit();
while(rs.next()){
System.out.println(rs.getString(1)+ +rs.getString(2);
}
Con.close();}
Catch(exception e)
{
Sysstem.out.println(no such class);
}}}
VivaVoice Questions: