Lab Manual CSE2006
Lab Manual CSE2006
(SCOPE)
Programming in Java
Lab Manual (CSE2006)
Slot :A24+F22
1
TABLE OF CONTENTS
1 Bonafide Certificate 3
2
SCHOOL OF COMPUTING SCIENCE AND ENGINEERING
BONAFIDE CERTIFICATE
____________
REGISTER NUMBER
2 4 B C E 1 0 4 7 4
3
EXPERIMENT EVALUATION SUMMARY
Marks Faculty
S. No Date Experiment
(50) Signature
4
13 21/09/2025 Write a java Program to implement multithreading
by extending Thread class
5
EX. NO. 1 Program to implement constructor in java.
Aim:
To study and implement the concept of constructors in Java by creating objects and initializing
values automatically without explicitly calling methods.
Pseudocodes:
Start
Define class Student
Declare variables name and age
Define constructor with parameters name and age
Initialize variables using constructor
Define method display to print name and age
In main method:
Create object of Student class by passing values
Call display method
Stop
Coding:
class Student {
String name;
int age;
Student(String n, int a) {
name = n;
age = a;
6
}
void display() {
s1.display();
7
EX. NO. 2 Program to implement Class concept in java.
Aim:
To write a Java program that demonstrates the concept of a class by defining attributes and
methods, and then creating objects to access them.
Pseudocodes:
Start
Define class Car
Declare variables brand and price
Define method setData to assign values to brand and price
Define method display to print brand and price
In main method:
Create object of Car class
Call setData method with values
Call display method
Stop
Coding:
class Car {
String brand;
int price;
brand = b;
price = p;
8
}
void display() {
// Setting values
c1.setData("Toyota", 2000000);
// Displaying values
c1.display();
9
EX. NO. 3 Program to implement method overloading by using static method in java.
Aim:
To write a Java program that demonstrates method overloading using static methods,
showing how multiple methods with the same name can accept different parameters.
Pseudocodes:
Start
In main method:
Stop
Coding:
class MathOperation {
return a + b;
10
// Static method with three integers
return a + b + c;
return a + b;
11
EX. NO. 4 Program to implement method overloading in single class in java.
Aim:
To write a Java program that demonstrates method overloading in a single class, where multiple
methods share the same name but differ in parameter lists.
Pseudocodes:
Start
In main method:
Stop
Coding:
class Calculator {
return a * b; }
12
// Method with three integers
return a * b * c;
return a * b;
13
EX. NO. 5 Program to implement simple inheritance in java.
Aim:
To write a Java program that demonstrates the concept of simple inheritance, where a child
class inherits properties and methods from a parent class.
Pseudocode:
Start
In main method:
Call showStudent
Stop
Coding:
// Parent class
class Person {
String name;
int age;
14
// Method to set person data
name = n;
age = a;
void display() {
int studentId;
studentId = id;
void showStudent() {
15
display(); // calling parent method
// Setting values
s1.showStudent();
16
EX. NO. 6 Program to implement method overriding in java.
Aim:
To write a Java program that demonstrates method overriding, where a child class provides
a specific implementation of a method already defined in the parent class.
Pseudocode:
Start
In main method:
Stop
Coding:
// Parent class
class Animal {
// Method to be overridden
void sound() {
17
// Child class
// Overriding method
@Override
void sound() {
a.sound();
d.sound();
18
EX. NO. 7 Call base class constructor using super keyword in java.
Aim:
To write a Java program that demonstrates calling a base class constructor from a derived
class using the super keyword to initialize inherited properties.
Pseudocode:
Start
Define constructor that uses super to call base class constructor and initialize studentId
In main method:
Call showStudent
Stop
Coding:
// Base class
class Person {
String name;
int age;
19
// Constructor
Person(String n, int a) {
name = n;
age = a;
void display() {
// Derived class
int studentId;
// Constructor
studentId = id;
void showStudent() {
20
System.out.println("Student ID: " + studentId);
// Displaying details
s1.showStudent();
21
EX. NO. 8 cCall base class method using super keyword in java.
Aim:
To write a Java program that demonstrates calling a base class method from a derived class
using the super keyword to access overridden methods.
Pseudocode:
Start
In main method:
Stop
Coding:
// Base class
class Person {
String name;
int age;
void display() {
22
System.out.println("Name: " + name);
Person(String n, int a) {
name = n;
age = a;
// Derived class
int studentId;
// Constructor
studentId = id;
@Override
void display() {
23
}
// Displaying details
s1.display();
24
EX. NO. 9 Run Time Polymorphism Using Dynamic Dispatch
Aim:
To write a Java program that demonstrates run-time polymorphism using dynamic method
dispatch, where a parent class reference calls an overridden method of a child class.
Pseudocodes:
Start
In main method:
Stop
Coding:
// Parent class
class Animal {
// Method to be overridden
void sound() {
// Child class
25
// Overriding method
@Override
void sound() {
a.sound();
26
EX. NO. 10 Java Program Using Array
Aim:
To write a Java program that demonstrates the use of arrays by storing multiple values in a
single variable and performing operations on them.
Pseudocodes:
Start
In main method:
Stop
Coding:
class ArrayExample {
System.out.println(numbers[i );
27
}
28
EX. NO. 11 Java Program to Implement Abstract Class
Aim:
To write a Java program that demonstrates the use of an abstract class by declaring abstract
methods and providing their implementation in the derived class.
Pseudocodes:
Start
In main method:
Stop
Coding:
// Abstract class
// Abstract method
// Derived class
double radius;
29
// Constructor to initialize radius
Circle(double r) {
radius = r;
@Override
void area() {
c.area();
30
EX. NO. 12 Java Program to Implement Interface
Aim:
To write a Java program that demonstrates the use of an interface by declaring abstract
methods in the interface and implementing them in a class.
Pseudocodes:
Start
In main method:
Stop
Coding:
// Interface
interface Vehicle {
void run();
@Override
31
System.out.println("Bike is running");
b.run();
32
EX. NO. 13 Java Program to Implement Multithreading by Extending Thread Class
Aim:
Pseudocodes:
Start
In main method:
Stop
Coding:
String threadName;
MyThread(String name) {
threadName = name;
@Override
33
public void run() {
// Starting threads
t1.start();
t2.start();
34
35
EX. NO. 14 Java Program to Fetch Data from Database Using JDBC-ODBC Bridge
Aim:
To write a Java program that demonstrates fetching data from a database using the JDBC-
ODBC bridge by establishing a connection, executing a query, and displaying results.
Pseudocodes:
Start
Stop
Coding:
import java.sql.*;
class FetchDataJDBC {
ResultSet rs = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
36
// Establish connection (DSN = MyDatabase)
con = DriverManager.getConnection("jdbc:odbc:MyDatabase");
// Create Statement
stmt = con.createStatement();
// Execute query
// Display data
System.out.println("Roll No\tName\tAge");
while(rs.next()) {
System.out.println(rs.getInt("rollno") + "\t" +
rs.getString("name") + "\t" +
rs.getInt("age"));
} catch(Exception e) {
} finally {
37
Sample Input and Output:
38
EX. NO. 15 Java Program to Calculate Factorial Using Loop
Aim:
To write a Java program that calculates the factorial of a number entered by the user using
looping statements such as for or while.
Pseudocodes:
Start
In main method:
Initialize factorial as 1
Display factorial
Stop
Coding:
import java.util.Scanner;
class Factorial {
39
int num = sc.nextInt();
int factorial = 1;
factorial *= i;
// Display factorial
40
EX. NO. 10 Java Program Using I/O Streams
Aim:
To write a Java program that demonstrates the use of input and output streams to read data
from the user and write it to a file.
Pseudocodes:
Start
In main method:
Stop
Coding:
import java.io. *;
class IOStreamsExample {
try {
41
// Convert string to bytes and write to file
fos.write(data.getBytes());
fos.close();
int i;
System.out.print((char)i);
fis.close();
} catch(Exception e) {
42