Abheet Kumar 19Bcs002

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 131

School of Computer Science and Engineering

LAB FILE REPORT


JAVA PROGRAMMING
Computer Science and Engineering

Name: ABHEET KUMAR


Entry number:19BCS002

Group: X Semester: 5TH

Course Coordinator’s Sign: ……… Remarks:


……………
LIST OF JAVA PROGRAMS CSL3023

1.Write program to print the kth digit from last. e.g. input 23617 and k=4 output 3.

2. Write a program to print first digit. e.g. input 23516 output

3. Write program to print the second digit. e.g. input 23516 the output is

4. Write program to find sum of all digits. Input 23617 output 2+3+6+1+7=19.

5. Write program, which will find sum of product to consecutive digits. e.g. when
the input is 23145 the output is 2x3 + 3x1 + 1x4 + 4x5 = 33.

6. Write program, which reads two number (assume that both have same number
of digits). The program outputs the sum of product of corresponding digits. Input
327 and 539 output 3x5+2x3+7x9=84.

7. Write program to print positional values of digits. Input 21463 output 3, 60, 400,
1000 and 20000.

8. Write program to find sum of even digits. Input 23617 output 2+6=8.

9. Write program to find number of digits. Input 423 output 3. Input 21151 output
5.

10. Write program to find number of even digits. In above case 2 and 1
respectively.

11. Write program to print the last even digit. e.g. input 23613 output 6.
[Hint:while (x%2 ¹ 0) x=x/10] 42. Program to print the digit immediately before
the last even digit. In above case 3.

12. Write program to print the digit immediately after the last even digit. In above
case 1.

13. Write program to print the last digit, which is multiple of 3. e.g. input 23617
output 6.
14. Write program to print the second last even digit. e.g. input 23863 output 8 (do
not use ‘if’). Input 325145761 output 4. [Hint: use two loops]

15. Read a number. Do half of number after last odd digit. Input 3 times. Input
61389426 output 184167639 (61389213*3). Input 87 output 261. Input 78 output
222 (74*3).

16. Write program, which finds the sum of numbers formed by consecutive digits.
Input 2415 output 24+41+15=80.

17. Find sum of numbers formed by exchanging consecutive digits. In above


42+14+51=10

18.Write a Java program that prints all real solutions to the quadratic equation ax2
+bx+c = 0. Read in a, b, c and use the quadratic formula. If the discriminate b2 -
4ac is negative, display a message stating that there are no real solutions.

19.The Fibonacci sequence is defined by the following rule. The first 2 values in
the sequence are 1, 1. Every subsequent value is the sum of the 2 values preceding
it. Write a Java program that uses both recursive and non-recursive functions to
print the nth value of the Fibonacci sequence.

20.Write a program for constructor overloading and overriding.

21.Write a program to find number of ways colors of rainbow can be permuted.

22.Write a program to demonstrate various function available in Math class.

23.Demonstrate the use of BigInteger and BigDecimal classes to perform


operations on very large integers and decimals

24.Write a Java Program to implement inheritance and demonstrate use of method


overriding.

25.Write a Java Program to implement multilevel inheritance by applying various


access controls to its data members and methods.

26.Write a Java program to practice using String class and its methods.
27.Write a Java program to practice using String Buffer class and its methods.

28.You are given a String at runtime. Capitalize all the characters at all odd
indexes in the string.

29.You are given a String at runtime. You are required to fetch the remaining
String after the occurrence of a certain sequence / character.

30.You are given a String at run time. Count the occurrence of a given word /
sequence in that String.

31.You are given a String at run-time. Delete all duplicate words from the String
(ignore the case) and return the modified String.

32.You are given a String at runtime. Find total vowels in the given String and also
display the count of each vowel in the String.

33.You are given a String at runtime. Replace all the characters at the even index
by the character present al all the next even index. Replace the character at the last
even index by “1”.

34.Write a program to demonstrate various String/StringBuffer/StringBuilder


functions for: Reversing a string (check palindrome), conversion to
uppercase/lowercase, equality check of strings, inserting/deleting
characters/sequence at a particular index, searching a sequence/character in String
at a particular position in String. Fetching the index of a particular
characters/substring, Replacing the occurrence of a substring/character in a string,
comparing string lexicographically, splitting a string based on a given token, etc.

35..Write a Java Program to implement Wrapper classes and their methods.

36.Write a java program to find the details of the students eligible to enroll for the
examination ( Students, Department combinedly give the eligibility criteria for the
enrollement class) using interfaces

37.Write a program to demonstrate use of implementing interfaces.

38.Write a java program to create an abstract class named Shape that contains two
integers and an empty method named printArea(). Provide three classes named
Rectangle, Triangle and Circle such that each one of the classes extends the class
Shape. Each one of the classes contain only the method printArea( ) that prints the
area of the given shape.

39.WAP for class TV with attributes name of company , Screen Size using
keyword inheritance . Create a colour TV class & B&W TV class.

40.WAP to demonstrate the use of overriding hashCode(), equals() & toString()


methods of Object class(The cosmic superclass).

41.Write a Java program to implement the concept of importing classes from user
defined package and creating packages.

42.WAP to multiply two given matrices

43.Write a Java Program to implement array of objects.

44.Write a Java program to implement the concept of importing classes from user
defined package and creating packages.

45.Write a Java Program to implement Vector class and its methods

46.Write a program to implement the concept of threading by extending Thread


Class

47.Write a program to implement the concept of threading by implementing


Runnable Interface

48.Write a java program that implements a multi-thread application that has three
threads. First thread generates random integer every 1 second and if the value is
even, second thread computes the square of the number and prints. If the value is
odd, the third thread will print the value of cube of the number.

49.WAP to create a class MyThread implementing the Runnable interface . The


constructor of this class takes an int as argument which has only three values 1,2,or
3. Based on the value of this integer the run() method will perform different
functions. If the value passed to constructor is 1, the thread will print even no.
series up to 100.If the value passed to constructor is 2, the thread print the odd no.
series, If the value passed to constructor is 3 the thread shall print the multiples of
3 up to 50.
50.Program to show Synchronization between Threads.

51.Create an ArrayList of objects(say Student/Employee objects) ,store


information about the objects at run time and store these objects in the ArrayList.

52.Write program for implementation of ArrayList, LinkedList , HashMap , Set


using appropriate interfaces of your own choice ?

53.Write a program to implement the concept of Exception Handling using


predefined exception.

54.Write a program to implement the concept of Exception Handling by creating


user defined exceptions.

55.Write a program using Applet For configuring Applets by passing


parameters.

56.Write a Java Program to demonstrate Keyboard event

57.Write a Java Program to demonstrate Mouse events

58.Write programs for using Graphics class - to display basic shapes and fill them -
draw different items using basic shapes - set background and foreground color.

59.Write a Java program that works as a simple calculator. Use a grid layout to
arrange buttons for the digits and for the +, -,*, % operations. Add a text field to
display the result. Handle any possible exceptions like divide by zero.

60. Develop an Applet that receives an integer in one text field & compute its
factorial value & returns it in another text filed when the button “Compute” is
clicked.

61.Write a Java program that handles all mouse events and shows the event name
at the center of the window when a mouse event is fired. (Use adapter classes).

62.WAP in AWT to demonstrate frame, checkbox, menu of your own choice.

63.Write a Program for JTable.

64.Write a Swing Program to show Magic Square Table.


65.Write a Program for Calculator using Swing.

66.Write a java program to design the page authenticating user name and password
by using SWING.

67. Write a java program to design a calculator by using Grid Layout.

68.Write a java program that implements a simple client server application. The
client sends data to server. The server receives the data uses it to produce a result
and then sends the result back to the client then the client displays the result on the
console.

69.Write a java program that simulates a traffic light. The program lets the user
select one of three lights: red, yellow, or green with radio buttons. On selecting a
button, an appropriate message with “stop” or “ready” or “go” should appear above
the buttons in a selected color. Initially there is no message shown.

70.Write a java program that connects to a database using JDBC and does add,
deletes, modify and retrieve operations?
SOLUTIONS
1. Write program to print the kth digit from last. e.g. input 23617 and k=4
output 3.
sol.
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int m=0;
System.out.println("enter the no");
int x = sc.nextInt();
int y = sc.nextInt();
for(int i=0; i<y; i++)
{
m=x%10;
x=x/10;
}
System.out.println(y+"th digit from last is ="+m);
}
}

2. Write a program to print first digit. e.g. input 23516 output 2.


sol.
class  Cs
{
public static void main(String args[])
{
int x = Integer.parseInt(args[0]);
int y =0;
while(x>0)
{
y=x%10;
x=x/10;
}
System.out.println("First digit is ="+y);
}
}

3. Write program to print the second digit. e.g. input 23516 the output is 3.
sol.
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y =0,z=0;
while(x>99)
{
x=x/10;
y=x%10;
}
System.out.println("Second digit is ="+y);

}
}

4. Write program to find sum of all digits. Input 23617 output


2+3+6+1+7=19.
sol.
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y =0,z=0;
while(x>0)
{
y=y+x%10;
x=x/10;
}
System.out.println("Sum of digits is ="+y);

}
}

5. Write program, which will find sum of product to consecutive digits. e.g.
when the input
is 23145 the output is 2x3 + 3x1 + 1x4 + 4x5 = 33.
sol.
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y =0,z=0;
while(x>0)
{
y= (x%10);
x=x/10;
y=y*(x%10);
z=z+y;
}
System.out.println("Sum of conjugative digits of given number is = "+z);

}
}
6. Write program, which reads two number (assume that both have same
number of digits).
The program outputs the sum of product of corresponding digits. Input 327
and 539
output 3x5+2x3+7x9=84.
sol.
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
int m=0,n=0,o=0;
while(x>0 && y>00)
{
m=x%10;
n=y%10;
o=o+(m*n);
x=x/10;
y=y/10;
}
System.out.println("sum of product of corresponding digits= "+o);
}
}
7. Write program to print positional values of digits. Input 21463 output 3,
60, 400, 1000
and 20000.
sol.
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();

int m=0,n=1;
System.out.print("Positional Values of the give number are :-");
while(x>0)
{
m=x%10;
m=m*n;
System.out.print(m +",");
n=n*10;
x=x/10;
}

}
}

8. Write program to find sum of even digits. Input 23617 output 2+6=8.
sol.
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();

int m=0,n=0;

while(x>0)
{
m=x%10;
if(m%2==0)
{
n=n+m;
x=x/10;
}
x=x/10;
}
System.out.println("Sum of even digits of given number :-"+n);

}
}

9. Write program to find number of digits. Input 423 output 3. Input 21151
output 5.
sol.
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();

int m=0,n=0;

while(x>0)
{
x=x/10;
n++;
}
System.out.println("Number of digits in given number are :- " + n);

}
}

10. Write program to find number of even digits. In above case 2 and 1
respectively.
sol.
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();

int m=0,n=0;

while(x>0)
{
m=x%10;
if(m%2==0)
{
n++;
}
x=x/10;
}
System.out.println("Number of even digits in given number are :- " + n);

}
}

11. Write program to print the last even digit. e.g. input 23613 output 6.
[Hint:while (x%2 ¹ 0) x=x/10]
sol.
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();

int m=0,n=0;

while(x>0)
{
m=x%10;
if(m%2==0)
{
System.out.println("Last even digit in given number is :- " + m);
break;
}
x=x/10;
}
}
}

12. Program to print the digit immediately before the last even digit. In
above case 3.
sol.
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();

int m=0,n=0;

while(x>0)
{
m=x%10;
if(m%2==0)
{
x=x/10;
m=x%10;
System.out.println("Digit immediately before the last even digit is :- " +
m);
break;
}
x=x/10;
}
}
}

13. Write program to print the digit immediately after the last even digit. In
above case 1.
sol.
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y =0;
int m=0,n=0;

while(x>0)
{
if(x%2==0)
{
System.out.println("The digit immediately after the last even digit="+y);
break;
}
y=x%10;
x=x/10;
}

}
}
14. Write program to print the last digit, which is multiple of 3. e.g. input
23617 output 6.
sol.
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y =0;
int m=0,n=0;

while(x>0)
{
if(x%2==0)
{
System.out.println("The digit immediately after the last even digit="+y);
break;
}
y=x%10;
x=x/10;
}

}
}

while(true)
{
while(x%2==0 && x>0)
{
x=x/10;

while(x%2==0 && x>0)


{
y=x%10;
System.out.println(y);
break;
}

}
}

15. Write program to print the second last even digit. e.g. input 23863
output 8 (do not use
‘if’). Input 325145761 output 4. [Hint: use two loops]
sol.
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y =0;
int m=0,n=0;

while(true)
{
while(x%2==0 && x>0)
{
x=x/10;

while(x%2==0 && x>0)


{
y=x%10;
System.out.println(y);
break;
}

}
}

}
}

16. Read a number. Do half of number after last odd digit. Input 3 times.
Input 61389426
output 184167639 (61389213*3). Input 87 output 261. Input 78 output 222
(74*3).
sol.
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y =0;
int z=0,count=0;

while(x>0)
{
y=x%10;
if(y%2!=0)
{
break;
}
x=x/10;
z=(int)(z+y*Math.pow(10,count));
count++;
}
z=z/2;
x=(int)(x*Math.pow(10,count));
x=(x+z)*3;
System.out.println(x);

}
}

17. Write program, which finds the sum of numbers formed by consecutive
digits. Input 2415
output 24+41+15=80.
sol.
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y =0;
int z=0,m=0,sum=0;

while (x>9)
{
y=x%10;
x=x/10;
z=x%10;
m=z*10;
sum=sum+y+m;
}
System.out.println("sum of numbers formed by consecutiv digits="+sum);

}
}

18. Find sum of numbers formed by exchanging consecutive digits. In above


42+14+51=107.
sol.
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y =0;
int z=0,m=0,sum=0;
while(x>9)
{
y=x%10;
x=x/10;
z=x%10;
y=y*10;
sum=sum+y+z;
}
System.out.println("Sum of numbers formed by exchanging consecutive
digits="+sum);

}
}

19. The Fibonacci sequence is defined by the following rule. The first 2 values in the sequence are 1, 1.
Every subsequent value is the sum of the 2 values preceding it. Write a Java program that uses both
recursive and non-recursive functions to print the nth value of the Fibonacci sequence.

import java.util.*;
class Function
{         
            void nrcf(int a,int b,int c,int n)
            {
                        for(int i=1;i<=n-2;i++)
                        {
                                    c=a+b;
                                    a=b;
                                    b=c;
                        }
                        a=b=1;
                        System.out.println("nth value in the series using non recursive function is : "+c);
                       
            }
            void  rcf(int a,int b,int c,int n)
            {
                                   
                        if(n-2>0)
                        {
                                    c=a+b;
                                    a=b;
                                    b=c;
                                    rcf(a,b,c,n-1);
                                    return;
                        }
                       
                        System.out.println("\nnth value in the series using recursive function is : "+c);
            }
}
           
class Fibonacci
{
            public static void main(String args[])
            {
                        Function f=new Function();
                        int n,a=1,b=1,c=0;
                        Scanner scr=new Scanner(System.in);
                        System.out.println("\nEnter n value:  ");
                        n=scr.nextInt();
                        f.nrcf(a,b,c,n);
                        f.rcf(a,b,c,n);
                       

            }
}

20.Write a program for constructor overloading and overriding.

public class Student {


//instance variables of the class
int id;
String name;
Student(){
System.out.println("this a default constructor");
}

Student(int i, String n){


id = i;
name = n;
}

public static void main(String[] args) {


//object creation
Student s = new Student();
System.out.println("\nDefault Constructor values: \n");
System.out.println("Student Id : "+s.id + "\nStudent Name : "+s.name);

System.out.println("\nParameterized Constructor values: \n");


Student student = new Student(10, "David");
System.out.println("Student Id : "+student.id + "\nStudent Name :
"+student.name);
}
}
21.Write a program to find number of ways colors of rainbow can be permuted.

22.Write a program to demonstrate various function available in Math class.

public class JavaMathExample1

{
public static void main(String[] args)

double x = 28;

double y = 4;

// return the maximum of two numbers

System.out.println("Maximum number of x and y is: " +Math.max(x, y));

// return the square root of y

System.out.println("Square root of y is: " + Math.sqrt(y));

//returns 28 power of 4 i.e. 28*28*28*28

System.out.println("Power of x and y is: " + Math.pow(x, y));

// return the logarithm of given value

System.out.println("Logarithm of x is: " + Math.log(x));

System.out.println("Logarithm of y is: " + Math.log(y));

// return the logarithm of given value when base is 10

System.out.println("log10 of x is: " + Math.log10(x));

System.out.println("log10 of y is: " + Math.log10(y));

// return the log of x + 1


System.out.println("log1p of x is: " +Math.log1p(x));

// return a power of 2

System.out.println("exp of a is: " +Math.exp(x));

// return (a power of 2)-1

System.out.println("expm1 of a is: " +Math.expm1(x));

}
23.Demonstrate the use of BigInteger and BigDecimal classes to perform
operations on very large integers and decimals

import java.math.BigDecimal;

public class BigDecimalExample

public static void main(String[] args)

// Create two new BigDecimals

BigDecimal bd1 =

new BigDecimal("124567890.0987654321");

BigDecimal bd2 =

new BigDecimal("987654321.123456789");

// Addition of two BigDecimals

bd1 = bd1.add(bd2);

System.out.println("BigDecimal1 = " + bd1);

// Multiplication of two BigDecimals

bd1 = bd1.multiply(bd2);

System.out.println("BigDecimal1 = " + bd1);

// Subtraction of two BigDecimals


bd1 = bd1.subtract(bd2);

System.out.println("BigDecimal1 = " + bd1);

// Division of two BigDecimals

bd1 = bd1.divide(bd2);

System.out.println("BigDecimal1 = " + bd1);

// BigDecima1 raised to the power of 2

bd1 = bd1.pow(2);

System.out.println("BigDecimal1 = " + bd1);

// Negate value of BigDecimal1

bd1 = bd1.negate();

System.out.println("BigDecimal1 = " + bd1);

}
24.Write a Java Program to implement inheritance and demonstrate use of method
overriding.
class Bank{

int getRateOfInterest(){return 0;}

//Creating child classes.

class SBI extends Bank{

int getRateOfInterest(){return 8;}

class ICICI extends Bank{

int getRateOfInterest(){return 7;}

class AXIS extends Bank{

int getRateOfInterest(){return 9;}

//Test class to create objects and call the methods

class Test2{

public static void main(String args[]){

SBI s=new SBI();

ICICI i=new ICICI();

AXIS a=new AXIS();

System.out.println("SBI Rate of Interest: "+s.getRateOfInterest());

System.out.println("ICICI Rate of Interest: "+i.getRateOfInterest());

System.out.println("AXIS Rate of Interest: "+a.getRateOfInterest());


}

25.Write a Java Program to implement multilevel inheritance by applying various


access controls to its data members and methods.
import java.io.DataInputStream;

class Student

private int rollno;

private String name;

DataInputStream dis=new DataInputStream(System.in);

public void getrollno()

try

System.out.println("Enter rollno ");

rollno=Integer.parseInt(dis.readLine());

System.out.println("Enter name ");

name=dis.readLine();

catch(Exception e){ }
}

void putrollno()

System.out.println("Roll No ="+rollno);

System.out.println("Name ="+name);

class Marks extends Student

protected int m1,m2,m3;

void getmarks()

try

System.out.println("Enter marks :");

m1=Integer.parseInt(dis.readLine());

m2=Integer.parseInt(dis.readLine());

m3=Integer.parseInt(dis.readLine());

catch(Exception e) { }

void putmarks()

System.out.println("m1="+m1);

System.out.println("m2="+m2);
System.out.println("m3="+m3);

class Result extends Marks

private float total;

void compute_display()

total=m1+m2+m3;

System.out.println("Total marks :" +total);

class MultilevelDemo

public static void main(String arg[])

Result r=new Result();

r.getrollno();

r.getmarks();

r.putrollno();

r.putmarks();

r.compute_display();
}

26.Write a Java program to practice using String class and its methods.

import java.lang.String;

public class StringMethods {

public static void main(String[] args) {

String str = "Softwaretestinghelp";


String str1 = "testing";
String str2 = "blog";
System.out.println("testing is a part of Softwaretestinghelp: " + str.contains(str1));
System.out.println("blog is a part of Softwaretestinghelp: " + str.contains(str2));

}
}

27.Write a Java program to practice using String Buffer class and its methods.
public class StringBufferInsert {
public static void main(String[] args) {
StringBuffer stringName = new StringBuffer(" Welcome");
System.out.println(stringName);
stringName.insert(8, " to ");
System.out.println(stringName);
stringName.insert(12, "TechVidvan ");
System.out.println(stringName);
stringName.insert(22, " Tutorial ");
System.out.println(stringName);
stringName.insert(31, " of ");
System.out.println(stringName);
stringName.insert(35, "Java");
System.out.println(stringName);
}
}

28.You are given a String at runtime. Capitalize all the characters at all odd
indexes in the string.

import java.util.*;
class A {

static String removeOddIndexCharacters(

String s)

// Stores the resultant string

String new_string = "";

for (int i = 0; i < s.length(); i++) {

// If the current index is odd

if (i % 2 == 1)

new_string += s.charAt(i).toUpperCase();

else

new_string += s.charAt(i);

// Return the modified string

return new_string;

// Driver Code
public static void main(String[] args)

String str = "abcdef";

// Remove the characters which

// have odd index

str = removeOddIndexCharacters(str);

System.out.print(str);

29.You are given a String at runtime. You are required to fetch the remaining
String after the occurrence of a certain sequence / character.
public class ABC

    // Method to print the string

    static void printString(String str, char ch, int count)

    {

        int occ = 0, i;

      

        // If given count is 0

        // print the given string and return

        if (count == 0) {

            System.out.println(str);
            return;

        }

      

        // Start traversing the string

        for (i = 0; i < str.length(); i++) {

      

            // Increment occ if current char is equal

            // to given character

            if (str.charAt(i) == ch)

                occ++;

      

            // Break the loop if given character has

            // been occurred given no. of times

            if (occ == count)

                break;

        }

      

        // Print the string after the occurrence

        // of given character given no. of times

        if (i < str.length() - 1)

            System.out.println(str.substring(i + 1));

      

        // Otherwise string is empty

        else

            System.out.println("Empty string");
    }

     

    // Driver Method

    public static void main(String[] args)

    {

        String str = "Sanjay is good professor";

        printString(str, 'e', 2);

    }

30.You are given a String at run time. Count the occurrence of a given word /
sequence in that String.

// Java program to count the number

// of occurrence of a word in

// the given string

import java.io.*;

class GFG {

static int countOccurrences(String str, String word)

// split the string by spaces in a


String a[] = str.split(" ");

// search for pattern in a

int count = 0;

for (int i = 0; i < a.length; i++)

// if match found increase count

if (word.equals(a[i]))

count++;

return count;

// Driver code

public static void main(String args[])

String str = "GeeksforGeeks A computer science portal for geeks ";

String word = "portal";

System.out.println(countOccurrences(str, word));

}
31.You are given a String at run-time. Delete all duplicate words from the String
(ignore the case) and return the modified String.

// Java program to remove duplicate character

// from character array and print in sorted

// order

import java.util.*;

class GFG {

static void removeDuplicate(char str[], int n)

// Create a set using String characters

// excluding '\0'

HashSet<Character> s = new LinkedHashSet<>(n - 1);

// HashSet doesn't allow repetition of elements

for (char x : str)

s.add(x);

// Print content of the set

for (char x : s)

System.out.print(x);
}

// Driver code

public static void main(String[] args)

char str[] = "geeksforgeeks".toCharArray();

int n = str.length;

removeDuplicate(str, n);

32.You are given a String at runtime. Find total vowels in the given String and also
display the count of each vowel in the String.

public class CountVowelConsonant {

public static void main(String[] args) {

//Counter variable to store the count of vowels and consonant

int vCount = 0, cCount = 0;

//Declare a string

String str = "This is a really simple sentence";


//Converting entire string to lower case to reduce the comparisons

str = str.toLowerCase();

for(int i = 0; i < str.length(); i++) {

//Checks whether a character is a vowel

if(str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i' ||


str.charAt(i) == 'o' || str.charAt(i) == 'u') {

//Increments the vowel counter

vCount++;

//Checks whether a character is a consonant

else if(str.charAt(i) >= 'a' && str.charAt(i)<='z') {

//Increments the consonant counter

cCount++;

System.out.println("Number of vowels: " + vCount);

System.out.println("Number of consonants: " + cCount);

34.Write a program to demonstrate various String/StringBuffer/StringBuilder


functions for: Reversing a string (check palindrome), conversion to
uppercase/lowercase, equality check of strings, inserting/deleting
characters/sequence at a particular index, searching a sequence/character in String
at a particular position in String. Fetching the index of a particular
characters/substring, Replacing the occurrence of a substring/character in a string,
comparing string lexicographically, splitting a string based on a given token, etc.

35..Write a Java Program to implement Wrapper classes and their methods.

class WrapperTest

public static void main (String args[])

Integer Obj1 = new Integer (44);

Integer Obj2 = new Integer ("44");

Integer Obj3 = new Integer (55);

//compareTo() method

System.out.println("Using compareTo() Obj1 and Obj2: " +


Obj1.compareTo(Obj2));

System.out.println("Using compareTo() Obj1 and Obj3: " +


Obj1.compareTo(Obj3));

//Equals() method

System.out.println("Using equals() Obj1 and Obj2: " +


Obj1.equals(Obj2));

System.out.println("Using equals() Obj1 and Obj3: " +


Obj1.equals(Obj3));

Float f1 = new Float("10.25f");

Float f2 = new Float("12.63f");

Float f3 = new Float(10.25f);


System.out.println("Using compare() f1 and f2: " +Float.compare(f1,f2));

System.out.println("Using compare() f1 and f3: " +Float.compare(f1,f3));

//Addition of Integer with Float

Float f = Obj1.floatValue() + f1;

System.out.println("Addition of intObj1 and f1: "+ Obj1 +"+" +f1+"="


+f );

Integer int1 = Integer.valueOf("12345");

//Converting from binary to decimal

Integer int2 = Integer.valueOf("101011", 2);

//Converting from hexadecimal to decimal

Integer int3 = Integer.valueOf("D", 16);

System.out.println("Value of int1 Object: "+ int1);

System.out.println("Value of int2 Object: "+ int2);

System.out.println("Value of int3 Object: "+ int3);

System.out.println("Hex value of int1: " + Integer.toHexString(int1));

System.out.println("Binary Value of int2: "+


Integer.toBinaryString(int2));

36.Write a java program to find the details of the students eligible to enroll for the
examination ( Students, Department combinedly give the eligibility criteria for the
enrollement class) using interfaces
import java.lang.*;
import java.util.*;
class Student
{
int studentId;
Scanner s=new Scanner(System.in);
String studentName,Class;
int getStudentId()
{
return studen
tId;
}
String getStudentName()
{
return studentName;
}
String getStudentClass()
{
return Class;
}
}
interface Department
{
int studentId1=0;
int attendance1=0;
double getAttendence();
}
class Exam extends Student implements Department
{
double attendLecture,totalLecture;
int studentId= studentId1;
double attendance = attendance1;
public double getAttendence()
{
return this.attendance;
}
boolean eligible()
//function to check student eligibility
{
if(this.attendance>75)
{
return true;
}
else
return false;}
void calculateAttendence()
{this.attendance=(this.attend
Lecture/this.totalLecture)*100;
}
void setValue()
//function to set info of students
{
System.out.println("Enter Student Id :");
super.studentI
d=s.nextInt();
s.nextLine();
System.out.println("Enter Student Name :");
super.studentName=s.nextLine();
System.out.println("Enter Student Class :");
super.Class=s.nextLine();
System.out.println("Enter attendLecture");
this.attendLecture=s.ne
xtInt();
System.out.println("Enter totalLecture");
this.totalLecture=s.nextInt();
}
}
class ex21
{
public static void main(String []args)
System.out.println("Name:
Mann
Patel");
System.out.println("ID:
18dcs074
");
Exam E=new Exam();
E.setValue();
E.calculateAttendence();
System.out.println("Student Id : "+E.getStudentId());
System.out.println("Student Name : "+E.getStudentName());
System.out.println("Student Class : "+E.getStudentClass());
System.out.println("Student a
ttendance : "+E.getAttendence());
System.out.println("You are eligible or not for Exam :
"+E.eligible());
}
}
.

37.Write a program to demonstrate use of implementing interfaces.


import java.util.Scanner;

interface area

public void dimensions();

public void area();

public class Interface_Implementation implements area

int length,breadth,area;

public void dimensions()

Scanner s=new Scanner(System.in);

System.out.print("Enter length:");

length=s.nextInt();

System.out.print("Enter breadth:");

breadth=s.nextInt();

public void area()

area=length*breadth;

System.out.print("Area:"+area);

}
public static void main(String[] args)

Interface_Implementation obj=new Interface_Implementation();

obj.dimensions();

obj.area();

38.Write a java program to create an abstract class named Shape that contains two
integers and an empty method named printArea(). Provide three classes named
Rectangle, Triangle and Circle such that each one of the classes extends the class
Shape. Each one of the classes contain only the method printArea( ) that prints the
area of the given shape.

import java.util.*;

import java.util.Scanner;

abstract class shape //abstract class

abstract void PrintArea();

abstract void getValue();

int length;

int width;

class Rectangle extends shape

void getValue()
{

Scanner s=new Scanner(System.in);

length=s.nextInt();

width=s.nextInt();

void PrintArea() //area of rectangle

System.out.println("Area Of Rectangle: "+(length*width));

class Triangle extends shape

void getValue()

Scanner s=new Scanner(System.in);

length=s.nextInt();

width=s.nextInt();

void PrintArea() //area of trinagle

{ System.out.println("Area Of Triangle: "+(0.5*length*width)); }}

class Circle extends shape

{ void getValue()

{ Scanner s=new Scanner(System.in);


length=s.nextInt();

width=s.nextInt();}

void PrintArea()

{ System.out.println("Area Of Circle: "+(Math.PI*length*length)); }}

class ex19

{ public static void main(String args[])

{ System.out.println("Name:Mann Patel");

System.out.println("ID:18dcs074");

Rectangle r=new Rectangle();

Triangle t=new Triangle();

Circle c=new Circle();

r.getValue();

r.PrintArea();

t.getValue();

t.PrintArea();

c.getValue();

c.PrintArea();}}

39.WAP for class TV with attributes name of company , Screen Size using
keyword inheritance . Create a colour TV class & B&W TV class.

40.WAP to demonstrate the use of overriding hashCode(), equals() & toString()


methods of Object class(The cosmic superclass).

// Java program to illustrate

// overriding of equals and


// hashcode methods

import java.io.*;

import java.util.*;

class Cosmic

String name;

int id;

Geek(String name, int id)

this.name = name;

this.id = id;

@Override

public boolean equals(Object obj)

// if both the object references are

// referring to the same object.


if(this == obj)

return true;

// it checks if the argument is of the

// type Geek by comparing the classes

// of the passed argument and this object.

// if(!(obj instanceof Geek)) return false; ---> avoid.

if(obj == null || obj.getClass()!= this.getClass())

return false;

// type casting of the argument.

Geek geek = (Geek) obj;

// comparing the state of argument with

// the state of 'this' Object.

return (geek.name.equals(this.name) && geek.id == this.id);

@Override

public int hashCode()

// We are returning the Geek_id


// as a hashcode value.

// we can also return some

// other calculated value or may

// be memory address of the

// Object on which it is invoked.

// it depends on how you implement

// hashCode() method.

return this.id;

// Driver code

class ABH

public static void main (String[] args)

// creating two Objects with

// same state

Cosmic g1 = new Cosmic("aditya", 1);

Cosmic g2 = new Cosmic("aditya", 1);


Map<Geek, String> map = new HashMap<Geek, String>();

map.put(g1, "CSE");

map.put(g2, "IT");

for(Geek geek : map.keySet())

System.out.println(map.get(geek).toString());

41.Write a Java program to implement the concept of importing classes from user
defined package and creating packages.

42.WAP to multiply two given matrices

public class MatrixMultiplicationExample{

public static void main(String args[]){

//creating two matrices

int a[][]={{1,1,1},{2,2,2},{3,3,3}};

int b[][]={{1,1,1},{2,2,2},{3,3,3}};

//creating another matrix to store the multiplication of two matrices

int c[][]=new int[3][3]; //3 rows and 3 columns


//multiplying and printing multiplication of 2 matrices

for(int i=0;i<3;i++){

for(int j=0;j<3;j++){

c[i][j]=0;

for(int k=0;k<3;k++)

c[i][j]+=a[i][k]*b[k][j];

}//end of k loop

System.out.print(c[i][j]+" "); //printing matrix element

}//end of j loop

System.out.println();//new line

}}

43.Write a Java Program to implement array of objects.

public class ArrayOfObjects

public static void main(String args[])

//create an array of product object

Product[] obj = new Product[5] ;

//create & initialize actual product objects using constructor

obj[0] = new Product(23907,"Dell Laptop");


obj[1] = new Product(91240,"HP 630");

obj[2] = new Product(29823,"LG OLED TV");

obj[3] = new Product(11908,"MI Note Pro Max 9");

obj[4] = new Product(43590,"Kingston USB");

//display the product object data

System.out.println("Product Object 1:");

obj[0].display();

System.out.println("Product Object 2:");

obj[1].display();

System.out.println("Product Object 3:");

obj[2].display();

System.out.println("Product Object 4:");

obj[3].display();

System.out.println("Product Object 5:");

obj[4].display();

//Product class with product Id and product name as attributes

class Product

int pro_Id;

String pro_name;

//Product class constructor


Product(int pid, String n)

pro_Id = pid;

pro_name = n;

public void display()

System.out.print("Product Id = "+pro_Id + " " + " Product Name = "+pro_name);

System.out.println();

45.Write a Java Program to implement Vector class and its methods

import java.util.*;

public class Main{

public static void main(String[] args)

// create default vector

Vector v1 = new Vector();

// create a vector of given Size

Vector v2 = new Vector(20);

// create a vector of given Size and Increment

Vector v3 = new Vector(30,10);

v2.add(100);
v2.add(100);

v2.add(100);

// create a vector with given collection

Vector v4 = new Vector(v2);

System.out.println("The element at index 1 is " + v1.get(1));

System.out.println("The last element is " + v1.lastElement());

System.out.println("Vector v1 of capacity " + v1.capacity());

System.out.println("Vector v2 of capacity " + v2.capacity());

System.out.println("Vector v3 of capacity " + v3.capacity());

System.out.println("Vector v4 of capacity " + v4.capacity());

46.Write a program to implement the concept of threading by extending Thread


Class

public class MyThread2 implements Runnable

public void run()

System.out.println("Now the thread is running ...");

// main method

public static void main(String argvs[])

{
// creating an object of the class MyThread2

Runnable r1 = new MyThread2();

// creating an object of the class Thread using Thread(Runnable r, String name)

Thread th1 = new Thread(r1, "My new thread");

// the start() method moves the thread to the active state

th1.start();

// getting the thread name by invoking the getName() method

String str = th1.getName();

System.out.println(str);

47.Write a program to implement the concept of threading by implementing


Runnable Interface

public class MyThread1

// Main method

public static void main(String argvs[])

// creating an object of the Thread class using the constructor Thread(String name)

Thread t= new Thread("My first thread");


// the start() method moves the thread to the active state

t.start();

// getting the thread name by invoking the getName() method

String str = t.getName();

System.out.println(str);

48.Write a java program that implements a multi-thread application that has three
threads. First thread generates random integer every 1 second and if the value is
even, second thread computes the square of the number and prints. If the value is
odd, the third thread will print the value of cube of the number.

import java.util.Random;

class RandomNumberThread extends Thread {

public void run() {

Random random = new Random();

for (int i = 0; i < 10; i++) {

int randomInteger = random.nextInt(100);

System.out.println("Random Integer generated : " +


randomInteger);

if((randomInteger%2) == 0) {

SquareThread sThread = new


SquareThread(randomInteger);

sThread.start();
}

else {

CubeThread cThread = new


CubeThread(randomInteger);

cThread.start();

try {

Thread.sleep(1000);

catch (InterruptedException ex) {

System.out.println(ex);

class SquareThread extends Thread {

int number;

SquareThread(int randomNumbern) {

number = randomNumbern;

}
public void run() {

System.out.println("Square of " + number + " = " + (number *


number));

class CubeThread extends Thread {

int number;

CubeThread(int randomNumber) {

number = randomNumber;

public void run() {

System.out.println("Cube of " + number + " = " + number * number *


number);

public class MultiThreadingTest {

public static void main(String args[]) {

RandomNumberThread rnThread = new RandomNumberThread();

rnThread.start();
}

49.WAP to create a class MyThread implementing the Runnable interface . The


constructor of this class takes an int as argument which has only three values 1,2,or
3. Based on the value of this integer the run() method will perform different
functions. If the value passed to constructor is 1, the thread will print even no.
series up to 100.If the value passed to constructor is 2, the thread print the odd no.
series, If the value passed to constructor is 3 the thread shall print the multiples of
3 up to 50.

50.Program to show Synchronization between Threads.

class Table{

void printTable(int n){//method not synchronized

for(int i=1;i<=5;i++){

System.out.println(n*i);

try{

Thread.sleep(400);

}catch(Exception e){System.out.println(e);}

class MyThread1 extends Thread{

Table t;
MyThread1(Table t){

this.t=t;

public void run(){

t.printTable(5);

class MyThread2 extends Thread{

Table t;

MyThread2(Table t){

this.t=t;

public void run(){

t.printTable(100);

class TestSynchronization1{

public static void main(String args[]){

Table obj = new Table();//only one object

MyThread1 t1=new MyThread1(obj);

MyThread2 t2=new MyThread2(obj);


t1.start();

t2.start();

51.Create an ArrayList of objects(say Student/Employee objects) ,store


information about the objects at run time and store these objects in the ArrayList.

package customArrayList;

public class Student

// Create instance variables name, id, and rollNo of data type String, int, and int
respectively.

String name;

int id;

int rollNo;

// Create three parameters constructor with parameters name, id, and rollNo.

Student(String name, int id, int rollNo)

this.name = name;

this.rollNo = rollNo;

this.id = id;

}
package customArrayList;

import java.util.ArrayList;

public class AddingData

// Create a ArrayList method of generic type 'Student'.

ArrayList<Student> studentData()

// Create three objects of the class Student and pass arguments to the constructor.

Student s1 = new Student("Deep", 1234, 04);

Student s2 = new Student("Shubh", 4321, 20 );

Student s3 = new Student("Riddhi", 1212, 02);

// Create the object of ArrayList of generic type 'Student'.

ArrayList<Student> studentlist = new ArrayList<Student>();

// Now add Student objects in the ArrayList using reference variable studentlist.

studentlist.add(s1);

studentlist.add(s2);

studentlist.add(s3);

// Return object reference variable 'studentlist' of the array list to the method
'studentValue'.

return studentlist;
}

52.Write program for implementation of ArrayList, LinkedList , HashMap , Set


using appropriate interfaces of your own choice ?

import java.util.ArrayList;

import java.util.Iterator;

import java.util.List;

public class ArrayListMethodsEx {

public static void main(String[] args) {

List<String> names = new ArrayList<String>();

names.add("Jane");

names.add("Thomas");

names.add("Robin");

names.add("David");

names.add("Becky");

System.out.println(names);

names.set(1, "Tom");

System.out.println(names);
System.out.format("There are %d elements in the collection%n",

names.size());

names.remove(1);

System.out.format("There are %d elements in the collection%n",

names.size());

System.out.println(names.get(3));

System.out.println("************");

Iterator<String> it = names.iterator();

while (it.hasNext()) {

System.out.println(it.next());

LinkedList<Integer> nums = new LinkedList<>();

nums.add(5);

nums.add(10);

nums.add(13);

nums.add(12);
nums.add(15);

nums.add(23);

System.out.println(nums);

nums.removeFirst();

nums.removeLast();

nums.addFirst(17);

nums.addLast(77);

System.out.println(nums);

Map<String, String> domains = new HashMap<>();

domains.put("de", "Germany");

domains.put("sk", "Slovakia");

domains.put("us", "United States");

domains.put("ru", "Russia");

domains.put("hu", "Hungary");

domains.put("pl", "Poland");

System.out.println(domains.get("pl"));

for (String item : domains.values()) {


System.out.println(item);

Set keys = domains.keySet();

System.out.println(keys);

53.Write a program to implement the concept of Exception Handling using


predefined exception.

class Main {

public static void main(String[] args) {

try {

// code that generates exception

int divideByZero = 5 / 0;

catch (ArithmeticException e) {

System.out.println("ArithmeticException => " + e.getMessage());

finally {
System.out.println("This is the finally block");

Same as above

54.Write a program to implement the concept of Exception Handling by creating


user defined exceptions

class MyException extends Exception{


String str1;

MyException(String str2) {
str1=str2;
}
public String toString(){
return ("MyException Occurred: "+str1) ;
}
}

class Example1{
public static void main(String args[]){
try{
System.out.println("Starting of try block");
// I'm throwing the custom exception using throw
throw new MyException("This is My error Message");
}
catch(MyException exp){
System.out.println("Catch Block") ;
System.out.println(exp) ;
}
}
}
55.Write a program using Applet For configuring Applets by passing
parameters.

import java.applet.*;

import java.awt.Graphics;

/* <applet code="AppletParamDemo.class" width=300 height=100>

<param name=place value="Gulbarga"> <param name=college value="Govt


Polytechnic">

</applet> */

public class AppletParamDemo extends Applet

String p,c;

public void init()

p=getParameter("place");

c=getParameter("college");

public void paint(Graphics g)

g.drawString(c,80,20);

g.drawString(p,100,40);

56.Write a Java Program to demonstrate Keyboard event


import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

class Keyboard_Event implements KeyListener,ActionListener

static JFrame frame;

static JTextField output;

static JTextField input;

//Driver function

public static void main(String args[])

//Create a frame

frame=new JFrame("Keyboard Event");

frame.setBackground(Color.white);

frame.setSize(500,500);

frame.setLayout(null);

//Create a text field for output

output=new JTextField();

output.setBounds(0,0,500,50);

frame.add(output);

//Create a text field for input

input=new JTextField();

input.setBounds(0,400,500,50);
frame.add(input);

//Create an exit button

JButton exit=new JButton("Exit");

exit.setBounds(220,200,60,30);

frame.add(exit);

//Create an object of the class

Keyboard_Event obj=new Keyboard_Event();

//Associate KeyListener with input

input.addKeyListener(obj);

//Associate ActionListener with exit

exit.addActionListener(obj);

frame.setVisible(true);

//function to dispose the frame when exit button is clicked

@Override

public void actionPerformed(ActionEvent e)

frame.dispose();

/*function to display the unicode of key released

and the character if it is a letter or a digit*/

@Override

public void keyReleased(KeyEvent e)


{

output.setText("");

output.setText("Key Released : "+e.getKeyCode());

if(Character.isLetter(e.getKeyChar()))

keyTyped(e);

if(Character.isDigit(e.getKeyChar()))

keyTyped(e);

/*function to display the unicode of key pressed

and the character if it is a letter or a digit*/

@Override

public void keyPressed(KeyEvent e)

output.setText("");

output.setText("Key Pressed : "+e.getKeyCode());

if(Character.isLetter(e.getKeyChar()))

keyTyped(e);

if(Character.isDigit(e.getKeyChar()))

keyTyped(e);

//function to display the character of the key typed

@Override

public void keyTyped(KeyEvent e)


{

output.setText("");

output.setText("Key Typed : "+e.getKeyChar());

57.Write a Java Program to demonstrate Mouse events

import java.awt.*;

import java.awt.event.*;

public class MouseListenerExample extends Frame implements MouseListener{

Label l;

MouseListenerExample(){

addMouseListener(this);

l=new Label();

l.setBounds(20,50,100,20);

add(l);

setSize(300,300);

setLayout(null);

setVisible(true);

public void mouseClicked(MouseEvent e) {

l.setText("Mouse Clicked");

}
public void mouseEntered(MouseEvent e) {

l.setText("Mouse Entered");

public void mouseExited(MouseEvent e) {

l.setText("Mouse Exited");

public void mousePressed(MouseEvent e) {

l.setText("Mouse Pressed");

public void mouseReleased(MouseEvent e) {

l.setText("Mouse Released");

public static void main(String[] args) {

new MouseListenerExample();

58.Write programs for using Graphics class - to display basic shapes and fill them -
draw different items using basic shapes - set background and foreground color.

import java.applet.*;

import java.awt.*;

/* <applet code=”Shapes.class” width=800 height-800> </applet>*/


public class Shapes extends Applet

public void paint(Graphics g)

setForefround(Color.red);

setBackGround(Color.blue);

//drawing squares

g.drawLine(10,10,100,10);

g.drawLine(10,10,10,10);

g.drawLine(10,100,100,100);

g.drawLine(100,100,100,10);

// Drawing triangle

g.drawLine(10,120,100,120);

g.drawLine(10,120,50,200);

g.drawLine(50,200,100,120);

//drawing Rectangle

g.drawRect(120,10,220,120);

g.fillRect(120,120,220,120);

//drawing ellipse and circle

g.drawOval(10,220,100,220);

g.setColor(Cplor.yellow);

g.fillOval(120,250,250,250);

//draw a filled arc


g.fillArc(350,50,400,100,0,90);

//draw a polygon

int x[]={400,500,400,500);

int y[]={240,240,340,340};

g.drawPolygon(x,y,4);

59.Write a Java program that works as a simple calculator. Use a grid layout to
arrange buttons for the digits and for the +, -,*, % operations. Add a text field to
display the result. Handle any possible exceptions like divide by zero.

import java.awt.*;

import java.awt.event.*;

import java.applet.*;

public class Calculator extends Applet

implements ActionListener

String msg=" ";

int p,q,result;

TextField t1;

Button b[]=new Button[10];

Button add,sub,mul,div,clear,mod,EQ;

char OP;

public void init()


{

t1=new TextField(10);

GridLayout gl=new GridLayout(4,5);

setLayout(gl);

for(int i=0;i<10;i++)

b[i]=new Button(""+i);

add=new Button("add");

sub=new Button("sub");

mul=new Button("mul");

div=new Button("div");

mod=new Button("mod");

clear=new Button("clear");

EQ=new Button("EQ");

t1.addActionListener(this);

add(t1);

for(int i=0;i<10;i++)

add(b[i]);

add(add);

add(sub);
add(mul);

14

add(div);

add(mod);

add(clear);

add(EQ);

for

(int i=0;i<10;i++)

b[i].addActionListener(this);

add.addActionListener(this);

sub.addActionListener(this);

mul.addActionListener(this);

div.addActionListener(this);

mod.addActionListener(this);

clear.addActionListener(this);

EQ.addActionListener(this);

public void actionPerformed(ActionEvent ae) {

String str=ae.getActionCommand();

char ch=str.charAt(0);

if ( Character.isDigit(ch))
t1.setText(t1.getText()+str);

else

if(str.equals("add")) {

p=Integer.parseInt(t1.getText());

OP='+';

t1.setText("");

else if(str.equals("sub")) {

p=Integer.parseInt(t1.getText());

OP='

-';

t1.setText("");

else if(str.equals("mul")) {

p=Integer.parseInt(t1.getText());

OP='*';

t1.setText("");

else if(str.equals("div")) {

p=Integer.parseInt(t1.getText());

OP='/';

15

t1.setText("");
}

else if(str.equals("mod")) {

p=Integer.parseInt(t1.getText());

OP='%';

t1.setText("");

if(str.equals("EQ")) {

q=Integer.parseInt(t1.getText());

if(OP=='+')

result=p+q;

else if(OP=='

-')

result=p

-q;

else if(OP=='*')

result=p*q;

else if(OP=='/')

result=p/q;

else if(OP=='%')

result=p%q;

t1.setText(""+result);

if(str.equals("clear")) {
t1.setText("");

60. Develop an Applet that receives an integer in one text field & compute its
factorial value & returns it in another text filed when the button “Compute” is
clicked.
import java.awt.*;

import java.awt.event.*;

public class factorial extends java.applet.Applet implements ActionListener

TextField t1,t2;

Label l1,l2,l3;

Button b1;

int fact=1,n,i;

factorial e;

public void init()

e=this;

t1=new TextField(10);

t2=new TextField(10);

l1=new Label("factorial of a number");

l2=new Label("enter number");

l3=new Label("result");

b1=new Button("compute");
add(l1);add(l2);add(l3);add(t1);add(t2);add(b1);

b1.addActionListener(this);

public void actionPerformed(ActionEvent ae)

String str=t1.getText();

n=Integer.parseInt(str);

for(i=n;i>1;i--)

fact=fact*i;

String msg=""+fact;

t2.setText(msg);

fact=1;

61.Write a Java program that handles all mouse events and shows the event name
at the center of the window when a mouse event is fired. (Use adapter classes).

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

/*<applet code="MouseDemo" width=300 height=300>

</applet>*/

public class MouseDemo extends Applet implements


MouseListener,MouseMotionListener
{

int mx=0;

int my=0;

String msg="";

public void init()

addMouseListener(this);

addMouseMotionListener(this);

public void mouseClicked(MouseEvent me)

mx=20;

my=40;

msg="Mouse Clicked";

repaint();

public void mousePressed(MouseEvent me)

mx=30;

my=60;

msg="Mouse Pressed";

repaint();
}

public void mouseReleased(MouseEvent me)

mx=30;

my=60;

msg="Mouse Released";

repaint();

public void mouseEntered(MouseEvent me)

mx=40;

my=80;

msg="Mouse Entered";

repaint();

public void mouseExited(MouseEvent me)

mx=40;

my=80;

msg="Mouse Exited";

repaint();

public void mouseDragged(MouseEvent me)


{

mx=me.getX();

my=me.getY();

showStatus("Currently mouse dragged"+mx+" "+my);

repaint(); }

public void mouseMoved(MouseEvent me)

mx=me.getX();

my=me.getY();

showStatus("Currently mouse is at"+mx+" "+my);

repaint();

public void paint(Graphics g)

g.drawString("Handling Mouse Events",30,20);

g.drawString(msg,60,40);

62.WAP in AWT to demonstrate frame, checkbox, menu of your own choice.

/*

<applet code="Subjects" width=300 height=300></applet>

*/
import java.applet.*;

import java.awt.*;

import java.awt.event.*;

public class Subjects extends Applet

public void init()

List l1=new List(10);

l1.setBounds(50,60,100,120);

l1.add("DSU");

l1.add("PIC");

l1.add("OOP");

l1.add("CGR");

l1.add("DTE");

l1.add("Microprocessor");

l1.add("CN");

l1.add("DBMS");

l1.add("SEN");

l1.add("JAVA");

add(l1);

setLayout(null);

}
public void paint(Graphics g)

repaint();

63.Write a Program for JTable.

import javax.swing.*;

public class TableExample {

JFrame f;

TableExample(){

f=new JFrame();

String data[][]={ {"101","Amit","670000"},

{"102","Jai","780000"},

{"101","Sachin","700000"}};

String column[]={"ID","NAME","SALARY"};

JTable jt=new JTable(data,column);

jt.setBounds(30,40,200,300);

JScrollPane sp=new JScrollPane(jt);

f.add(sp);

f.setSize(300,400);

f.setVisible(true);
}

public static void main(String[] args) {

new TableExample();

64.Write a Swing Program to show Magic Square Table.

65.Write a Program for Calculator using Swing.

import java.awt.event.*;

import javax.swing.*;

import java.awt.*;

class calculator extends JFrame implements ActionListener {

// create a frame

static JFrame f;

// create a textfield

static JTextField l;

// store operator and operands

String s0, s1, s2;

// default constructor

calculator()

{
s0 = s1 = s2 = "";

// main function

public static void main(String args[])

// create a frame

f = new JFrame("calculator");

try {

// set look and feel

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassNa
me());

catch (Exception e) {

System.err.println(e.getMessage());

// create a object of class

calculator c = new calculator();

// create a textfield

l = new JTextField(16);
// set the textfield to non editable

l.setEditable(false);

// create number buttons and some operators

JButton b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, ba, bs, bd, bm, be, beq, beq1;

// create number buttons

b0 = new JButton("0");

b1 = new JButton("1");

b2 = new JButton("2");

b3 = new JButton("3");

b4 = new JButton("4");

b5 = new JButton("5");

b6 = new JButton("6");

b7 = new JButton("7");

b8 = new JButton("8");

b9 = new JButton("9");

// equals button

beq1 = new JButton("=");

// create operator buttons

ba = new JButton("+");
bs = new JButton("-");

bd = new JButton("/");

bm = new JButton("*");

beq = new JButton("C");

// create . button

be = new JButton(".");

// create a panel

JPanel p = new JPanel();

// add action listeners

bm.addActionListener(c);

bd.addActionListener(c);

bs.addActionListener(c);

ba.addActionListener(c);

b9.addActionListener(c);

b8.addActionListener(c);

b7.addActionListener(c);

b6.addActionListener(c);

b5.addActionListener(c);

b4.addActionListener(c);

b3.addActionListener(c);
b2.addActionListener(c);

b1.addActionListener(c);

b0.addActionListener(c);

be.addActionListener(c);

beq.addActionListener(c);

beq1.addActionListener(c);

// add elements to panel

p.add(l);

p.add(ba);

p.add(b1);

p.add(b2);

p.add(b3);

p.add(bs);

p.add(b4);

p.add(b5);

p.add(b6);

p.add(bm);

p.add(b7);

p.add(b8);

p.add(b9);

p.add(bd);

p.add(be);
p.add(b0);

p.add(beq);

p.add(beq1);

// set Background of panel

p.setBackground(Color.blue);

// add panel to frame

f.add(p);

f.setSize(200, 220);

f.show();

public void actionPerformed(ActionEvent e)

String s = e.getActionCommand();

// if the value is a number

if ((s.charAt(0) >= '0' && s.charAt(0) <= '9') || s.charAt(0) == '.') {

// if operand is present then add to second no

if (!s1.equals(""))

s2 = s2 + s;

else
s0 = s0 + s;

// set the value of text

l.setText(s0 + s1 + s2);

else if (s.charAt(0) == 'C') {

// clear the one letter

s0 = s1 = s2 = "";

// set the value of text

l.setText(s0 + s1 + s2);

else if (s.charAt(0) == '=') {

double te;

// store the value in 1st

if (s1.equals("+"))

te = (Double.parseDouble(s0) + Double.parseDouble(s2));

else if (s1.equals("-"))

te = (Double.parseDouble(s0) - Double.parseDouble(s2));

else if (s1.equals("/"))

te = (Double.parseDouble(s0) / Double.parseDouble(s2));
else

te = (Double.parseDouble(s0) * Double.parseDouble(s2));

// set the value of text

l.setText(s0 + s1 + s2 + "=" + te);

// convert it to string

s0 = Double.toString(te);

s1 = s2 = "";

else {

// if there was no operand

if (s1.equals("") || s2.equals(""))

s1 = s;

// else evaluate

else {

double te;

// store the value in 1st

if (s1.equals("+"))

te = (Double.parseDouble(s0) + Double.parseDouble(s2));

else if (s1.equals("-"))
te = (Double.parseDouble(s0) - Double.parseDouble(s2));

else if (s1.equals("/"))

te = (Double.parseDouble(s0) / Double.parseDouble(s2));

else

te = (Double.parseDouble(s0) * Double.parseDouble(s2));

// convert it to string

s0 = Double.toString(te);

// place the operator

s1 = s;

// make the operand blank

s2 = "";

// set the value of text

l.setText(s0 + s1 + s2);

66.Write a java program to design the page authenticating user name and password
by using SWING.
//import required classes and packages

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.lang.Exception;

//create CreateLoginForm class to create login form

//class extends JFrame to create a window where our component add

//class implements ActionListener to perform an action on button click

class CreateLoginForm extends JFrame implements ActionListener

//initialize button, panel, label, and text field

JButton b1;

JPanel newPanel;

JLabel userLabel, passLabel;

final JTextField textField1, textField2;

//calling constructor

CreateLoginForm()

//create label for username

userLabel = new JLabel();


userLabel.setText("Username"); //set label value for textField1

//create text field to get username from the user

textField1 = new JTextField(15); //set length of the text

//create label for password

passLabel = new JLabel();

passLabel.setText("Password"); //set label value for textField2

//create text field to get password from the user

textField2 = new JPasswordField(15); //set length for the password

//create submit button

b1 = new JButton("SUBMIT"); //set label to button

//create panel to put form elements

newPanel = new JPanel(new GridLayout(3, 1));

newPanel.add(userLabel); //set username label to panel

newPanel.add(textField1); //set text field to panel

newPanel.add(passLabel); //set password label to panel

newPanel.add(textField2); //set text field to panel

newPanel.add(b1); //set button to panel


//set border to panel

add(newPanel, BorderLayout.CENTER);

//perform action on button click

b1.addActionListener(this); //add action listener to button

setTitle("LOGIN FORM"); //set title to the login form

//define abstract method actionPerformed() which will be called on button click

public void actionPerformed(ActionEvent ae) //pass action listener as a


parameter

String userValue = textField1.getText(); //get user entered username from


the textField1

String passValue = textField2.getText(); //get user entered pasword from


the textField2

//check whether the credentials are authentic or not

if (userValue.equals("test1@gmail.com") && passValue.equals("test")) { //if


authentic, navigate user to a new page

//create instance of the NewPage

NewPage page = new NewPage();

//make page visible to the user


page.setVisible(true);

//create a welcome label and set it to the new page

JLabel wel_label = new JLabel("Welcome: "+userValue);

page.getContentPane().add(wel_label);

else{

//show error message

System.out.println("Please enter valid username and password");

//create the main class

class LoginFormDemo

//main() method start

public static void main(String arg[])

try

//create instance of the CreateLoginForm

CreateLoginForm form = new CreateLoginForm();

form.setSize(300,100); //set size of the frame


form.setVisible(true); //make form visible to the user

catch(Exception e)

//handle exception

JOptionPane.showMessageDialog(null, e.getMessage());

NewPage.java

//import required classes and packages

import javax.swing.*;

import java.awt.*;

//create NewPage class to create a new page on which user will navigate

class NewPage extends JFrame

//constructor

NewPage()

setDefaultCloseOperation(javax.swing.

WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Welcome");

setSize(400, 200);

67. Write a java program to design a calculator by using Grid Layout.

//import package to create simple calculator

import java.util.*;

import java.awt.*;

import java.awt.event.*;

import java.io.*;

class Week9 extends Frame implements ActionListener

int i=0,temp=0;

char a;

float stk[];

int top;

TextField t;

Button dot,mod,b,one,two,three,four,five,six,seven,eight,nine,

zero,add,sub,mul,div,eq,sine,sqrt,cbrt;

GridBagConstraints gc;

Week9()

super("My Calculator");
stk=new float[20];

top=-1;

gc=new GridBagConstraints(); //creating gridlayout

//creating textfield and button on simple calculator

t=new TextField("");

b=new Button("Reset");

one=new Button(" 1 ");

two=new Button(" 2 ");

three=new Button(" 3 ");

four=new Button(" 4 ");

five=new Button(" 5 ");

six=new Button(" 6 ");

seven=new Button(" 7 ");

eight=new Button(" 8 ");

nine=new Button(" 9 ");

zero=new Button(" 0 ");

add=new Button(" + ");

sub=new Button(" - ");

mul=new Button(" * ");

div=new Button(" / ");

eq=new Button(" = ");

dot=new Button("...");

mod=new Button(" % ");


sine=new Button(" sin ");

sqrt=new Button(" sqrt ");

cbrt=new Button(" cbrt ");

setSize(250,250);

setLocation(500,200);

setLayout(new GridBagLayout());

addcomp(one,1,1,1,1);

addcomp(two,1,2,1,1);

addcomp(three,1,3,1,1);

addcomp(four,1,4,1,1);

addcomp(five,2,1,1,1);

addcomp(six,2,2,1,1);

addcomp(seven,2,3,1,1);

addcomp(eight,2,4,1,1);

addcomp(nine,3,1,1,1);

addcomp(zero,3,2,1,1);

addcomp(mul,3,3,1,1);

addcomp(div,3,4,1,1);

addcomp(add,4,1,1,1);

addcomp(sub,4,2,1,1);

addcomp(eq,4,3,1,1);

addcomp(mod,4,4,1,1);

addcomp(dot,5,1,1,1);
addcomp(sine,5,2,1,1);

addcomp(sqrt,5,3,1,1);

addcomp(cbrt,5,4,1,1);

addcomp(new Label(""),7,1,4,1);

addcomp(t,8,1,4,1);

addcomp(new Label(""),9,1,4,1);

addcomp(b,10,2,2,1);

setVisible(true);

one.addActionListener(this);

two.addActionListener(this);

three.addActionListener(this);

four.addActionListener(this);

five.addActionListener(this);

six.addActionListener(this);

seven.addActionListener(this);

eight.addActionListener(this);

nine.addActionListener(this);

zero.addActionListener(this);

mul.addActionListener(this);

div.addActionListener(this);

add.addActionListener(this);

sub.addActionListener(this);

eq.addActionListener(this);
mod.addActionListener(this);

dot.addActionListener(this);

sine.addActionListener(this);

sqrt.addActionListener(this);

cbrt.addActionListener(this);

b.addActionListener(this);

public void addcomp(Component cc,int r,int c,int w,int h)

gc.gridx=c;

gc.gridy=r;

gc.gridwidth=w;

gc.gridheight=h;

gc.fill=gc.BOTH;

add(cc,gc);

// performing action on simple calculator

public void actionPerformed(ActionEvent ae)

{ // comparing input value in simple calculator

if(ae.getSource()==b)

t.setText("");

}
if(ae.getSource()==one)

if(temp==1)

func();

t.setText(t.getText()+"1");

if(ae.getSource()==two)

if(temp==1)

func();

t.setText(t.getText()+"2");

if(ae.getSource()==three)

if(temp==1)

func();

t.setText(t.getText()+"3");

if(ae.getSource()==four)

if(temp==1)

func();

t.setText(t.getText()+"4");
}

if(ae.getSource()==five)

if(temp==1)

func();

t.setText(t.getText()+"5");

if(ae.getSource()==six)

if(temp==1)

func();

t.setText(t.getText()+"6");

if(ae.getSource()==seven)

if(temp==1)

func();

t.setText(t.getText()+"7");

if(ae.getSource()==eight)

if(temp==1)

func();
t.setText(t.getText()+"8");

if(ae.getSource()==nine)

t.setText(t.getText()+"9");

if(temp==1)

func();

if(ae.getSource()==zero)

t.setText(t.getText()+"0");

if(temp==1)

func();

if(ae.getSource()==add||ae.getSource()==sub||ae.getSource()==mul||

ae.getSource()==div||ae.getSource()==mod||ae.getSource()==sqrt||

ae.getSource()==cbrt||ae.getSource()==sine)

String s;

s=t.getText();

float num1=0,num2=0,num3=0;

float n=Float.parseFloat(s);

push(n);
if(ae.getSource()==add)

a='+';

if(ae.getSource()==sub)

a='-';

if(ae.getSource()==mul)

a='*';

if(ae.getSource()==div)

a='/';

if(ae.getSource()==mod)

a='%';

t.setText("");

if(ae.getSource()==sqrt)

double num=pop();

t.setText(Double.toString(Math.sqrt(num)));

if(ae.getSource()==cbrt)

double num=pop();

t.setText(Double.toString(Math.cbrt(num)));

if(ae.getSource()==sine)

{
double num=pop();

t.setText(Double.toString(Math.sin(num)));

if(ae.getSource()==eq)

float num1=0,num2=0,num3=0,temp1;

String s=t.getText();

float n=Float.parseFloat(s);

push(n);

num1=pop();

num2=pop();

switch(a)

// perform arithmetic operation

case '+' : num3=num1+num2;push(num3);break;

case '-' : num3=num2-num1;push(num3);break;

case '*' : num3=num1*num2;push(num3);break;

case '/' : num3=num2/num1;push(num3);break;

case '%' : num3=num2%num1;push(num3);break;

if(i==1)

{
t.setText(Float.toString(num3));

i=0;

else

t.setText(Integer.toString((int)num3));

temp=1;

if(ae.getSource()==dot)

i=1;

t.setText(t.getText()+".");

public void push(float a)

top++;

stk[top]=a;

public float pop()

float num=stk[top];

top--;

return(num);
}

public void func()

t.setText("");

temp=0;

public static void main(String rr[])throws Exception

new Week9();

68.Write a java program that implements a simple client server application. The
client sends data to server. The server receives the data uses it to produce a result
and then sends the result back to the client then the client displays the result on the
console.

import java.io.*;

import java.net.*;

class Server

public static void main(String args[])


{

try

ServerSocket ss=new ServerSocket(1064);

System.out.println("Waiting for Client Request");

Socket s=ss.accept();

BufferedReader br;

PrintStream ps;

String str;

br=new BufferedReader(new
InputStreamReader(s.getInputStream()));

str=br.readLine();
System.out.println("Received radius");

double r=Double.parseDouble(str);

double area=3.14*r*r;

ps=new PrintStream(s.getOutputStream());

ps.println(String.valueOf(area));

br.close();

ps.close();

s.close();

ss.close();

catch(Exception e)
{

System.out.println(e);

//Client Program

import java.io.*;

import java.net.*;

class Client

public static void main(String args[])throws IOException

{
Socket s=new Socket(InetAddress.getLocalHost(),1064);

BufferedReader br;

PrintStream ps;

String str;

System.out.println("Enter Radius :");

br=new BufferedReader(new InputStreamReader(System.in));

ps=new PrintStream(s.getOutputStream());

ps.println(br.readLine());

br=new BufferedReader(new
InputStreamReader(s.getInputStream()));

str=br.readLine();
System.out.println("Area of the circle is : "+str);

br.close();

ps.close();

69.Write a java program that simulates a traffic light. The program lets the user
select one of three lights: red, yellow, or green with radio buttons. On selecting a
button, an appropriate message with “stop” or “ready” or “go” should appear above
the buttons in a selected color. Initially there is no message shown.

//Program for implementing Traffic Signals

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

/*<applet code="Signals" width=400 height=250></applet>*/

public class Signals extends Applet implements ItemListener

String msg="";

Checkbox stop,ready,go;

CheckboxGroup cbg;
public void init()

cbg = new CheckboxGroup();

stop = new Checkbox("Stop", cbg, false);

ready = new Checkbox("Ready", cbg, false);

go= new Checkbox("Go", cbg, false);

add(stop);

add(ready);

add(go);

stop.addItemListener(this);

ready.addItemListener(this);

go.addItemListener(this);

public void itemStateChanged(ItemEvent ie)

repaint();

public void paint(Graphics g)

{
msg=cbg.getSelectedCheckbox().getLabel();

g.drawOval(165,40,50,50);

g.drawOval(165,100,50,50);

g.drawOval(165,160,50,50);

if(msg.equals("Stop"))

g.setColor(Color.red);

g.fillOval(165,40,50,50);

else if(msg.equals("Ready"))

g.setColor(Color.yellow);

g.fillOval(165,100,50,50);

else

g.setColor(Color.green);

g.fillOval(165,160,50,50);

}
}

70.Write a java program that connects to a database using JDBC and does add,
deletes, modify and retrieve operations?

ConnectionUtil.java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionUtil
{
public static Connection getConnection() throws SQLException
{
Connection connection = null;
try
{
Class.forName("com.mysql.jdbc.Connection");
connection = DriverManager.getConnection("jdbc:mysql://192.168.216.250:3306/vijju","root",
"root");
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
catch (SQLException e)
{
e.printStackTrace();
}
System.out.println("message for connection open"+connection);
return connection;

}
}
StudentDetails.java
public class StudentDetails
{
private long st_id;
private String st_name;
private long st_mobile;
public StudentDetails(long st_id,String st_name,long st_mobile)
{
this.st_id = st_id;
this.st_name = st_name;
this.st_mobile = st_mobile;
}
public long getSt_id()
{
return st_id;
}
public void setSt_id(long st_id)
{
this.st_id = st_id;
}
public String getSt_name()
{
return st_name;
}
public void setSt_name(String st_name)
{

this.st_name = st_name;
}
public long getSt_mobile()
{
return st_mobile;
}
public void setSt_mobile(long st_mobile)
{
this.st_mobile = st_mobile;
}
}

Prog6.java
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Prog6
{
String createTableQuery = "create table test.student_details (st_namevarchar(50), st_mobile
numeric(10), st_id numeric(10))";
public static void main(String[] args)
{ Connection conn = null;
try
{
conn = ConnectionUtil.getConnection();
Prog6 prog6 = new Prog6();
System.out.println("Student_details table data before inserting:");
prog6.retrieveData(conn);

StudentDetails st1 = new StudentDetails(1, "GNIT", 23232323);


StudentDetails st2 = new StudentDetails(2, "GNEC", 24242424);
StudentDetails st3 = new StudentDetails(3, "GNITC", 25252525);
prog6.insertData(conn, st1);
prog6.insertData(conn, st2);
prog6.insertData(conn, st3);
System.out.println("Student_details table data after inserting:");
prog6.retrieveData(conn);
prog6.deleteARow(conn,2);
System.out.println("Student_details table data after deleting:");
prog6.retrieveData(conn);
prog6.modifyData(conn, 26262626, 3);
System.out.println("Student_details table data after modifying:");
prog6.retrieveData(conn);
} catch (SQLException e)
{
e.printStackTrace();
} finally
{
try {
conn.close();
} catch (SQLException e)
{
e.printStackTrace();
}
}
}
private void modifyData(Connection conn, long st_mobile, long st_id)

{
String query = "update student_details set st_mobile=? wherest_id=?";
try {
PreparedStatement pstmt = conn.prepareStatement(query);
pstmt.setLong(1, st_mobile);
pstmt.setLong(2, st_id);
int row = pstmt.executeUpdate();
//System.out.println(row);
} catch (SQLException e)
{ e.printStackTrace();
}
}
private void deleteARow(Connection conn, long st_id)
{
String query = "delete from student_details where st_id=?" ;
try
{
PreparedStatement pstmt = conn.prepareStatement(query);
pstmt.setLong(1, st_id);
int row = pstmt.executeUpdate();
//System.out.println(row);
}
catch (SQLException e)
{
e.printStackTrace();
}
}
private void insertData(Connection conn, StudentDetails details)

{
String query = "insert into test.student_details values (?,?,?)";
try
{
PreparedStatement pstmt = conn.prepareStatement(query);
pstmt.setString(1,details.getSt_name());
pstmt.setLong(2, details.getSt_mobile());
pstmt.setLong(3, details.getSt_id());
int row = pstmt.executeUpdate();
//System.out.println(row);
}
catch (SQLException e)
{
e.printStackTrace();
}
}
private void retrieveData(Connection conn)
{
try {
String query = "select * from test.student_details";
PreparedStatement pstmt = conn.prepareStatement(query);
ResultSet rs = pstmt.executeQuery();
System.out.println("ST_ID\tST_NAME\t\tST_MOBILE");
while(rs.next())
{
System.out.println(rs.getString("st_id")+"\t"+rs.getString("st_name")+"\t\
t"+rs.getString( "st_mobile"));
}

}
catch (SQLException e)
{
e.printStackTrace();
}
}
}

You might also like