0% found this document useful (0 votes)
8 views22 pages

Oops Lab Manual Jan 03, 2024

The document outlines a series of Java programming experiments conducted by students at Aryan Institute of Engineering & Technology, covering various topics such as printing messages, calculating areas, checking even/odd numbers, and implementing inheritance. Each experiment includes sample code, expected output, and brief descriptions of the concepts being demonstrated. The experiments range from basic programming tasks to more advanced topics like exception handling and multithreading.

Uploaded by

Bimal Pattnaik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views22 pages

Oops Lab Manual Jan 03, 2024

The document outlines a series of Java programming experiments conducted by students at Aryan Institute of Engineering & Technology, covering various topics such as printing messages, calculating areas, checking even/odd numbers, and implementing inheritance. Each experiment includes sample code, expected output, and brief descriptions of the concepts being demonstrated. The experiments range from basic programming tasks to more advanced topics like exception handling and multithreading.

Uploaded by

Bimal Pattnaik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

(OARYAN NSTTUTE OF ENGINEERNG &TECHNOLOGY

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING
EXPERIMENT NO:-1 (A)

NAME OF THE EXPERIMENT:


IWrite a java program to print any message
class Hello

public static void main(String[] args)


System.out.println("Hello world");

OUTPUT:
Hello

0OP USING JAVA


3 | Page
LABORATORY
oARYAN NSTUTE OF ENGINEERING &TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE AND
ENGINEERING
EXPERIMENT -2(A)

2(A).NAME OF THE EXPERIMENT:

I/Compute area of Circle.


public class ComputeArea {
public static void main(String[] args) {
double radius; // Declare radius
double area; //Declare area
IlAssign aradius
radius =20;// radius is now 20
I/Compute area
area = radius * radius * 3.14159:
I/ Display results
System.out.println("The area for the circle of radius "+
radius + " is " + area);

OUTPUT:
The oe o fox +e
1a56. 636.
ciC Ie f

OOP USING JAVA


LABORATORY
5|Page
ARYAN
NSTVEE OF ENGINEERINGA TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

2(B)NAME OF THEEXPERIMENT:

I/Enter any number and check whether it is even or odd using If Statement.
import java.util.Scanner;
public class SimplelfDemo{
public static void main(String] args) {
Scanner input =new Scanner(System.in);
System.out.printn("Enter an integer: ");
int number = input.nextInt();
if (number % ==)

System.out.printin("Even");
else

System.out.println("Odd");
}

OUTPUT:
&ntex
integes
odd

Even

OOP USING JAVA


7| Page LABORATORY
9ARYAN NSTTUIEOF ENGINEERING &TECHNOLOGY
DEPARTMENT OFCOMPUTER SCIENCE AND ENGINEERING
2(C).NAME OF THE EXPERIMENT:
llelse if ladder

public class score

public static void main(Stringl]args)


double score-87.5;
if (score >=90.0)
grade = 'A':
else if (score >=80.0)
grade = 'B';
else if (score >= 70.0)
grade = 'C;
else if (score >= 60.0)
grade = 'D';
else
grade = 'F':
System.out.printin("Grade'+grade);

OUTPUT:
Gde B

OOP USING JAVALABORATORY


9 | Page
aYAN ARYAN
NSMTE OF ENGINEERNG& TECHNOLOGY
DEPARTMENT OFCOMPUTER SCIENCE AND ENGINEERING
EXPERIMENT NO:-3(A).

3(A).NAME OF THE EXPERIMENT:


IISum of numbers using do-while loop
import java.util.Scanner;
public class TestDoWhile

public static void main(Stringl] args) {


int data;
int sum =0;
Scanner data= new Scanner(System.in);
I/Keep reading data until the input is 0
do

System.out.print( "Enter an integer (the input ends if it is 0): ");


data = input.nextInt();
sum += data:
while (data !=();
System.out.printin("The sum is" +sum);
}

OUTPUT:
Entes n integes (the inat eds if it i5 o)3
©ntes on inte aex(+he in Pot end5 if it is o)!5
Entes an 1Heges Cthe inPt endsiE i+ iS o):6
an inteAex (the int eds iE it iS o).o
enter

0OP USING JAVA LABORATORY


11 | Page
9)ARYAN
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

EXPERIMENT NO:-3(B)
BANAME OF TIE EXPERIMENT:

ctorialof uumber using for loop.


pubie class tactorial
publie statie void main (String [] args)
int nunm 5;

long tuctorial 1;
for (int i= 1; i<=num; ++i)

Il factorial = factorial * i;
factorial *= i;

System.out.println("factorial of "+num+'is "+ factorial):

OUTPUT:
foctogil

OOP USING JAVA LABORATORY


13 | Pa ge
9ARYAN NSTNITEOE ENGINEERINGLTECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

EXPERIMENT NO:-3( C)
3(C)NAME OF THE EXPERIMENT:
|/Fibonacci Series using while loop.
class Fibo{
public static void main (String [] args)
int i= 1, n = 10, firstTerm = 0, secondTerm = 1:
System.out.println("Fibonacci Series till " +n+" tens:"):

while (i<=n) {
System.out.print(firstTerm + ", "):

int nextTernm = firstTerm + secondTerm:


firstTerm = secondTerm:
secondTerm = nextTen:

it+;

OUTPUT:
fibon acGi Gesies +il lo +exm:
0l,l,2, 3, S, 8,13,2,34

0OP USING JAVA LABORATORY


15 | Page
ARYAN
NSTIJTE OF ENGINEERING&TECHNOLOGY
DEPARTIMENT OF COMPUTER SCIENCE AND
EXPERIMENT NO;-4(A)
ENGINEERING
4(A).NAME OF THE EXPERIMENT
I/Initialization through Reference variable
class Student
int id;
String name;

class TestStudent2{
public static void main (String args[]{
Student sl=new Student ():
sl.id=111;
sl.name="Chitta";
System.out.printn(sl.id+" "*sl.name);/printing members with awhite space
}

OUTPUT:

0OP USING JAVA LABORATORY


17 |P age
e ARYAN NSIEOF ENGINEERNG &TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERINC

EXPERIMENT NO;-4(B)

4(B).NAME OF THE EXPERIMENT:


I/Initialization through a method
class Rectangle
int length;
int width;
void insert (int 1, int w) {
length=1;
width=w;
}
void calculateArea({System.out.println(length*width):}
}
class TestRectanglel{
public static void main (String args[]) {
Rectangle rl=new Rectangle ();
Rectangle r2-new Rectangle ();
rl. insert (11,5);
r2. insert (3,15);
rl. calculateArea ();
r2. calculateArea ();

OUTPUT:

OOP USING JAVA LABORATORY


19 | P a ge
ARYAN
NSmIE OF ENGINEERING ATECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE AND

EXPERIMENT NO:-5(A)
ENGINEERING

5(A).NAME OF THE EXPERIMENT:


I/Data abstraction
abstract class Bank{
abstract int getRateOflnterest (0:

class SBI extends Bank {


int getRateOfinterest () {return 7;}

class PNB extends Bank {


int getRateOfInterest 0 {return 8;)

class TestBank
public staticvoid main (String args){
Bank b;
b=new SBI ():
System.out.printin("Rate of Interest is: "+b. getRateOfinterest 0 +" %");
b=new PNB (0;
System.out,printn("Rate of Interest is: "+b. getRateOflnterest (0 +" %")%

OUTPUT:
Rote of IntBXe 5+ i5 7.
Ro+e oe Tntexe6t i5:&.

OOP USING JAVA LABORATORY


21 | P a ge
9ARYAN NSTUTE OF ENGINEER0NG &TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

EXPERIMENT NO:-5(B)

5(B).NAME OF THE EXPERIMENT:


I/Single inheritance

class Animal {
void eat ()
{System.out.println('eating.. ");}
class Dog extends Animal
void bark 0
{System.out.printin("barking.."):}
class TestInheritance{
public static void main (String args[){
Dog d-new Dog ();
d.bark0:
d.eat();
}}

OUTPUT:

bozuing.
eoting -

0OP USING JAVA LABORATORY


23| Page
9ARYAN NSTTIUT:ORENGINEERING &
TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE AND
EXPERIMENT NO: 5(C)
ENGINEERING
5( C)NAME OFTHE EXPERIMENT:
IIMultilevel inheritance

class Animal {
void eat () (System.out.printn("'eating...")}

class Dog extends Animal {


void bark () {System.out.printin("barking..");}

class BabyDog extends Dog


void weep (0 {System.out.printn("weeping..");}
}
class Testlnheritance2
public static void main (String args ){
BabyDog d-new BabyDog);
d.weep);
d.bark ();
d.eat();

OUTPUT:
weeeing
bosking
eating- ---

00P USING JAVA LABORATORY


25|P age
O ARYANWSTINUTE OF ENGINEERING TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERINC
EXPERIMENT NO0:-5(D)

5D).NAME OF THE EXPERIMENT:


IIMultiple inheritance

interface Printable {
void print );
interface Showable
void show 0;

class Aimplements Printable, Showable


public void print () (System.out.println("Hello"):}
public void show ) {System.out.printin("Welcome");}

public static void main (String args () {


A obj = new A);
obj.print ();
obj. show (0;

OUTPUT:
Helo
welcome

0OP USING JAVA LABORATORY


27 | Page
ARYAN
WSTNITE OF ENGINEERING &TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE AND
EXPERIMENT NO:-5E)
ENGINEERING

5(E).NAME OF THE EXPERIMENT:


IPolymorphism

class Bank{
float getRateOfInterest ) {return 0;}
}
class SBI extends Bank {
float getRateOfInterest () {return 8.4f;)

class ICICl extends Bank


float getRate0fInterest () {return 7.3£;}

class AXIS extends Bank {


float getRateOfInterest (0 {return 9.7)

class TestPolymorphism{
public static void main (String args ){
Bank b:;
b=new SBI ();
System.out.println("SBIRate of Interest: "+b,getRateOfinterest():
b=new ICICI ():
System.out.println("1CICI Rate of Interest: "+b. getRateOflnterest ();
b=new AXIS 0;
System.out.printn("AXIS Rate of Interest: "+b. getRateOfinterest ());

OUTPUT:
S8I Rote of TntexeS+ :3-4
IcICI Rote of Inte6e5t : 3
AxIS Rote of Inteze5t 97

0OP USING JAVA LABORATORY


29 | Page
9 ARYAN NSTUTE OFENGINEERING TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
EXPERIMENT NO:-6(A)
6(A).ONAME OF THE EXPERIMENT:
ljava thread example by extending thread class
class Multiextends Thread {
public void run (){
System.out.println("thread is running..");

public static void main (String args[]){


Multitl=ew Multi 0;
tl. start ();

OUTPUT:

(DNAME OF THE EXPERIMENT:


Il Java Thread Example by implementing Runnable interface
class Multi3 implements Runnable {
public void run () {
System.out.printn("thread is running..");

public static void main (String args [1){


Multi3 ml=new Multi3);
Thread tl =new Thread(ml ); I/Using the constructor Thread (Runnabler)
tl. start (0;

OUTPUT:
+h Bod 15 Kunn i ng

0OP USING JAVA LABORATORY


31 | Pa g e
eARYAN
COMPUTER
NSTTEOF ENGINEERING &TECHNOLOGY
DEPARTMENT OF SCIENCE AND
ENGINEERING
EXPERIMENT NO:-6(B)

6(B).NAME OF THE EXPERIMENT:


I/Exception Handling
public class JavaExceptionExample {
public static void main (String args 0){
try {
llcode that may raise exception
int data=100/0;
}catch (ArithmeticException e) {System.out.println(e);:}
l/rest code of the program
System.out.println("rest of the code...");

OUTPUT:

G,nGep+ion in +h3eod moin Jawo. lona Adu


Meto

OOP USING JAVA LABORATORY


33| P a ge
eARYAN NSTITUTEOF ENGINEERING &TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERINC
EXPERIMENT NO:-6(C)

6( C).NAME OF THE EXPERIMENT:


lIApplet

import java.applet.Applet;
import java.awt.Graphics;
publicclass First extends Applet {

public void paint (Graphics g) {


g. drawstring("welcome", 150,150);

OUTPUT:
Caelcome

OOP USING JAVA LABORATORY


35 | P a ge
eARYAN NSTUE OF ENGINEERING& TECHNOLOGY
ENGINEERINC
DEPARTMENT OF COMPUTER SCIENCE AND
EXPERIMENT NO:-7(A)

7(A)NAME OF THE EXPERIMENT:


Ilwrapper class example: primitive to wrapper
I/Autoboxing example of int to Integer
public class WrapperExamplel {
public static void main (String args [)) {
I/Converting int into Integer
int a-20;
Integer i=Integer.valueOf(a);//converting int into Integer explicitly
Integer j-a;//autoboxing, now compiler will write Integer.value Of(a) internally
System.out.println(a+" "tit" "j);
3}

OUTPUT:

OOP USING JAVA LABORATORY


37 | Pa ge
OARYAN NSTITUTE OF ENGINEERING &TECHNOLOGY

DEPARTIMENT OF COMPUTER SCIENCE AND ENGINEERING


EXPERIMENT NO:-7(B)

7B).NAME OF THE EXPERIMENT:


IWrapper class Example: Wrapper to Primitive
IIUnboxing example of Integer to int
public class WrapperExample2{
public static void main (String args |){
IIConverting Integer to int
Integer aFnew Integer (3);
int i=a.intValue()://converting Integer to int explicitly
int j-a;//unboxing, now compiler will write a.intValue() internally

System.out.println(a+" "tit" "tj);

OUTPUT:
333

OOP USING JAVA LABORATORY


39 | P a ge
O ARYAN WSTTUTE OF ENGINEERNG &TECHNOLOGY

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


EXPERIMENT NO:-1 (Beyond Syllabus)

1.NAME OF THE EXPERIMENT:


I/Design a National flag using applet.

import java.awt.*;
import java.applet.*;
public class India Flag extends Applet

public void paint(Graphics g)

g.setColor(Color. blue);
g.fillRect(50,20,5,300);
g.setColor(Color.black);
g.drawRect(50, 18,3,300);
g.setColor(Color.orange);
g.fillRect(55,20,120,30);
g.setColor(Color.black):
g.drawRect(55,20,118,28);
g.setColor(Color.green);
g.fillRect(55,80,119,30);
g.setColor(Color.black);
g.drawRect(55,80,117,28);
g.setColor(Color.black);
gdrawOval(100,50,30,30);

<htm|>
<head>
<head>
<body>
<applet code = "IndiaFlag. Class" width ="320" height ="480"></applet>
<body>
<htm>

0OP USING JAVALABORATORY


41| Pa ge
DEPARTMENT OF
ARYAN
INSTITUTE OF ENGINEERING &TECHNOLOGY
COMPUTER SCIENCE AND ENGINEERING

OUTPUT:

OOP USING JAVA LABORATORY


42 | Pa ge
ARYAN TECHNOLOGY
NSTIIUIE OF ENGINEER0NG &
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

OUTPUT:

0OP USING JAVA LABORATORY


47 | P age

You might also like