Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

Page |1

RAJA BALWANT SINGH COLLEGE,


AGRA
Session 2019-20

Assignment
Of
Java Programming And
Dynamic Webpage Design
Submitted To:
Mr. Vivek Sir Submitted By:
Utkarsh Jindal
BCA 5th Sem.
Page |2

Acknowledgement
I would like to express my special thanks of
gratitude to my teacher Mr. VIVEK SIR who
gave me the golden opportunity to do this
wonderful project on the topic Java
Programming And Dynamic Webpage
Design, which also helped me in doing a lot of
Research and i came to know about so many new
things I am really thankful to them.
Secondly i would also like to thank my parents
and friends who helped me a lot in finalizing this
project within the limited time frame.
Page |3

INDEX
PROGRAM PAGE NO.
Addition of two no. 4
Demonstration of Wrapper Class 5
Demonstrate For Each Loop 6
Check a no. is prime or not 7
Demonstrate Anonymous Object 9
Show all type of Constructor 10
Demonstrate Static variable and static method 11
Demonstrate the use of this keyword 13
Demonstrate Inheritance 14
Demonstrate method Overloading 16
Demonstrate method Overriding 17
Demonstrate the use of super keyword 18
Show the use of abstract class 19
Show the use of interface 20
Show the use of package 21
Demonstrate Exception handling 22
Show the use of thread 23
Demonstrate list in HTML 24
Demonstrate frames in HTML 25
Demonstrate tables in HTML 26
Demonstrate Applet 28
Page |4

Program to addition of two numbers


import java.util.Scanner;

class Add

public static void main(String args[])

int a, b;

System.out.println("Enter two Number to calculate their sum");

Scanner in = new Scanner(System.in);

a = in.nextInt();

b = in.nextInt();

System.out.println("Sum of the integers = " + (a+b));

Output:
Page |5

Program to demonstrate wrapper


class
public class WrapClass

public static void main(String args[])

int a=75;

//Example of Autoboxing

Integer i=Integer.valueOf(a);

Integer j=a;

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

Output:
Page |6

Program to demonstrate for each


loop
class ForEachLoop

public static void main(String[] args)

String[] Names = {"Amit", "Raju", "Sanjay", "Yash", "Utkarsh"};

for (String name : Names)

System.out.println(name);

Output:
Page |7

Program to check a no is prime or not


import java.util.Scanner;

class PrimeNumber

public static void main(String[] args)

int temp;

boolean isPrime=true;

Scanner scan= new Scanner(System.in);

System.out.println("Enter any number:");

int num=scan.nextInt();

scan.close();

for(int i=2;i<=num/2;i++)

temp=num%i;

if(temp==0)

isPrime=false;

break;

if(isPrime)

System.out.println(num + " is a Prime Number");


Page |8

else

System.out.println(num + " is not a Prime Number");

Output:
Page |9

Program to Demonstrate anonymous object


class AnonymousObject {

public String add(int x, int y){

return "Addition is: " + (x+y);

public static void main(String[] args) {

System.out.println(new AnonymousObject().add(52,94));

Output:
P a g e | 10

Program to show all types of


Constructors
class ConstructorsExample

ConstructorsExample()

System.out.println("Default or Non-Parameterized Constructor");

ConstructorsExample(float a, float b)

{
System.out.println("Parameterized Constructor");
System.out.println("Sum :"+(a+b));
}
public static void main(String[] args)

ConstructorsExample ce = new ConstructorsExample();

ConstructorsExample ce1 = new ConstructorsExample(13,85);

Output:
P a g e | 11

Program to demonstrate static


variable and static method
class Student

String name;

int rollNo;

static String ColgName;

static int counter = 0;

public Student(String name) {

this.name = name;

this.rollNo = setRollNo();

static int setRollNo() {

counter++;

return counter;

static void setColg(String name){

ColgName = name ;

void getStudentInfo(){

System.out.println("name : " + this.name);

System.out.println("rollNo : " + this.rollNo);

System.out.println("ColgName : " + ColgName);


P a g e | 12

public class StaticExample

public static void main(String[] args)

Student.setColg("RBS");

Student s1 = new Student("Shivam");

Student s2 = new Student("Raja");

s1.getStudentInfo();

s2.getStudentInfo();

Output:
P a g e | 13

Program to demonstrate the use of


‘this’ keyword
class MyClass {

int example;

MyClass(int example){

this.example = example;

public static void main(String[] args) {

MyClass obj = new MyClass(48);

System.out.println("Value obj hold = " + obj.example);

Output:
P a g e | 14

Program to Demonstrate inheritance


class AClass

AClass()

System.out.println("Class--A");

class BClass extends AClass

BClass()

System.out.println("Class--B");

class CClass extends AClass

CClass()

System.out.println("Class--C");

}
P a g e | 15

class Inheritance extends BClass

Inheritance()

System.out.println("Inheritance");

public static void main(String args[]){

Inheritance obj = new Inheritance();

CClass obd1 = new CClass();

Output:
P a g e | 16

Program to demonstrate method


overloading
class Method
{
public void display(char c) {
System.out.println(c);
}
public void display(char c, int num) {
System.out.println(c + " "+num);
}
}
class Overloading
{
public static void main(String args[]) {
Method obj = new Method();
obj.display('U');
obj.display('J',10);
}

}Output:
P a g e | 17

Program to demonstrate method


overriding
class Human{
public void eat()
{
System.out.println("Human is eating");
}
}
class Boy extends Human{
public void eat(){
System.out.println("Boy is eating");
}
public static void main( String args[]) {
Boy obj = new Boy();
obj.eat();
}
}

Output:
P a g e | 18

Program to demonstrate the use of


‘supper’ keyword
class AClass
{
AClass() {
System.out.println("A is created");
}
}
class BClass extends AClass
{
BClass(){
super();
System.out.println("B is created");
}
}
class SupperExample
{
public static void main(String args[]){
BClass obj = new BClass();
}
}

Output:
P a g e | 19

Program to show the use of abstract


class
abstract class Shape{
abstract void draw();
}
class Rectangle extends Shape{
void draw(){
System.out.println("drawing rectangle");
}
}
class Circle1 extends Shape{
void draw(){
System.out.println("drawing circle");
}
}
class Abstraction{
public static void main(String args[]){
Shape s=new Circle1();
s.draw();
}
}

Output:
P a g e | 20

Program to show the use of interface


interface Polygon {

void getArea(float length, float breadth);

class Rectangle implements Polygon {

public void getArea(float length, float breadth) {

System.out.println("The area of the rectangle is " + (length * breadth));

class InterfaceExample {

public static void main(String[] args) {

Rectangle r1= new Rectangle();

r1.getArea(7,4);

Output:
P a g e | 21

Program to show the use of package


package pack1;

public class PackageExmaple

public static void main(String args[])

System.out.println("Welcome to class PackageExmaple in pack1");

Output:
P a g e | 22

Program to demonstrate exception


handling
import java.io.*;

public class ExcepExample {

public static void main(String args[]) {

try {

int a[] = new int[2];

System.out.println("Access element three :" + a[3]);

catch (ArrayIndexOutOfBoundsException e) {

System.out.println("Exception thrown :" + e);

System.out.println("Out of the block");

Output:
P a g e | 23

Program to show the use of thread


class Thread2 implements Runnable

public void run()

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

public static void main(String args[])

Thread2 t2=new Thread2();

Thread t =new Thread(t2);

t.start();

Output:
P a g e | 24

Program to demonstrate lists in


HTML
<!DOCTYPE html>
<html>
<body>
<h2>Unordered List with Circle Bullets</h2>
<ul>
<li>Apple</li>
<li>Orange</li>
<li>Banana</li>
<li>Grapes</li>
</ul>
<h2>Ordered List with Numbers</h2>
<ol type="1">
<li>Car</li>
<li>Bike</li>
<li>Scooter</li>
</ol>
</body>
</html>

Output:
P a g e | 25

Program to demonstrate the use of


frames in HTML
<!DOCTYPE html>
<html>
<head>
<title>HTML Frames</title>
</head>
<frameset rows = "40%,40%,40%">
<frame name = "top" src = "lists.html" />
<frame name = "main" src = "lists.html" />
<frame name = "bottom" src = "lists.html" />
<noframes>
<body>Your browser does not support frames.</body>
</noframes>
</frameset>
</html>

Output:
P a g e | 26

Program to demonstrate the use of


tables in HTML
<!DOCTYPE html>

<html>

<head>

<title>HTML Table </title>

</head>

<body>

<table border = "1" width = "300" height = "200">

<tr>

<th>Roll No.</th>

<th>Name</th>

<th>Marks</th>

</tr>

<tr>

<td>101</td>

<td>Raman</td>

<td>76</td>

</tr>

<tr>

<td>102</td>

<td>Dhruv</td>

<td>61</td>
P a g e | 27

</tr>

<tr>

<td>103</td>

<td>Utkarsh</td>

<td>85</td>

</tr>

</table>

</body>

</html>

Output:
P a g e | 28

Program to demonstrate Applet


import java.applet.Applet;

import java.awt.Graphics;

public class HelloWorld extends Applet

@Override

public void paint(Graphics g)

g.drawString("Hello World", 20, 20);

//html file

<html>

<head>

<title>Applet Demo</title>

</head>

<body>

<applet code="HelloWorld.class" width="300" height="300">

</applet>

</body>
P a g e | 29

</html>

Output:

You might also like