Practical File of Web Developement

download Practical File of Web Developement

of 41

Transcript of Practical File of Web Developement

  • 8/13/2019 Practical File of Web Developement

    1/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL

    PRACTICALFILE OFWEB DEVELOPMENT

    VAISH COLLEGE OF ENGINEERING

    SUBMITTEDTO SUBMITTEDBY

    Mr.Kulwinder Singh Pankaj GillAsst. Professor 11/CSE/168CSE Deptt. CSE-B

  • 8/13/2019 Practical File of Web Developement

    2/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL

    INDEX Aim Page Remarks

    1. Write a simple java program 1

    2. Write a program to show conversionTemperature from Celsius to Fahrenheit andFahrenheit to Celsius

    2

    3. Write a program to find the no and sum of all

    integers greater than 100 and less than 200that are divisible by 7.

    6

    4. Write a program to show a Grading system 8

    5. Write a program to print a format using * inincreasing order

    10

    6 Write a program to find out some of digits ofany integer number

    12

    7. Write a program to show the Multiplicationtable

    14

    8. Write a program to show ConstructorMethod

    16

    9. Write a program to show MethodOverloading

    18

    10. Write a program to show Method Overriding 20

    11. Write a program to show Polymorphism usingInheritance

    22

    12. Write a program to show Inheritance 25

    13. Write a program to show Swapping of twoStrings

    27

    14. Write a program to show Multiplication oftwo Matrices

    30

    15. Show the Life Cycle of an Applet 34

    16. Write a program to show a simple Applet 38

  • 8/13/2019 Practical File of Web Developement

    3/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    1

    PROGRAM NO. 1Write a simple java program

    class Sample

    {

    public static void main(String args[])

    {

    System.out.println("=== Hello java ====");

    }

    }

  • 8/13/2019 Practical File of Web Developement

    4/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    2

    OUTPUT

  • 8/13/2019 Practical File of Web Developement

    5/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    3

    PROGRAM NO. 2Write a program to show conversion Temperature from Celsius

    to Fahrenheit and Fahrenheit to Celsius

    Import.java.util.*;

    class Temp

    {

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

    IOException

    {

    Scanner cin=new Scanner(System.in);

    intch;

    System.out.println("\n Press 1 for Centigrate to

    Farnhit OR 2 for Farnhit to Centigrate\n");

    ch=cin.nextInt();

    if(ch==1)

    {

    Scanner cin1=new Scanner(System.in);

    System.out.println("Enter temp in centigrate");

    float c;

    float f;

    c=cin1.nextFloat();

    f=(9*c+160)/5;

    System.out.println( "The temperature in

    Fahrenheit scale is :"+f);

  • 8/13/2019 Practical File of Web Developement

    6/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    4

    }

    else if(ch==2)

    {

    Scanner cin2=new Scanner(System.in);

    System.out.println("Enter temp in Farnhit");

    float c;

    float f;

    f=cin2.nextFloat();

    c=(5*f-160)/9;

    System.out.println( "The temperature in

    centigrate scale is :"+c);

    }

    else

    {

    System.out.println("wrong choice Try Again

    !!!!");

    }

    }

    }

  • 8/13/2019 Practical File of Web Developement

    7/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    5

    OUTPUT

  • 8/13/2019 Practical File of Web Developement

    8/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    6

    PROGRAM NO. 3Write a program to find the no and sum of all integers greater

    than 100 and less than 200 that are divisible by 7.

    classFindSumIntCompute

    {

    public static void main(String[] args)

    {

    int sum = 0;

    for (inti=100; i

  • 8/13/2019 Practical File of Web Developement

    9/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    7

    OUTPUT

  • 8/13/2019 Practical File of Web Developement

    10/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    8

    PROGRAM NO. 4Write a program to show a Grading system

    importjava.util.*;

    class Grade

    {

    public static void main(String args[])

    {

    System.out.println("Enter any number from 0 to 100 ");

    Scanner cin=new Scanner(System.in);

    inti;

    i=cin.nextInt();

    if(i>=81 && i=61 && i=41 && i=0 && i

  • 8/13/2019 Practical File of Web Developement

    11/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    9

    OUTPUT

  • 8/13/2019 Practical File of Web Developement

    12/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    10

    PROGRAM NO. 5Write a program to print a format using * in increasing order

    class Star

    {

    public static void main(String args[])

    {

    inti,j;

    for(i=1;i

  • 8/13/2019 Practical File of Web Developement

    13/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    11

    OUTPUT

  • 8/13/2019 Practical File of Web Developement

    14/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    12

    PROGRAM NO. 6Write a program to find out some of digits of any integer

    number

    importjava.util.*;

    import java.io.*;

    classSumDigitnew

    {

    public static void main(String args[])

    {

    Scanner cin=new Scanner(System.in)

    int sum, i,a,d;

    d=cin.nextInt();

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

    sum = 0;

    for(i=1;i< =10;i++)

    {

    d=a%10;

    a=a/10;

    sum=sum+d;

    }

    System.out.println("Sum of Digit :"+sum);

    }

    }

  • 8/13/2019 Practical File of Web Developement

    15/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    13

    OUTPUT

  • 8/13/2019 Practical File of Web Developement

    16/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    14

    PROGRAM NO. 7Write a program to show the Multiplication table

    importjava.util.*;

    class Table

    {

    static public void main(String[] args)

    {

    Scanner cin=new Scanner(System.in);

    System.out.println("please enter the number");

    int n=cin.nextInt();

    System.out.println("Multiplication table : ");

    for(inti=1;i

  • 8/13/2019 Practical File of Web Developement

    17/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    15

    OUTPUT

  • 8/13/2019 Practical File of Web Developement

    18/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    16

    PROGRAM NO. 8Write a program to show Constructor Method

    classRect

    {

    intlength,breadth;

    publicRect() //Default Constructer

    {

    length=0 ; breadth=0 ;

    System.out.println("Default constructer is fired");

    }

    publicRect(intl,int b) //Parametrised( Double Argumented) Constructer

    {

    int s;

    length=l ; breadth=b ;

    System.out.println("Parametrised( Double Argumented)Constructer is fired");

    s=l+b;

    System.out.println("sum="+s);

    }

    public static void main(String args[])

    {

    Rect r1=new Rect();

    Rect r2=new Rect(6,7);

    }

    }

  • 8/13/2019 Practical File of Web Developement

    19/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    17

    OUTPUT

  • 8/13/2019 Practical File of Web Developement

    20/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    18

    PROGRAM NO. 9Write a program to show Method Overloading

    classmethodOverloading

    {

    int add( inta,int b)

    {

    return(a+b);

    }

    float add(float a,float b)

    {

    return(a+b);

    }

    double add( int a, double b,double c)

    {

    return(a+b+c);}

    }

    classmainClass extends methodOverloading

    {

    public static void main( String arr[] )

    {

    mainClass temp = new mainClass();

    System.out.println(temp.add(10,20));

    System.out.println(temp.add(1.5f,2.3f));

    System.out.println(temp.add(10,20.4,25.6));

    }

    }

  • 8/13/2019 Practical File of Web Developement

    21/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    19

    OUTPUT

  • 8/13/2019 Practical File of Web Developement

    22/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    20

    PROGRAM NO. 10Write a program to show Method Overriding

    class A

    {

    public void Show()

    {

    System.out.println("A CAN DO HORSE RIDING BUT CANNOTRIDE A BIKE");

    }

    }

    class B extends A

    {

    public void Show()

    {

    System.out.println("B CAN RIDE A BIKE BUT DOESNOTKNOW HORSE RIDING");

    System.out.println("A class's show() method isoverridden by B class's show() method");

    }

    // Here the Show() method of parent class A is Overridden byShow() method of Child class B..

    }

    class Test

    {

    public static void main(String args[])

    {

    B obj=new B();

    obj.Show();

    }

    }

  • 8/13/2019 Practical File of Web Developement

    23/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    21

    OUTPUT

  • 8/13/2019 Practical File of Web Developement

    24/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    22

    PROGRAM NO. 11Write a program to show Polymorphism using Inheritance

    Polymorphism means the ability of a single variable of a given type to be used to referenceobjects ofdifferent types, and automatically call the method that is specific to the type ofobject the variable references. The benefit of polymorphism is that it is very easy to addnew classes of derived objects without breaking the calling code that uses the polymorphicclasses or interfaces. When you send a message to an object even though you dont knowwhat specific type it is, and the right thing happens, thats called polymorphism. The processused by object-oriented programming languages to implement polymorphism is calleddynamic binding. Polymorphism can be achieved by Method Overloading, MethodOverriding & Inheritance.Example :-

    class A{

    public void showA()

    {

    System.out.println("Class A is Shown");

    }

    }

    class B extends A

    {

    public void showB()

    {

    System.out.println("Class B is Shown");

    }

    }

    class C extends B

    {

    public void showC()

    {

    System.out.println("Class C is Shown");

  • 8/13/2019 Practical File of Web Developement

    25/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    23

    }

    }

    classTestABC

    {

    public static void main(String args[])

    {

    C obj=new C();

    obj.showA();

    obj.showB();

    obj.showC();

    }

    }

    Description of Program:-

    We have created object of class C only but due to polymorphism we are able to refer toClass a and class B also i.e. If we derive many classes from a base class then we can refer toany class by creating object of Derived Class (Child class).

  • 8/13/2019 Practical File of Web Developement

    26/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    24

    OUTPUT

  • 8/13/2019 Practical File of Web Developement

    27/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    25

    PROGRAM NO. 12Write a program to show Inheritance

    class Parent

    {

    public void Show()

    {

    inti=200000;

    System.out.println("I HAVE 200000 RUPEES IN BANK

    ACCOUNT");

    }

    }

    class Child extends Parent

    {

    }

    class Test

    {

    public static void main(String args[])

    {

    Child obj=new Child();

    obj.Show();

    System.out.println("child has takken parent'sproperties");

    }

    }

  • 8/13/2019 Practical File of Web Developement

    28/41

  • 8/13/2019 Practical File of Web Developement

    29/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    27

    PROGRAM NO. 13Write a program to show Swapping of two Strings

    importjava.util.*;

    class Swap

    {

    public static void main(String[] args)

    {

    Scanner cin=new Scanner(System.in);

    String i;

    System.out.println("Enter first String");

    i=cin.nextLine();

    Scanner cin1=new Scanner(System.in);

    String j;

    System.out.println("Enter Second String");

    j=cin1.nextLine();

    System.out.println("\nBefore swapping\n");

    System.out.println(" "+i+" "+j);

    swap(i,j);

    }

  • 8/13/2019 Practical File of Web Developement

    30/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    28

    static void swap(String i,String j)

    {

    String temp;

    temp=i;

    i=j;

    j=temp;

    System.out.println("\nAfter swapping\n");

    System.out.println(" "+i+" "+j);

    }

    }

  • 8/13/2019 Practical File of Web Developement

    31/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    29

    Output

  • 8/13/2019 Practical File of Web Developement

    32/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    30

    PROGRAM NO. 14Write a program to show Multiplication of two Matrices

    importjava.util.Scanner;

    class Matrix

    {

    public static void main(String args[])

    {

    int m, n, p, q, sum = 0, c, d, k;

    Scanner in = new Scanner(System.in);

    System.out.println("Enter the number of rows and

    columns of first matrix");

    m = in.nextInt();

    n = in.nextInt();

    int first[][] = new int[m][n];

    System.out.println("Enter the elements of first

    matrix");

    for ( c = 0 ; c < m ; c++ )

    for ( d = 0 ; d < n ; d++ )

    first[c][d] = in.nextInt();

  • 8/13/2019 Practical File of Web Developement

    33/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    31

    System.out.println("Enter the number of rows and

    columns of second matrix");

    p = in.nextInt();

    q = in.nextInt();

    if ( n != p )

    System.out.println("Matrices with entered orders

    can't be multiplied with each other.");

    else

    {

    int second[][] = new int[p][q];

    int multiply[][] = new int[m][q];

    System.out.println("Enter the elements of

    second matrix");

    for ( c = 0 ; c < p ; c++ )

    for ( d = 0 ; d < q ; d++ )

    second[c][d] = in.nextInt();

    for ( c = 0 ; c < m ; c++ )

    {

    for ( d = 0 ; d < q ; d++ )

    {

  • 8/13/2019 Practical File of Web Developement

    34/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    32

    for ( k = 0 ; k < p ; k++ )

    {

    sum = sum +

    first[c][k]*second[k][d];

    }

    multiply[c][d] = sum;

    sum = 0;

    }

    }

    System.out.println("Product of entered

    matrices:-");

    for ( c = 0 ; c < m ; c++ )

    {

    for ( d = 0 ; d < q ; d++ )

    System.out.print(multiply[c][d]+"\t");

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

    }

    }

    }

    }

  • 8/13/2019 Practical File of Web Developement

    35/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    33

    OUTPUT

  • 8/13/2019 Practical File of Web Developement

    36/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    34

    PROGRAM NO. 15Show the Life Cycle of an Applet

    importjava.applet.Applet;

    importjava.awt.Graphics;

    importjava.awt.*;

    /*

    * Applet can either run by browser or appletviewer application.

    * Define tag within comments as given below to speed up

    * the testing.

    */

    public class AppletLifeCycleExample extends Applet

    {

    Label l1,l2,l3,l4,l5;

    public void init()

    {

    super.init(); //init method is called first.

    // It is used to initialize variables and called only once.

    l1=new Label("INSIDE init()");

    add(l1);

    }

    public void start()

    {

    super.start();

    //start method is the second method to be called.

    // start method is called every time the applet has been stopped.

    l2=new Label("INSIDE Start()");

    add(l2);

  • 8/13/2019 Practical File of Web Developement

    37/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    35

    }

    public void stop()

    {

    super.stop();

    //stop method is called when the the user navigates away from

    // html page containing the applet.

    l3=new Label("INSIDE stop()");

    add(l3);

    }

    public void paint(Graphics g)

    {

    super.paint(g);

    //paint method is called every time applet has to redraw its output.

    l4=new Label("INSIDE paint()");

    add(l4);

    }

    public void destroy()

    {

    super.destroy();

    //destroy method is called when browser completely removes

    //the applet from memeory. It should free any resources initialized

    //during the init method.

    }

    }

    Description

    Each Java applet goes through a sequence of stages. They are created (initialized), displayed(painted),paused while off screen (stopped, started) and finally removed (destroyed) when

    over.

  • 8/13/2019 Practical File of Web Developement

    38/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    36

    Initialization occurs when the applet is first loaded. Tasks performed here are creatingobjects, setting initial state, loading images, fonts, etc. and setting parameters. The methodused is init()

    Display is how things are drawn on screen whether it is text, graphics or background.Redisplay occurs many time through the life of an applet. The method used is paint(Graphicsg).

    Stopping occurs when one leaves a page that contains a running applet. Threads normallycontinue running but can be manually stopped. The method used is stop().

    Starting occurs after initialization and after stops occur. Tasks include starting threads,sendingmessages to helper objects, or to tell the applet to start running. The method used isstart().

    Destruction cleans up an applet before the browser exits. Tasks include thread stopping.Normally the method destroy() is not overridden.

  • 8/13/2019 Practical File of Web Developement

    39/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    37

    OUTPUT

  • 8/13/2019 Practical File of Web Developement

    40/41

    PRACTICALFILE OF WEB DEVELOPMENT

    PANKAJGILL 11/CSE/168

    38

    PROGRAM NO. 16Write a program to show a simple Applet

    importjava.applet.*;

    importjava.awt.*;

    /**/

    public class A extends Applet

    {

    Label lb;

    public A()

    {

    lb=new Label("HELLO APPLET");

    add(lb);

    }

    }

  • 8/13/2019 Practical File of Web Developement

    41/41

    PRACTICALFILE OF WEB DEVELOPMENT

    OUTPUT