98
VISIT www.educationjockey.com for old papers, practical file samples. This file is for reference purpose only. Java Practical File

Java Practical File - educationjockey.comeducationjockey.com/wp-content/uploads/2016/02/javapractical.pdf · VISIT for old papers, practical file samples. This file is for reference

  • Upload
    buihanh

  • View
    267

  • Download
    3

Embed Size (px)

Citation preview

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

Java

Practical

File

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

******************************************************************************

PROGRAM TO PRINT A STRING ******************************************************************************

class a

{

public static void main(String args[])

{

System.out.println("rashi");

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO CALCULATE LENGTH OF AN ARRAY

************************************************************************

class comdline

{

public static void main(String args[])

{

int c=args.length;

System.out.println(c);

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO ADD TWO STRINGS

************************************************************************

class comd

{

public static void main(String args[])

{

String sum;

sum=args[0]+args[1];

System.out.println(sum);

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO ADD TWO NUMBERS

************************************************************************

class add

{

public static void main(String args[])

{

int a,b,c;

a=5;

b=4;

c=a+b;

System.out.println(c);

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO CHECK WHETHER A NUMBER IS EVEN OR ODD

************************************************************************

class even

{

public static void main(String args[])

{

int a;

a=Integer.parseInt(args[0]);

if(a%2==0)

{

System.out.println(a + "is even number");

}

else

{

System.out.println(a + "is odd number");

}

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO CALCULATE FACTORIAL OF A NUMBER

************************************************************************

class fact

{

public static void main(String args[])

{

int n,i,f;

f=1;

n=Integer.parseInt(args[0]);

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

{

f=f*i;

}

System.out.println("THE FACTORIAL OF " + n + "is: " + f);

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO CALCULATE FIBONACCI SERIES

************************************************************************

class fibo

{

public static void main(String args[])

{

int a=0,b=1,c,n,i;

n=Integer.parseInt(args[0]);

System.out.println("THE SERIES IS:");

System.out.println(a);

System.out.println(b);

for(i=0;i<n-2;i++)

{

c=a+b;

a=b;

b=c;

System.out.println(c);

}

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO CALCULATE REVERSE OF A NUMBER

class reverse

{

public static void main(String args[])

{

int n,b=0;

n=Integer.parseInt(args[0]);

while(n>0)

{

int r=n%10;

n=n/10;

b=b*10+r;

}

System.out.println("THE REVERSE IS:");

System.out.println(b);

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO CALCULATE MATHS FUNCTIONS

************************************************************************

import java.lang.Math;

class func

{

public static void main(String args[])

{

double x=25.4;

double y,c,d,a,b;

y=Math.sqrt(x);

System.out.println("THE SQUARE ROOT IS: " + y);

a=Math.ceil(x);

System.out.println("THE CEILED ANSWER IS: " + a);

b=Math.floor(x);

System.out.println("THE FLOORED ANSWER IS : " + b);

c=Math.min(4.3,4.5);

System.out.println("MINIMUM NUMBER IS: " + c);

d=Math.max(4.3,4.5);

System.out.println("MAXIMUM NUMBER IS; " + d);

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

}

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO CONVERT VALUE GIVEN AT COMMAND LINE TO INTEGER &

ADD THEM

************************************************************************

class add1

{

public static void main(String args[])

{

int sum;

int d,e;

d=Integer.parseInt(args[0]);

e=Integer.parseInt(args[1]);

sum=d+e;

System.out.println(sum);

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO DISPLAY VALUES AT COMMANDLINE

************************************************************************

class disp

{

public static void main(String args[])

{

int i;

for(i=0;i<args.length;i++)

{

System.out.println(args[i]);

}

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO CHECK WHETHER CHARACTER IS VOWEL OR CONSONANT

************************************************************************

class vowel

{

public static void main(String args[])

{

char b='u';

if(b=='a'||b=='e'||b=='i'||b=='o'||b=='u'||b=='A'||b=='E'||b=='I'||b=='O'||b=='U')

{

System.out.println(b + " is vowel");

}

else

{

System.out.println(b + " is consonant");

}

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO CHECK WHETHER NUMBER IS PRIME OR NOT

************************************************************************

class prime

{

public static void main(String args[])

{

int n=Integer.parseInt(args[0]);

int c=0;

for(int i=1;i<=n;i++)

{

if(n%i==0)

{

c++;

}

}

if(c==2)

{

System.out.println(n + " IS PRIME NUMBER");

}

else

{

System.out.println(n + " IS NOT PRIME NUMBER");

}

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO FIND THE GREATEST AMONG THE THREE NUMBERS

************************************************************************

class great

{

public static void main(String args[])

{

int a=Integer.parseInt(args[0]);

int b=Integer.parseInt(args[1]);

int c=Integer.parseInt(args[2]);

if((a>b) && (a>c))

{

System.out.println(a + " IS GREATEST");

}

else if((b>a) && (b>c))

{

System.out.println(b + " IS GREATEST");

}

else

{

System.out.println(c + " IS GREATEST");

}

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO USE THE ASSIGNMENT OPERATOR

************************************************************************

class assign

{

public static void main(String args[])

{

int a;

a=Integer.parseInt(args[0]);

a+=5;

System.out.println("CHANGED VALUE OF A IS: " + a);

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO USE THE RELATIONAL OPERATOR

************************************************************************

class relation

{

public static void main(String args[])

{

int a=Integer.parseInt(args[0]);

if(a==1)

{

System.out.println("HELLO,YOU HAVE ENTERED 1");

}

else

{

System.out.println("ENTER 1 TO GET OUTPUT");

}

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO USE THE CONDITIONAL OPERATOR

************************************************************************

class cond

{

public static void main(String args[])

{

int a=Integer.parseInt(args[0]);

int x=(a>10)?a:10;

System.out.println("THE VALUE OF X IS : " + x);

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO USE THE INCREMENT/DECREMENT OPERATOR

************************************************************************

class oper

{

public static void main(String args[])

{

int a=Integer.parseInt(args[0]);

int x=a++;

System.out.println("OUTPUT USING POST INCREMENT IS " + x);

int y=++a;

System.out.println("OUTPUT USING PRE INCREMENT IS " + y);

int x1=a--;

System.out.println("OUTPUT USING POST DECREMENT IS " + x1);

int y1=--a;

System.out.println("OUTPUT USING PRE DECREMENT IS " + y1);

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO USE THE BITWISE OPERATOR

************************************************************************

class bit

{

public static void main(String args[])

{

int a=Integer.parseInt(args[0]);

int x=a<<2;

System.out.println("OUTPUT USING LEFT SHIFT IS : " + x);

int y=a>>2;

System.out.println("OUTPUT USING RIGHT SHIFT IS : " + y);

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO USE WHILE,DO=WHILE,FOR LOOP

************************************************************************

class loop

{

public static void main(String args[])

{

System.out.println("RESULT OF FOR LOOP IS : ");

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

{

System.out.println(i);

}

System.out.println("RESULT OF WHILE LOOP IS : ");

int n=1;

while(n<5)

{

System.out.println(n);

n=n+1;

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

}

System.out.println("RESULT OD DO-WHILE LOOP IS : ");

int j=1;

do

{

System.out.println(j);

j=j+1;

}

while(j<5);

}

}

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO USE POST AND PRE INCREMENT OPERATOR

************************************************************************

class hi

{

public static void main(String args[])

int x=1;

int y=1;

x=x++ + y++;

System.out.println("VALUE OF X IS : " + x);

System.out.println("VALUE OF Y IS : " + y);

y=++x + ++y;

System.out.println("VALUE IS : " + x);

System.out.println("VALUE IS : " + y);

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO USE MATH FUNCTION AND CALCULATE VOLUME

************************************************************************

import java.lang.Math;

class func1

{

public static void main(String args[])

{

int r=Integer.parseInt(args[0]);

double x=Math.pow(r,3);

double y=Math.PI;

double v=(4*y*x)/3;

System.out.println("VOLUME IS : " + v);

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO MANIPULATE STRINGS

************************************************************************

class sfunc

{

public static void main(String args[])

{

String s1=new String();

String s2=new String();

s1=args[0];

s2=args[1];

System.out.println("RESULT AFTER CONCATENATION " + (s1.concat(s2)));

System.out.println("LENGTH OF SECOND STRING IS : " + (s2.length()));

System.out.println("RESULT AFTER CHECKING EQUALITY " + (s1.equals(s2)));

System.out.println("RESULT AFTER CHECKING EQUALITY AND IGNORING

CASE : " + (s1.equalsIgnoreCase(s2)));

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM FOR PRINTING SERIES

************************************************************************

class series

{

public static void main(String args[])

{

int n=Integer.parseInt(args[0]);

System.out.print("1\n");

for(int j=1;j<=n;j++)

{

System.out.print("1");

int a=0;

int b=1;

for(int i=1;i<=j;i++)

{

int c=a+b;

a=b;

b=c;

System.out.print(c);

}

System.out.print("\n");

}

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO IMPLEMENT INPUT FROM THE USER

************************************************************************

import java.io.*;

class input

{

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

{

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

String n;

System.out.println("ENTER STRING");

System.out.flush();

n=a.readLine();

System.out.println("YOU HAVE ENTERED " + n);

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO USE THIS KEYWORD

class a

{

int age;

String name;

a(String name,int age)

{

this.name=name;

this.age=age;

}

void display()

{

System.out.println("NAME IS " + name);

System.out.println("AGE IS " + age);

}

}

class thii

{

public static void main(String args[])

{

a o=new a("rashi",20);

o.display();

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO USE TWO CLASSES AND INSTANCE VARIABLE

************************************************************************

import java.io.*;

class bank

{

int t;

void credit_balance()

{

int m=0;

System.out.println("CURRENT BALANCE IS :RS" + t);

try

{

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

System.out.println("ENTER AMOUNT TO BE CREDITED");

System.out.flush();

m=Integer.parseInt(a.readLine());

}

catch(IOException e)

{

System.out.println("THERE HAS BEEN AN EXCEPTION");

}

t=t+m;

System.out.println("BALANCE AFTER CREDIT IS RS" + t);

}

void debit_balance()

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

{

int m1=0;

System.out.println("CURRENT BALANCE IS :RS" + t);

try

{

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

System.out.println("ENTER AMOUNT TO BE DEBITED");

System.out.flush();

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

}

catch(IOException e)

{

System.out.println("THERE HAS BEEN AN EXCEPTION");

}

t=t-m1;

System.out.println("BALANCE AFTER DEBIT IS RS" + t);

}

}

class bankac

{

public static void main(String args[])

{

bank o=new bank();

o.t=1000;

o.credit_balance();

o.debit_balance();

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO SHOW WORKING OF APPLET

************************************************************************

import java.applet.*;

import java.awt.*;

public class simple extends Applet

{

public void paint(Graphics g)

{

g.drawString("THIS IS A SIMPLE APPLET",200,200);

}

}

HTML FILE:

<html>

<body>

<applet code=simple width=200 height=200>

</applet>

</body>

</html>

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM THAT IMPLEMENTS PARAMETER PASSING TO AN APPLET

************************************************************************

import java.applet.*;

import java.awt.*;

public class parameter extends Applet

{

String s;

public void init()

{

s=getParameter("string");

}

public void paint(Graphics g)

{

g.drawString(s,100,100);

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

}

HTML FILE:

<html>

<body>

<applet code=parameter width=200 height=200>

<PARAM name=String value="HI,THIS IS RASHI">

</applet>

</body>

</html>

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM USING ALIGN ATTRIBUTE IN APPLET

************************************************************************

import java.applet.*;

import java.awt.*;

public class allign extends Applet

{

String s;

public void init()

{

s=getParameter("string");

}

public void paint(Graphics g)

{

g.drawString(s,100,100);

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

}

HTML FILE:

<html>

<body>

<applet code=allign width=200 height=200>

<PARAM name=String value="hello to everyone">

<ALIGN=LEFT>

</applet>

</body>

</html>

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO DISPLAY NUMERICAL VALUES IN APPLETS

************************************************************************

import java.applet.*;

import java.awt.*;

public class numerical extends Applet

{

public void paint(Graphics g)

{

int sum=10+30;

String s=String.valueOf(sum);

g.drawString("Addition of 10 and 30 gives"+s,100,100);

}

}

HTML FILE:

<html>

<body>

<applet code=numerical width=200 height=200>

</applet>

</body>

</html>

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO WRITE BYTES INTO A FILE

************************************************************************

import java.io.*;

class wbytes

{

public static void main(String args[])

{

byte write[]={'R','A','S','H','I'};

FileOutputStream f1=null;

try

{

f1=new FileOutputStream("rashi.txt");

f1.write(write);

System.out.println("file is written");

f1.close();

}

catch(IOException e)

{

System.out.println("there is an exception");

}

finally

{

try

{

f1.close();

}

catch(IOException e)

{

System.out.println("catch my exception");

}

}

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM FOR READING BYTES FROM A FILE

************************************************************************

import java.io.*;

class rbytes

{

public static void main(String args[])

{

FileInputStream f1=null;

int a;

try

{

f1=new FileInputStream("rashi.txt");

System.out.println("file contains:");

while((a=f1.read())!=-1)

{

System.out.println((char)a);

}

f1.close();

}

catch(IOException e)

{

System.out.println("there is an exception");

}

finally

{

try

{

f1.close();

}

catch(IOException e)

{

System.out.println("catch my exception");

}

}

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO COPY BYTES FROM 1 FILE TO ANOTHER

************************************************************************

import java.io.*;

class cbyes

{

public static void main(String args[])

{

FileInputStream f1=null;

FileOutputStream f2=null;

byte a;

try

{

f1=new FileInputStream("rashi.txt");

f2=new FileOutputStream("rashi1.txt");

do

{

a=(byte)f1.read();

f2.write(a);

}

while(a!=-1);

System.out.println("file is copied");

}

catch(FileNotFoundException e)

{

System.out.println("file not found");

}

catch(IOException e)

{

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

}

finally

{

try

{

f1.close();

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

f2.close();

}

catch(IOException e)

{

System.out.println("catch my exception");

}

}

}

}

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM FOR WRITING CHARACTERS INTO A FILE

************************************************************************

import java.io.*;

class wcharacters

{

public static void main(String args[])

{

char a[]={'R','A','S','H','I'};

File f1=new File("rashi100.txt");

FileWriter o1=null;

try

{

o1=new FileWriter(f1);

o1.write(a);

System.out.println("file is written");

o1.close();

}

catch(IOException e)

{

System.out.println("there is an exception");

}

finally

{

try

{

o1.close();

}

catch(IOException e)

{

System.out.println("catch my exception");

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

}

}

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO READ CHARACTERS FROM A FILE

************************************************************************

import java.io.*;

class rcharacters

{

public static void main(String args[])

{

File f1=new File("rashi100.txt");

FileReader o1=null;

try

{

o1=new FileReader(f1);

int ch;

System.out.println("file contains:");

while((ch=o1.read())!=-1)

{

System.out.println((char)ch);

}

o1.close();

}

catch(IOException e)

{

System.out.println("there is an exception");

}

finally

{

try

{

o1.close();

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

}

catch(IOException e)

{

System.out.println("catch my exception");

}

}

}

}

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO COPY CHARACTERS FROM 1 FILE TO ANOTHER

************************************************************************

import java.io.*;

class ccharacters

{

public static void main(String args[])

{

File f1=new File("rashi100.txt");

File f2=new File("rashi2.txt");

FileReader o1=null;

FileWriter o2=null;

try

{

o1=new FileReader(f1);

o2=new FileWriter(f2);

int ch;

while((ch=o1.read())!=-1)

{

o2.write(ch);

}

System.out.println("file is copied");

}

catch(IOException e)

{

System.out.println("there is an exception");

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

finally

{

try

{

o1.close();

o2.close();

}

catch(IOException e)

{

System.out.println("catch exception");

}

}

}

}

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

import java.net.*;

class netdemo

{

public static void main(String args[])

{

try

{

InetAddress ia=InetAddress.getLocalHost();

System.out.println("IP address is "+ ia);

}

catch(UnknownHostException e)

{

System.out.println("there is an exception");

}

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO USE DIFFERENT METHODS OF GRAPHICS CLASS

************************************************************************

import java.applet.*;

import java.awt.*;

public class funct extends Applet

{

public void paint(Graphics g)

{

g.setColor(Color.yellow);

g.fillOval(200,150,200,200);

g.setColor(Color.black);

g.drawOval(250,200,10,10);

g.drawOval(330,200,10,10);

g.drawLine(300,210,300,270);

g.setColor(Color.red);

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

g.drawArc(255,235,90,80,180,180);

g.setColor(Color.black);

g.drawString("SMILEY FACE",260,110);

}

}

HTML FILE:

<html>

<body>

<applet code=funct width=200 height=200>

</applet>

</body>

</html>

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

PROGRAM THAT CAPTURES AND PROCESSES ALL THE MOUSE EVENTS

************************************************************************

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

public class mousedemo extends Applet implements

MouseListener,MouseMotionListener

{

String msg=null;

int x=0;

int y=0;

public void init()

{

addMouseListener(this);

addMouseMotionListener(this);

}

public void mouseEntered(MouseEvent e)

{

x=10;

y=20;

msg="mouse has been entered";

repaint();

}

public void mouseClicked(MouseEvent e)

{

x=10;

y=20;

msg="mouse has been clicked";

repaint();

}

public void mouseExited(MouseEvent e)

{

x=10;

y=20;

msg="mouse has been exited";

repaint();

}

public void mousePressed(MouseEvent e)

{

x=e.getX();

y=e.getY();

msg="down";

repaint();

}

public void mouseReleased(MouseEvent e)

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

{

x=e.getX();

y=e.getY();

msg="up";

repaint();

}

public void mouseDragged(MouseEvent e)

{

x=e.getX();

y=e.getY();

msg="mouse dragged";

showStatus("mouse dragged at" + x + "," + y);

repaint();

}

public void mouseMoved(MouseEvent e)

{

x=e.getX();

y=e.getY();

msg="mouse dragged";

showStatus("mouse moved at" + x + "," + y);

repaint();

}

public void paint(Graphics g)

{

g.drawString(msg,x,y);

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO USE MULTIPLE CATCH STATEMENTS

************************************************************************

class excep2

{

public static void main(String args[])

{

try

{

int d=args.length;

int b=42/d;

int c[]={1};

c[10]=100;

System.out.println("THE VALUE OF C IS : " + c);

}

catch(ArithmeticException e1)

{

System.out.println("DIVIDE BY ZERO");

}

catch(ArrayIndexOutOfBoundsException e)

{

System.out.println("ARRAY OUT OF BOUNDS");

}

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO PERFORM MULTITHREADING AND SET PRIORITY

************************************************************************

class mythread1 extends Thread

{

public void run()

{

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

{

System.out.println("thread1 is running");

}

System.out.println("exit from thread1");

}

}

class mythread2 extends Thread

{

public void run()

{

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

{

System.out.println("my thread2 is running");

}

System.out.println("exit from thread2");

}

}

class mythread3 extends Thread

{

public void run()

{

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

{

System.out.println("my thread3 is running");

}

System.out.println("exit from thread3");

}

}

class th

{

public static void main(String args[])

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

{

mythread1 mt1=new mythread1();

mythread2 mt2=new mythread2();

mythread3 mt3=new mythread3();

mt1.setPriority(Thread.MAX_PRIORITY);

mt2.setPriority(Thread.MIN_PRIORITY);

mt3.setPriority(mt2.getPriority()+4);

System.out.println(mt3.getPriority());

mt1.start();

mt2.start();

mt3.start();

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO USE TRY,CATCH,FINALLY

************************************************************************

class excep1

{

public static void main(String args[])

{

try

{

int a=Integer.parseInt(args[0]);

System.out.println("The value of a is "+a);

int b=42/a;

System.out.println("The value of b is "+b);

}

catch(ArithmeticException e)

{

System.out.println("DIVIDE BY ZERO");

}

finally

{

System.out.println("HELLO");

}

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM TO ADD NUMBER OF ELEMENTS PASSED IN AN ARRAY

************************************************************************

class array

{

public static void main(String args[])

{

int i,c=0;

for(i=0;i<args.length;i++)

{

c=c+Integer.parseInt(args[i]);

}

System.out.println("THE SUM IS: " + c);

}

}

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

************************************************************************

PROGRAM IMPLEMENTING INPUT TO AN APPLET

************************************************************************

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

public class event1 extends Applet implements ActionListener

{

TextField t1,t2,t3;

public void init()

{

t1=new TextField(10);

t2=new TextField(10);

add(t1);

add(t2);

t1.setText("0");

t2.setText("0");

t1.addActionListener(this);

t2.addActionListener(this);

}

public void paint(Graphics g)

{

int x,y,sum;

String s1,s2,s3;

g.drawString("ENTER TWO STRINGS",100,30);

try

{

s1=t1.getText();

x=Integer.parseInt(s1);

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.

s2=t2.getText();

y=Integer.parseInt(s2);

sum=x+y;

s3=String.valueOf(sum);

g.drawString("THE SUM IS:",100,100);

g.drawString(s3,415,100);

}

catch(Exception e)

{

System.out.println("there is an exception");

}

}

public void actionPerformed(ActionEvent e)

{

repaint();

}

}

OUTPUT:

VISIT www.educationjockey.com for old papers, practical file samples.

This file is for reference purpose only.