0% found this document useful (0 votes)
2 views39 pages

Java Lab Final

The document outlines the practical work record for a Java programming lab at Syed Ammal Arts and Science College for the academic year 2024-2025. It includes various exercises on Java concepts such as classes, constructors, inheritance, method overloading, multithreading, and JDBC connectivity, with each exercise demonstrating successful execution of Java programs. The document serves as a certification of the practical work completed by students in the Software Development department.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views39 pages

Java Lab Final

The document outlines the practical work record for a Java programming lab at Syed Ammal Arts and Science College for the academic year 2024-2025. It includes various exercises on Java concepts such as classes, constructors, inheritance, method overloading, multithreading, and JDBC connectivity, with each exercise demonstrating successful execution of Java programs. The document serves as a certification of the practical work completed by students in the Software Development department.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

SYED AMMAL ARTS AND SCIENCE COLLEGE

(Affiliated to Alagappa University - Karaikudi)


Koottampuli, Ramanathapuram - 623513

DEPARTMENT OF SOFTWARE DEVELOPMENT

JAVA programming LAB-23VSD5P1

REG NO :

NAME:

Academic Year 2024 - 2025


SYED AMMAL ARTS AND SCIENCE
COLLEGE DEPARTMENT OF SOFTWARE
DEVELOPMENT
(Affiliated to Alagappa University)

Certified a Bonafide record of practical work done on 23VSD4P1-RDBMS LAB


By Reg no:
of [Link] (Software Development)
– II year during IV semester March 2025

STAFF INCHARGE

HEAD OF THE DEPARTMENT


PRINCIPAL

Submitted to the practical examination held on


at syed ammal arts and science college , kootampuli.

INTERNAL EXAMINER EXTERNAL


EXAMINER
SNO DATE PROGRAM PAGE SIGN
NO

1 CREATING SIMPLE CLASSES AND OBJECT

2 CREATING CONSTRUCTOR AND DESTRUCTOR

3 WORKING WITH COPY CONSTRUCTOR

4 WORKING WITH PARAMETERIZED CONSTRUCTOR

5 WORKING WITH INHERITANCE

6 ILLUSTRATING METHOD OVERLOADING

7 WORKING WITH METHOD OVERRIDING

8 CREATION OF INTERFACES

9 CREATION AND IMPLEMENTATION OF PACKAGES

10 WORKING WITH THREADS

11 ILLUSTRATING MULTITHREADING

12 WORKING WITH INPUT / OUTPUT STREAMS

13 DRAWING IMAGES USING APPLET

14 JDBC CONNECTIVITY
[Link]
Date: CREATING SIMPLE CLASSES AND OBJECTS

Aim:
To create java program using simple classes and objects.

Program:
import [Link].*;
public class car1
{
String color;
String model;
int year;
void startEngine()
{
[Link]("Engine started");
}
void displayInfo()
{
[Link]("model:"+model);
[Link]("color:"+color);
[Link]("year:"+year);
}
public static void main(String[]args)
{
car1 mycar=new car1();
[Link]="red";
[Link]="lambokine";
[Link]=2025;
[Link]();
[Link]();
}
}
OUTPUT:

Result:
Thus, the above program has been executed successfully.
[Link]
Date: CREATING CONSTRUCTOR AND DECONSTRUCTOR

Aim:
To create java program using constructor and deconstructor.

Program:
import [Link].*;
class Student {
String name;
int age;
Student(String n, int a) {
name = n;
age = a;
[Link]("Constructor called: "+name+" created");
}
void display() {
[Link]("Name: "+name+", Age: "+age);
}
void destroy() {
[Link]("Destructor called: "+name+ "removed");
}
}
public class Main11 {
public static void main(String[] args) {
Student s1 = new Student("aaa",21);
[Link]();
[Link]();
[Link]("End of program");
}
}
OUTPUT:

Result:
Thus, the above program has been executed successfully.
[Link]
Date: WORKING WITH COPY CONSTRUCTOR

Aim:
To create java program using copy constructor.

Program:
import [Link] .*;
class Employee {
String name;
int id;
double salary;
Employee(String n, int i, double s) {
name = n;
id = i;
salary = s;
}
Employee(Employee e) {
name = [Link];
id = [Link];
salary = [Link];
}
void display(){
[Link]("ID: " + id + ", Name: " + name + ", Salary: " + salary);
}
}
public class work{
public static void main(String args[]) {
Employee emp1 = new Employee("aaa", 101, 50000);
Employee emp2 = new Employee(emp1);
[Link]();
[Link]();
}
}
OUTPUT:

Result:
Thus, the above program has been executed successfully.
[Link]
Date: WORKING WITH PARAMETERIZED CONSTRUCTOR

Aim:
To create java program using parameterized constructor.

Program:
import [Link].*;
class Hospital
{
String name;
String location;
int patientid;
Hospital(String n, String loc, int i)
{
name=n;
location=loc;
patientid=i;
}
void displayInfo()
{
[Link]("Hospital Name:" +name);
[Link]("Location: "+location);
[Link]("patientid:" +patientid);
[Link]("----------------------");
}
}
public class lab4
{
public static void main(String[]args)
{
Hospital h1= new Hospital("Appollo Hospital","Chennai",1);
Hospital h2=new Hospital("Government Hospital", "madurai",2);
Hospital h3=new Hospital("Sunrise Multispeciality ", "coimbatore",3);
[Link]();
[Link]();
[Link]();
}
}
OUTPUT:

Result:
Thus, the above program has been executed successfully.
[Link]
Date: WORKING WITH INHERITANCE

Aim:
To create java program using inheritance.

Program:
import [Link].*;
class Person {
String name;
int age;

void setDetails(String name, int age) {


[Link] = name;
[Link] = age;
}

void showDetails() {
[Link]("Name: " + name);
[Link]("Age: " + age);
}
}

class Student extends Person {


String studentId;

void setStudentId(String studentId) {


[Link] = studentId;
}

void showStudentInfo() {
showDetails();
[Link]("Student ID: " + studentId);
}
}
public class StudentDemo7 {
public static void main(String[] args) {
Student s1 = new Student();
[Link]("AAA", 19);
[Link]("101");
[Link]("Student Information ");
[Link]();
}
}
OUTPUT:

Result:
Thus, the above program has been executed successfully.
[Link]
Date: ILLUSTRATING METHOD OVERLOADING

Aim:
To create java program using method overloading.

Program:
import [Link].*;
class company {
void registerEmployee(String name) {
[Link]("Registered employee: " + name);
}
void registerEmployee(String name, int id) {
[Link]("Registered employee: " + name + " with ID: " + id);
}
void registerEmployee(String name, int id, String department) {
[Link]("Registered employee: " + name + ", ID: " + id + ",department: " + department);
}
}
public class lab6 {
public static void main(String args[]) {
company mycompany = new company();
[Link]("AA");
[Link]("BB", 101);
[Link]("CC", 102, "Finance");
}
OUTPUT:

Result:
Thus, the above program has been executed successfully.
[Link]
Date: WORKING WITH METHOD OVERRIDING

Aim:
To create java program using method overriding.

Program:
import [Link].*;
class Hospital
{
void treatPatient()
{
[Link]("Hospital provides general treatment");
}
}
class GovernmentHospital extends Hospital {
@Override
void treatPatient() {
[Link]("Government Hospital provides free basic treatment");
}
}
class PrivateHospital extends Hospital {
@Override
void treatPatient() {
[Link]("Private Hospital provides premium treatment with advanced facilities");
}
}
public class Main4 {
public static void main(String[] args)
Hospital h1 = new Hospital();
Hospital h2 = new GovernmentHospital();
Hospital h3 = new PrivateHospital();
[Link]();
[Link]();
[Link]();
}
}
OUTPUT:

Result:
Thus, the above program has been executed successfully.
[Link]
Date: CREATION OF INTERFACES

Aim:
To create java program using method overriding.

Program:
import [Link].*;
interface musicplayer
{
void play();
void pause();
void stop();
}
class guitar implements musicplayer
{
public void play()
{
[Link]("guitar is playing a melody");
}
public void pause()
{
[Link]("guitar music is paused");
}
public void stop()
{
[Link]("'guitar music has stopped");
}
}
class piano implements musicplayer
{
public void play()
{
[Link]("piano is playing classical notes...");
}
public void pause()
{
[Link]("piano music is paused");
}
public void stop()
{
[Link]("piano music has stopped");
}
}
public class lab8
{
public static void main (String[] args)
{
musicplayer m1=new guitar();
musicplayer m2=new piano();
[Link]();
[Link]();
[Link]();
[Link]("------");
[Link]();
[Link]();
[Link]();
}
}
OUTPUT:

Result:
Thus, the above program has been executed successfully.
[Link]
Date: CREATION AND IMPLEMENTATION OF PACKAGES

Aim:
To create java program on creation and implementation of packages.

Program:
package mypackage;

public class Message {


public void display() {
[Link]("Hello from the mypackage!");
}
}
import [Link];

public class TestPackage {


public static void main(String[] args) {
Message msg = new Message();
[Link]();
}
}

OUTPUT:
Hello from the mypackage!

Result:
Thus, the above program has been executed successfully.
[Link]
Date: WORKING WITH THREADS

Aim:
To create java program using threads.

Program:
import [Link].*;
class MyRunnable implements Runnable{
public void run() {
for(int i=1;i<=5;i++){
[Link]("Child Thread:"+i);
try{
[Link](500);
}catch(InterruptedException e){
[Link](e);
}
}
}
}
public class ThreadExample{
public static void main(String[]args){
MyRunnable obj=new MyRunnable();
Thread t1=new Thread(obj);
[Link]();
for(int i=1;i<=5;i++){
[Link]("Main Thread:"+i);
try{
[Link](500);
}catch(InterruptedException e){
[Link](e);
}
}
}
}
OUTPUT:

Result:
Thus, the above program has been executed successfully.
[Link]
Date: ILLUSTRATING MULTITHREADING

Aim:
To create java program using multithreading.

Program:

import [Link].*;
class MyRunnable implements Runnable
{
public void run()
{
for(int i=1;i<=5;i++)
{
[Link]([Link]().getName() +"-count:" +i);
try
{
[Link](500);
}
catch(InterruptedException e)
{
[Link](e);
}
}
}
public static void main(String[] args)
{
MyRunnable obj1=new MyRunnable();
MyRunnable obj2=new MyRunnable();
Thread t1=new Thread(obj1,"Thread-A");
Thread t2=new Thread(obj2,"Thread-B");
[Link]();
[Link]();
}
}

OUTPUT:
Result:
Thus, the above program has been executed successfully.
[Link]

Date: WORKING WITH INPUT/OUTPUT STREAMS

Aim:
To create java program using input / output streams.

Program:
import [Link].*;
import [Link];
public class studentDetailsI
{
public static void main(String[]args) throws Exception
{
Scanner sc=new Scanner([Link]);
[Link]("enter number of student:");
int n = [Link]();
[Link]();
PrintWriter pw = new PrintWriter(new FileWriter("[Link]",true));
for(int i = 0; i < n; i++)
{
[Link]("enter student name:");
String name = [Link]();
[Link]("enter student roll number:");
String roll = [Link]();
[Link](roll +"-"+name);
}
[Link]();
BufferedReader br = new BufferedReader(new FileReader("[Link]"));
String line;
[Link]("student Details from file:");
while((line = [Link]()) !=null)
{
[Link](line);
}
[Link]();
}
}
OUTPUT:

Result:
Thus, the above program has been executed successfully
[Link]
Date: DRAWING IMAGES USING APPLET

Aim:
To create java program using applet.

Program:
import [Link];
import [Link];
import [Link];
/*<applet code="simple drawing applet"width=500 height=500><?applet>*/
public class simple drawing applet extenda applet
{
public void init()
{
}
public void paint(graphics g)
{
setBackground([Link]-GRAY);
[Link]([Link]);
[Link](50,50,100,60);
[Link]([Link]);
[Link](200,50,100,60);
[Link]([Link]);
[Link](50,150,300,150)
[Link]([Link]);
[Link](200,200,80,80);
}
}
OUTPUT:

Result:
Thus, the above program has been executed successfully.

[Link]
Date:
JDBC CONNECTIVITY

Aim:
To create java program using JDBC Connectivity.

Program:
CREATING DATABASE:
CREATE DATABASE studentdb;
USE studentdb;
CREATE TABLE students (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50),
age INT
);
import [Link].*;

public class JDBCExample {


public static void main(String[] args) {
// Database credentials
String url = "jdbc:mysql://localhost:3306/studentdb";
String user = "root"; // replace with your MySQL username
String password = "yourpassword"; // replace with your MySQL password

// JDBC variables
Connection con = null;
Statement stmt = null;
ResultSet rs = null;

try {
// Step 1: Load the JDBC driver
[Link]("[Link]");

// Step 2: Establish the connection


con = [Link](url, user, password);
[Link]("✅ Database connected successfully!");

// Step 3: Create a statement


stmt = [Link]();

// Step 4: Execute an INSERT statement


String insertQuery = "INSERT INTO students(name, age) VALUES('Alice', 22)";
[Link](insertQuery);
[Link]("✅ Record inserted successfully!");

// Step 5: Execute a SELECT query


String selectQuery = "SELECT * FROM students";
rs = [Link](selectQuery);

// Step 6: Process the result set


[Link]("\n📋 Student Records:");
while ([Link]()) {
int id = [Link]("id");
String name = [Link]("name");
int age = [Link]("age");
[Link](id + " | " + name + " | " + age);
}
} catch (Exception e) {
[Link]();
} finally {
// Step 7: Close resources
try {
if (rs != null) [Link]();
if (stmt != null) [Link]();
if (con != null) [Link]();
} catch (SQLException e) {
[Link]();
}
}
}
}

OUTPUT:
✅ Database connected successfully!
✅ Record inserted successfully!

📋 Student Records:
1 | Alice | 22

You might also like