Practical File of Web Developement

Published on June 2016 | Categories: Topics | Downloads: 38 | Comments: 0 | Views: 299
of 41
Download PDF   Embed   Report

Practical File of Web Development for B.Tech Computer Science and Engineering Students.

Comments

Content

PRACTICAL FILE OF WEB DEVELOPMENT

PRACTICAL FILE OF WEB DEVELOPMENT
VAISH COLLEGE OF ENGINEERING

SUBMITTED TO
Mr.Kulwinder Singh Asst. Professor CSE Deptt.

SUBMITTED BY
Pankaj Gill 11/CSE/168 CSE-B

PANKAJ GILL

PRACTICAL FILE OF WEB DEVELOPMENT

INDEX
Aim
1. 2. Write a simple java program Write a program to show conversion Temperature from Celsius to Fahrenheit and Fahrenheit to Celsius Write a program to find the no and sum of all integers greater than 100 and less than 200 that are divisible by 7. Write a program to show a Grading system Write a program to print a format using * in increasing order Write a program to find out some of digits of any integer number Write a program to show the Multiplication table Write a program to show Constructor Method Write a program to show Method Overloading Write a program to show Method Overriding Write a program to show Polymorphism using Inheritance Write a program to show Inheritance Write a program to show Swapping of two Strings Write a program to show Multiplication of two Matrices Show the Life Cycle of an Applet Write a program to show a simple Applet

Page
1 2

Remarks

3.

6

4. 5. 6 7. 8. 9. 10. 11. 12. 13. 14. 15. 16.

8 10 12 14 16 18 20 22 25 27 30 34 38

PANKAJ GILL

PRACTICAL FILE OF WEB DEVELOPMENT

Write a simple java program
class Sample { public static void main(String args[]) { System.out.println("=== Hello java ===="); } }

PROGRAM NO. 1

PANKAJ GILL

1
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

OUTPUT

PANKAJ GILL

2
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

Write 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[]) 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); //throws

PROGRAM NO. 2

PANKAJ GILL

3
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT
} 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 !!!!"); } } }

PANKAJ GILL

4
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

OUTPUT

PANKAJ GILL

5
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

Write 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<=200; i++) { if (i % 7 == 0) { System.out.println(i); sum += i; } } System.out.println("Sum of all integers greater than 100 and less than 200 that are divisible by 7 is " + sum); } }

PROGRAM NO. 3

PANKAJ GILL

6
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

OUTPUT

PANKAJ GILL

7
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

Write 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 ");

PROGRAM NO. 4

Scanner cin=new Scanner(System.in); inti; i=cin.nextInt(); if(i>=81 && i<=100) { System.out.println("Grade=A"); } else if(i>=61 && i<=80) { System.out.println("Grade=B"); } else if(i>=41 && i<=60) { System.out.println("Grade=C"); } else if(i>=0 && i<=40) { System.out.println("Grade=D"); } } }

PANKAJ GILL

8
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

OUTPUT

PANKAJ GILL

9
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

Write a program to print a format using * in increasing order
class Star { public static void main(String args[]) { inti,j; for(i=1;i<10;i++) { System.out.println(""); for(j=0;j<i;j++) { System.out.print("*"); } } } }

PROGRAM NO. 5

PANKAJ GILL

10
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

OUTPUT

PANKAJ GILL

11
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

Write 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); } }

PROGRAM NO. 6

PANKAJ GILL

12
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

OUTPUT

PANKAJ GILL

13
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

Write 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<=10;i++) { System.out.println(n+"*"+i+"="+(n*i)); } } }

PROGRAM NO. 7

PANKAJ GILL

14
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

OUTPUT

PANKAJ GILL

15
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

Write a program to show Constructor Method
classRect { intlength,breadth; publicRect() { length=0 ; breadth=0 ; System.out.println("Default constructer is fired"); } publicRect(intl,int b) { 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); } }
//Parametrised( Double Argumented) Constructer

PROGRAM NO. 8

//Default Constructer

PANKAJ GILL

16
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

OUTPUT

PANKAJ GILL

17
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

Write 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)); } }

PROGRAM NO. 9

PANKAJ GILL

18
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

OUTPUT

PANKAJ GILL

19
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

Write a program to show Method Overriding
class A { public void Show() { System.out.println("A CAN DO HORSE RIDING BUT CANNOT RIDE A BIKE"); } } class B extends A { public void Show() { System.out.println("B CAN RIDE A BIKE BUT DOESNOT KNOW HORSE RIDING"); System.out.println("A class's show() method is overridden by B class's show() method"); } // Here the Show() method of parent class A is Overridden by Show() method of Child class B.. } class Test { public static void main(String args[]) { B obj=new B(); obj.Show(); } }

PROGRAM NO. 10

PANKAJ GILL

20
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

OUTPUT

PANKAJ GILL

21
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

Write a program to show Polymorphism using Inheritance
Polymorphism means the ability of a single variable of a given type to be used to reference objects ofdifferent types, and automatically call the method that is specific to the type of object the variable references. The benefit of polymorphism is that it is very easy to add new classes of derived objects without breaking the calling code that uses the polymorphic classes or interfaces. When you send a message to an object even though you don’t know what specific type it is, and the right thing happens, that’s called polymorphism. The process used by object-oriented programming languages to implement polymorphism is called dynamic binding. Polymorphism can be achieved by Method Overloading, Method Overriding & 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");

PROGRAM NO. 11

PANKAJ GILL

22
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT
} } 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 to Class a and class B also i.e. If we derive many classes from a base class then we can refer to any class by creating object of Derived Class (Child class).

PANKAJ GILL

23
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

OUTPUT

PANKAJ GILL

24
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

Write 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 {

PROGRAM NO. 12

} class Test { public static void main(String args[]) { Child obj=new Child(); obj.Show(); System.out.println("child has takken parent's properties"); } }

PANKAJ GILL

25
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

OUTPUT

PANKAJ GILL

26
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

Write 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(" swap(i,j); } "+i+" "+j);

PROGRAM NO. 13

PANKAJ GILL

27
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT
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);

PANKAJ GILL

28
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

Output

PANKAJ GILL

29
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

Write 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();

PROGRAM NO. 14

PANKAJ GILL

30
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT
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++ ) {

PANKAJ GILL

31
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT
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"); } } } }

PANKAJ GILL

32
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

OUTPUT

PANKAJ GILL

33
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

Show the Life Cycle of an Applet
importjava.applet.Applet; importjava.awt.Graphics; importjava.awt.*;
/* * Applet can either run by browser or appletviewer application. * Define <applet> tag within comments as given below to speed up * the testing. */

PROGRAM NO. 15

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);

PANKAJ GILL

34
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT
} 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.

PANKAJ GILL

35
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT
Initialization occurs when the applet is first loaded. Tasks performed here are creating objects, setting initial state, loading images, fonts, etc. and setting parameters. The method used 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(Graphics g). Stopping occurs when one leaves a page that contains a running applet. Threads normally continue 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 is start(). Destruction cleans up an applet before the browser exits. Tasks include thread stopping. Normally the method destroy() is not overridden.

PANKAJ GILL

36
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

OUTPUT

PANKAJ GILL

37
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

Write a program to show a simple Applet
importjava.applet.*; importjava.awt.*; /*<Applet code="A" height=200 width=200></Applet>*/ public class A extends Applet { Label lb; public A() { lb=new Label("HELLO APPLET"); add(lb); } }

PROGRAM NO. 16

PANKAJ GILL

38
11/CSE/168

PRACTICAL FILE OF WEB DEVELOPMENT

OUTPUT

PANKAJ GILL

39
11/CSE/168

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close