Java Practical File Submitted by Poorva Bhardwaj (02390202019)
Java Practical File Submitted by Poorva Bhardwaj (02390202019)
1
18 22/05/21 Create a Class called DIMENSION which declares 3
Variables LENGTH, WIDTH and HEIGHT of Type
FLOAT. It contains 2 Constructor first a Default
Constructor
that WELCOMES THE USER to the program and second
1Parameterized Constructor to set the values of the 3
Parameters. Create 2 Overloaded Methods to Calculate the
VOLUME. First Method is Non - Parameterized and
Second is Parameterized
19 22/05/21 Create a Class STUDENT with Attributes ID, NAME, and
AGE. It contains a Method of GETVALUES with all 3
Parameters as ID, NAME, and AGE Use the
KEYWORD THIS to set the values. Create a Method
DISPLAY to display the values.
20 22/05/21 Write a program to show the usage of STATIC KEYWORD
with a Variable and Method.
21 Write a program to create a class AREA and Calculate Area
22/05/21 RECTANGLE and CIRCLE as Subclasses using DYNAMIC
METHOD DISPATCH (METHOD OVERRIDIING).
22 22/05/21 Write a program to create a Class BOX with INSTANCE
Variables WIDTH and HEIGHT. Create another Class
BOXWEIGHT which inherits Class BOX with an additional
INSTANCE Variable WEIGHT. Compute the Volume of
BOX Using NHERITANCE.
23 22/05/21 Write a program to create a Class BOX with INSTANCE
Variables WIDTH and HEIGHT. Create another Class
BOXWEIGHT which inherits Class BOX with an additional
INSTANCE Variable WEIGHT. Compute the Volume of
BOX Using SUPER KEYWORD
24 23/05/21 Write a program to show the Usage of SUPER KEYWORD
with a Variable and Constructor
25 23/05/21 Write a Relevant program to show the Usage of FINAL
KEYWORD with CLASS, VARIABLE and METHOD
26 23/05/21 Create an ABSTRACT CLASS FIGURE and it 2 CLASSES
RECTANGLE and TRIANGLE. Calculate its AREA
Using DYNAMIC METHOD DISPATCH.
27 23/05/21 Write a program to implement STACKS using INTERFACE
28 14/06/21 Create a PACKAGE CIRCLE with a Class to Calculate the
1 Area of the Circle. Import the PACKAGE in another Class
and implement the Calculation f Area
2
29 14/06/21 Write a Relevant program to show the Usage of TRY,
CATCH, THROW and FINALLY
30 14/06/21 Write a program to create USER-DEFINE EXCEPTION
Class and Throw it Using Extends Keyword
31 14/06/21 Write a program to create a File and Check whether the file
earlier exist or not also print the LENGHT of the file
32 14/06/21 Write a program to Read the Content of a File Using
FileInputStream.
33 14/06/21 Write a program to write some user input data in a File
Using FileWriter Class
34 14/06/21 Write a program to Copy the Contents of Two File to another
File Using SequenceInputStream
35 15/06/21 Write a program to Create an APPLET and perform
Addition of two Numbers entered by User. Display the
Output using drawstring().
36 15/06/21 Design an AWT Form for Registration of any Email
Account.
Perform any 2 Event Handling procedures on it.
37 15/06/21 Write a program to Client Server TCP Based Socket
Program to show the requirement and response
Communication.
38 15/06/21 Write a program to Insert Data into an Existing DataBase.
39 15/06/21 Write a program to Select Data into an Existing DataBase
40 15/06/21 Write a program to Insert Data into a table Using
REPARED STATEMENT.
3
Q1 Write a program to display a WELCOME message to the user in
the command prompt.
OUTPUT:-
4
Q2 Write a program to take COMMAND LINE ARGUMENTS
from the user .Display the No. of Arguments and their content.
OUTPUT:-
5
public class Comdline
{
public static void main(String args[])
{
int count;
count=args.length;
System.out.print(" \n");
System.out.print("The Entered String is:");
for(int i=0;i<count;i++)
{
System.out.print(" "+args[i]);
}
System.out.println("\n Length of array : "+ count);
}
}
C:\notepadjavaprogs>javac Comdline.java
C:\notepadjavaprogs>javadoc Comdline.java
C:\notepadjavaprogs>java Comdline Hello Mister How Do You Do?
OUTPUT:-
6
Coding:-
import java.util.Scanner;
public class UserDetails {
public static void main(String args[])
{
int age;
String name;
String des;
Scanner sc=new Scanner(System.in);
System.out.println("Enter Name: " );
name=sc.nextLine();
System.out.println("Enter Age: " );
age=sc.nextInt();
System.out.println("Enter Designation: " );
des=sc.next();
System.out.println("\n******User Details*******\n");
System.out.println("User name : "+ name );
System.out.println("User Age : "+ age );
System.out.println("User Designation : "+ des );
}
}
7
Q4 Write a program to check whether a number is a number is
POSITIVE ODD, POSITIVE EVEN, NEGATIVE ODD and NEGATIVE
EVEN.
OUTPUT OF EVEN:-
Positive:-
8
Negative:-
OUTPUT OF ODD:-
Positive:-
9
Negative:-
Coding:-
import java.util.Scanner;
public class OddEven
{
public static void main(String args[])
10
{
Scanner sc=new Scanner(System.in);
int n;
System.out.println("Enter Number: ");
n=sc.nextInt();
if(n%2==0)
{
if(n>0)
{
System.out.println("Enterd Number is POSITIVE EVEN NUMBER");
}
else
{
System.out.println("Enterd Number is NEGATIVE EVEN NUMBER");
}
}
else
{
if(n>0)
{
System.out.println("Enterd Nymber is POSITIVE ODD NUMBER");
}
else
{
System.out.println("Enterd Nymber is NEGATIVE ODD NUMBER");
}
}
}
}
Q5 Write a program to generate Grades of Students Using IF ELSE
LADDER
OUTPUT:-
11
Coding:-
import java.util.Scanner;
public class Grade {
public static void main(String args[])
{
int marks;
Scanner sc=new Scanner(System.in);
System.out.println("Enter The Marks: ");
marks=sc.nextInt();
System.out.println("\n*****Grade Of Student*****");
if(marks >=90)
{
System.out.println("Excellent");
System.out.println("Grade = A");
}
else
if( marks >=80 && marks <90 )
{
System.out.println("Very Good");
12
System.out.println("Grade = B");
}
else
if(marks >=70 && marks <80)
{
System.out.println("Good");
System.out.println("Grade = C");
}
else
if(marks >=60 && marks <70)
{
System.out.println("Fair");
System.out.println("Grade = D");
}
else
if(marks >=50 && marks <60)
{
System.out.println("Work Hard");
System.out.println("Grade = E");
}
else
if(marks<=50)
{
System.out.println("Fail");
System.out.println("Grade = F");
}
}
}
OUTPUT:-
13
Coding:-
import java.util.Scanner;
public class SumofCubs {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int i,n,m;
long sum=0;
System.out.println("****Enter The Range of sum of cubes*****");
System.out.println("Enter the Starting Range: ");
n=sc.nextInt();
System.out.println("Enter the Ending Range: ");
m=sc.nextInt();
for(i=n;i<=m;i++)
{
sum=sum+i*i*i;
}
System.out.println("Sum of cubes from " + n +" to " + m + "
numbers is: "+ sum);
14
}
}
$ $ $ $ $ $
$ $ $ $ $
$ $ $ $
$ $ $
$ $
$
15
OUTPUT:-
Coding:-
16
System.out.print("$");
}
System.out.println("");
}
}
}
OUTPUT:-
17
Coding:-
import java.util.Scanner;
public class Fibonacci {
public static void main(String args[])
{
int n,sum;
int num1=0,num2=1,i=1;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Number: ");
n=sc.nextInt();
System.out.println("****Fibonacci Series of "+ n +" are****");
do
{
System.out.print(num1+" ");
sum=num1+num2;
num1=num2;
num2=sum;
i++;
}
while(i<=n);
}
18
}
OUTPUT:-
19
Coding:-
import java.util.Scanner;
public class SumOfDigits {
public static void main(String args[])
{
long num,n,p;
int sum=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Number or Digits: ");
n=sc.nextLong();
p=n;
while(n>0)
{
num=n%10;
sum+=num;
n=n/10;
}
System.out.println("Sum of Digits of Number "+ p + " is: " + sum );
}
}
Q10 Write a program to print the BINARY EQUIVALENT OF A
DECIMAL NUMBER entered by user.
OUTPUT:-
20
Coding:-
import java.util.Scanner;
public class DecilBinary
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
long bin_num[]=new long[100];
long dec_num;
int i=0;
System.out.println("Enter Decimal Number: " );
dec_num=sc.nextLong();
long num=dec_num;
OUTPUT:-
22
Coding:-
import java.util.Scanner;
public class Array {
public static void main(String args[])
{
int i,n;
int sum=0;
Scanner sc=new Scanner(System.in);
int arr[]=new int[10];
n=arr.length;
System.out.println("Enter The Elements: ");
for(i=0;i<n;i++)
{
arr[i]=sc.nextInt();
}
System.out.print(" Sum of Array Elements is: ");
for(i=0;i<n;i++)
{
23
sum=sum+arr[i];
}
System.out.println(" "+sum);
}
}
OUTPUT:-
24
Coding:-
import java.util.Scanner;
public class ArrayEvenOdd {
public static void main(String args[])
{
int i;
int sumodd =0,sumeven =0;
int count=0;
double avg=0.0;
Scanner sc=new Scanner(System.in);
int arr[]=new int[10];
System.out.println("Enter the Elements: ");
for(i=0;i<arr.length;i++)
{
arr[i]=sc.nextInt();
}
for(i=0;i<arr.length;i++)
{
25
if(arr[i]%2==0)
{
count++;
sumeven+=arr[i];
avg=sumeven/count;
}
else
{
sumodd+=arr[i];
}
}
System.out.println("Sum of ODD Numbers in Array is: " + sumodd );
System.out.println("Average of Even Numbers in Array Is: "+ avg);
}
}
OUTPUT:-
26
Coding:-
import java.util.Scanner;
public class InsertionSortNew {
public static void main(String[] args) {
int arr[] = new int[10];
int i, j = 0, temp;
int size = 10;
Scanner sc = new Scanner(System.in);
System.out.println("Enter element: ");
for (i = 0; i < 10; i++)
{
arr[i] = sc.nextInt();
}
System.out.println("Array Before Sort: ");
for (i = 0; i < size; i++)
{
System.out.print(arr[i] + " ");
}
27
System.out.println("\nArray after Sort:");
for (i = 1; i < size; i++)
{
temp = arr[i];
j = i - 1;
while ((temp < arr[j]) && (j >= 0))
{
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = temp;
}
for (i = 0; i < size; i++)
{
System.out.print(arr[i] + " " );
}
}
}
OUTPUT:-
28
Coding:-
import java.util.Scanner;
public class LinearSearch {
public static void main(String args[])
{
int n,item,flag=0;
Scanner sc=new Scanner(System.in);
int arr[];
arr=new int[10];
System.out.println("Enter how many You want to Enter :");
n=sc.nextInt();
System.out.println("Enter the Elements:");
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
}
System.out.println("\n Enter the number to be searched: ");
item=sc.nextInt();
29
for(int i=0;i<n;i++)
{
if(arr[i]==item)
{
flag=1;
System.out.println("Element " + item + " Found at position " + (i+1));
}
}
if(flag==0)
{
System.out.println("Element " + item + " is NOT Found");
}
}
}
Q15 Create a 2-D ARRAY OF 3X3 and print the SUM OF LEFT AND
RIGHT DIAGONAL ELEMENTS.
OUTPUT:-
30
Coding:-
import java.util.Scanner;
public class LeftRightDigonal {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int i,j, n=3,m=3;
int sumleft=0;
int sumright=0;
int arr[][]=new int[n][m];
31
arr[i][j]=sc.nextInt();
}
}
System.out.println("Left Diagonal Element are: ");
for( i=0;i<n;i++)
{
for( j=0;j<m;j++)
{
if(i==j)
{
System.out.print(" "+arr[i][j]);
sumleft=sumleft+arr[i][j];
}
}
}
System.out.println("\nSum of Left Diagonal Element is: "+sumleft+"\
n");
System.out.println("Right Diagonal Element are: ");
j=m-1;
for(i=0;i<n;i++)
{
System.out.print(" "+arr[i][j]);
sumright=sumright+arr[i][j];
j--;
}
System.out.println("\nSum of Right Diagonal Element is:
"+sumright);
}
}
Q16 Create a 2-D ARRAY OF 3X3 and print the SUM OF BORDERED
AND UNBORDERED ELEMENTS.
OUTPUT:-
32
Coding:-
import java.util.Scanner;
public class Unboadered_BoarderArray {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int row=3,col=3;
int i,j,b = 0;
int sumboundry=0,sumunboundry=0;
int arr[][]=new int[row][col];
33
}
}
System.out.println("Bordered Elements are:");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(i==0 || i==row-1 || j==0 || j==col-1 )
{
System.out.print( arr[i][j]+" ");
sumboundry=sumboundry+arr[i][j];
}
else
{
b=arr[i][j];
System.out.print(" ");
sumunboundry=sumunboundry+arr[i][j];
}
}
System.out.println();
}
System.out.println("Unbordered Element is:\n "+b);
System.out.println("\nThe sum of Bordered is: " + sumboundry );
System.out.println("The sum of UNBordered is: " + sumunboundry );
}
OUTPUT:-
34
Coding:-
import java.util.Scanner;
public class StringMethods {
public static void main(String args[])
{
String S1,S2;
35
String S3="Apple";
String S4=" Banana ";
int S5,b=7;
String S6;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the First String: ");
S1=sc.next();
System.out.println("Enter the First String: ");
S2=sc.next();
System.out.println("Third String is:"+S3+"\n"+"Fouth String is:
"+S4+"\n" );
System.out.println("**********String Function************\n" );
System.out.println("Upper Case of First String: "+ S1.toUpperCase() );
System.out.println("Lower Case of Second String: "+ S2.toLowerCase());
System.out.println("Repalce 'o' to 'u' in First String: "+ S1.replace('o', 'u'));
System.out.println("2nd Character At of Second String: "+ S2.charAt(2));
S5=S3.indexOf('p');
System.out.println("Index of 'P' in Third String: "+ S5);
System.out.println("Caparision of First String to Second String: "+
S1.compareTo(S2) );
System.out.println("Trim of Fourth String: "+ S4.trim());
System.out.println("Concationation of Third And Fouth Strings: "+
S3.concat(S4) );
System.out.println("Is First String = Second String: "+ S1.equals(S2) );
System.out.println("Is Third String = Fourth String in any case: "+
S3.equalsIgnoreCase(S4) );
System.out.println("Substring Second String: "+ S2.substring(3) );
System.out.println("Substring Second String: "+ S2.substring(2,5) );
S6=Integer.toString(b);
System.out.println("Convert int to String: "+ S6 );
System.out.println("Index of 'r' in Second String: "+ S2.indexOf("r") );
System.out.println("Index of 'r' and 7th letter in Second String: "+
S2.indexOf("r",7) );
36
}
}
Coding:-
class Dimension{
float Length,Width,Height,cal_volume;
Dimension()
{
System.out.println("WELCOME USER-");
}
Dimension(float l,float w,float h)
{
System.out.println("\n***Values in Paramerized Construction****");
Length=l;
Width=w;
Height=h;
}
void volume()
{
System.out.println("Length: "+Length+" "+"Width: "+ Width+"
"+"Height: "+" "+ Height);
cal_volume=Length*Width*Height;
System.out.println("volume is : "+cal_volume);
}
}
public class ConstOverload {
public static void main(String args[])
{
Dimension d1=new Dimension();
Dimension d2=new Dimension(20,30,40);
d2.volume();
d1.volume(90,80,70);
}}
Q19 Create a Class STUDENT with Attributes ID, NAME, and
AGE. It contains a Method of GETVALUES with all 3 Parameters
as ID, NAME, and AGE Use the KEYWORD THIS to set the
values. Create a Method DISPLAY to display the values.
OUTPUT:-
39
Coding:-
class Student1
{
int id,Rno;
String Name;
void getvalue(int id,int Rno,String Name)
{
this.id=id;
this.Rno=Rno;
this.Name=Name;
}
void display()
{
System.out.println("Student Id is: "+ id);
System.out.println("Student Roll Number is: "+ Rno);
System.out.println("Student Name is: "+ Name);
}
40
}
OUTPUT:-
41
Coding:-
class Student
{
int age;
static int i;
static String name="poorva";
Student()
{
System.out.println("object is created");
i++;
}
Student(int a)
{
age=a;
System.out.println("parameterized constructor is created");
System.out.println("\n***Static Member ***");
System.out.println( "Name of Student is "+name +" and age is " +age);
42
i++;
}
OUTPUT:-
43
Coding:-
class Area{
int length,breath,height;
void set(int l,int b,int h){
length=l;
breath=b;
height=h;
}
void cal_Area(){
System.out.println("*** Area Class ***");
int a=length*breath*height;
System.out.println("Area is: "+a+"\n");
}}
class Rectangle1 extends Area{
void get(int l,int b){
length=l;
breath=b;
}
44
void cal_Area(){
System.out.println("*** Rectangle Class ***");
int a=length*breath;
System.out.println("Area of Rectangle is: "+a+"\n");
}
}
}
}
45
Q22 Write a program to create a Class BOX with INSTANCE
Variables WIDTH and HEIGHT. Create another Class
BOXWEIGHT which inherits Class BOX with an additional
INSTANCE Variable WEIGHT. Compute the Volume of BOX
Using NHERITANCE.
OUTPUT:-
46
Coding:-
import java.util.Scanner;
class Box
{
int height,width;
void setdata(int h,int w)
{
System.out.println("**Method of Box Class**");
height=h;
width=w;
}
void getdata()
{
System.out.println("width is: "+width+" "+"height is: "+height);
}
}
47
int weight;
void volume()
{
height=30;
width=30;
System.out.println("width is: "+width+" "+"height is: "+height+" "+
"weigth is: "+weight);
int vol=width*height*weight;
System.out.println("Volume is: "+vol);
}
}
OUTPUT:-
48
Coding:-
class Box1
{
int height,width;
Box1()
{
height=50;
width=30;
}
}
OUTPUT:-
50
Coding:-
class Flower{
int count=5;
Flower()
{
String FlName="White Roses";
System.out.println(" Make A booke of "+FlName);
}
}
OUTPUT:-
52
Coding:-
final class FINAL{
FINAL(){
System.out.println("Hi Poorva.I'am Constructor of final class");
}
}
class House{
final int cash;
House(){
cash=200000;
System.out.println("I Bought House of Rupees "+cash);
}
final void Rent(){
System.out.println(" i have taken Rental house");
}}
public class UseOfFinal {
public static void main(String args[])
{
System.out.println("\n*** Constructor of Final Class***");
FINAL f1=new FINAL();
53
System.out.println("\n***Final Variable***");
House h1=new House();
System.out.println("\n***Final Function***");
h1.Rent();
}
}
OUTPUT:-
54
Coding:-
56
r1.getdata(5, 7);
r1.Area();
System.out.println("\n****Calling Abstract class Member Fuction*****\n");
r1.me();
}
}
57
OUTPUT OF PEEP FUNCTION (CASE 2):-
58
OUTPUT OF DISPLAY FUNCTION (CASE 4):-
Coding:-
59
import java.util.Scanner;
interface Stack
{
public void push();
public void pop();
public void peep();
public void display();
}
class Stackbase implements Stack{
Scanner sc=new Scanner(System.in);
int max_size=5;
int arr[]=new int[5];
int top=-1,i;
int item;
public void push()
{
if(top==(max_size-1))
{
System.out.println("\n***Stack Overflow***");
}
else
{
item=sc.nextInt();
top++;
arr[top]=item;
}
}
}
public void display()
{
System.out.println("\n***Elements in the stack are:***");
for(i=top;i>=0;i--)
{
System.out.print(" "+arr[i]+" ");
}
}
}
61
System.out.println("**Enter the choice to Perform the following
Operation on Stack**");
System.out.println("(1) Push");
System.out.println("(2) Peep");
System.out.println("(3) Pop");
System.out.println("(4) Display");
System.out.println("\nEnter choice: ");
int choice=sc.nextInt();
switch (choice){
case 1:System.out.println("\n***Enter the element in the Stack:***");
s1.push();
s1.display();
break;
case 2:s1.peep();
break;
case 3:s1.pop();
s1.display();
break;
case 4:s1.display();
break;
}
}
}
OUTPUT:-
62
Coding:-
Creating new Package and a Class in it:-
package Circle_Package;
import java.util.Scanner;
public class Circle {
Scanner sc=new Scanner(System.in);
double pie=3.14;
double Calculate;
public void Cal_Area(){
System.out.println("Enter the value of Radius: ");
int r=sc.nextInt();
Calculate=pie*r*r;
System.out.println("Area of Circle is: "+Calculate);
}
}
import Circle_Package.Circle;
//import Circle_Package.*;
public class Package {
63
public static void main(String args[]){
Circle c1=new Circle();
// Circle_Package.Circle c1=new Circle_Package.Circle();
System.out.println("***Use User_Defined of Package***\n");
c1.Cal_Area();
}
}
64
Coding:-
import java.util.Scanner;
public class useoftexcep {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
try
{
int a,b;
float c;
System.out.println("***Use of try,catch,throw,finally***");
System.out.println("Enter first value: ");
a=sc.nextInt();
System.out.println("Enter Second Value: ");
b=sc.nextInt();
if(b == 0)
{
throw new ArithmeticException();
}
65
else
{
c=a/b;
System.out.println("Result of first number dividing second is:"+c);
}
}
catch(ArithmeticException ex)
{
System.out.println("Division by zero is not possible");
}
finally
{
System.out.println("Hi am Final Block");
}
}
}
OUTPUT:-
66
Coding:-
import java.lang.Exception;
import java.util.Scanner;
class myexception extends Exception{
myexception(String message)
{
super(message);
}
}
67
float c;
System.out.println("***User Defined Exception extends Throw
Keyword***");
System.out.println("Enter first value: ");
a=sc.nextInt();
System.out.println("Enter Second Value: ");
b=sc.nextInt();
if(b == 0)
{
throw new myexception("Division by zero is not possible");
}
else
{
c=a/b;
System.out.println("Result of first number dividing second is:"+c);
}
}
catch(myexception ex)
{
System.out.println(ex);
}
finally{
System.out.println("Hi am Finally Block");
}}}
Q31 Write a program to create a File and Check whether the file
earlier exist or not also print the LENGHT of the file.
OUTPUT:-
68
OUTPUT OF FILE1 (Content After creation of file):-
Coding:-
import java.io.*;
public class File_Existence {
public static void main(String args[]) throws IOException
69
{
File f1=new File("File1");
if(f1.createNewFile())
{
System.out.println("New File created"+ f1.getName());
}
else
{
System.out.println("File1 is Already Exists");
}
else
{
System.out.println("File1 Don't Exists");
}
}
}
FILE1 Content:
70
OUTPUT
Coding:-
import java.io.*;
public class ReadContentOfFile {
public static void main(String args[])throws IOException{
File f1=new File("File1");
71
FileInputStream fin=new FileInputStream("File1");
int i;
while((i=fin.read())!=-1){
System.out.print((char)i);
}
}
Q33 Write a program to write some user input data in a File Using
FileWriter Class
OUTPUT
72
OUTPUT OF FILE1 (Content written by using FileWriter)
Coding:-
import java.io.*;
import java.util.Scanner;
public class WriteUserDataInFile {
73
public static void main(String args[])throws IOException{
Scanner sc=new Scanner(System.in);
FileWriter fout=new FileWriter("File1");
}
}
FILE3 Content
74
FILE4 Content
OUTPUT
75
OUTPUT OF FILE5 (Content written by using SequenceInputStream)
Coding:-
76
import java.io.*;
public class SequencingInFile {
public static void main(String args[])throws IOException{
File f3=new File("File3");
File f4=new File("File4");
File f5=new File("File5");
if(f4.createNewFile())
{
System.out.println("New File created"+ f4.getName());
}
else
{
System.out.println("Already Exists");
}
if(f5.createNewFile())
{
77
System.out.println("New File created"+ f5.getName());
}
else
{
System.out.println("Already Exists");
}
int j;
while((j=seq.read())!=-1){
System.out.print((char)j);
fout.write((char)j);
}
seq.close();
fin.close();
fin1.close();
}
}
Coding:-
import java.applet.*;
import java.awt.event.*;
import java.awt.*;
try{
a=Integer.parseInt(t1.getText());
b=Integer.parseInt(t2.getText());
}
catch(Exception e){}
Result=a+b;
String rs;
rs=String.valueOf(Result);
g.drawString("Sum of two Numbers is:", 100, 150);
g.drawString(rs,150,168);
}
public Boolean Action(Event event,Object object){
repaint();
return true;
}
}
81
Coding:-
public Emial_Registeration() {
initComponents();
}
SERVER OUTPUT:-
83
CLIENT OUTPUT
Server coding:
import java.io.*;
import java.net.*;
84
public class Server1 {
public static void main(String[] args){
try{
ServerSocket ss=new ServerSocket(6666);
Socket s=ss.accept();//establishes connection
DataInputStream dis=new DataInputStream(s.getInputStream());
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
String str=(String)dis.readUTF();
System.out.println("message= "+str);
dout.writeUTF("Hello Client i am your Server and Your Request is Accepted");
ss.close();
}
catch(Exception e){
System.out.println(e);
}
}
}
Client coding:
import java.io.*;
import java.net.*;
public class Client1 {
85
public static void main(String[] args) {
try{
Socket s=new Socket("localhost",6666);
DataInputStream dis=new DataInputStream(s.getInputStream());
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("Hello Server i am your new Client");
String str=(String)dis.readUTF();
System.out.println("message= "+str);
dout.flush();
dout.close();
s.close();
}
catch(Exception e){
System.out.println(e);
}
}
}
OUTPUT
86
Coding:
import java.sql.*;
public class DataBase {
public static void main(String args[]){
try{
//step1 load the driver class
Class.forName("org.apache.derby.jdbc.ClientDriver");
87
}
catch(Exception e){
System.out.println(e);
}
}
}
OUTPUT
88
Coding:
import java.sql.*;
public class DataBase {
public static void main(String args[]){
try{
//step1 load the driver class
Class.forName("org.apache.derby.jdbc.ClientDriver");
OUTPUT
90
Coding:-
import java.sql.*;
import java.util.*;
public class DataBase {
public static void main(String args[]){
try{
//step1 load the driver class
Class.forName("org.apache.derby.jdbc.ClientDriver");
91
stmt.setInt(1, a);
stmt.setString(2, b);
int i=stmt.executeUpdate();
System.out.println(i+"Record Inserted");
92