0% found this document useful (0 votes)
3 views5 pages

BCA Java Lab Record-1

The document contains a lab record for BCA-402T Internet & JAVA Programming, featuring 10 Java programs. These programs cover various concepts including a simple calculator, array operations, class and object examples, inheritance, exception handling, multithreading, file handling, Java Swing, JDBC connectivity, and a servlet example. Each program includes code snippets demonstrating the respective functionalities.
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)
3 views5 pages

BCA Java Lab Record-1

The document contains a lab record for BCA-402T Internet & JAVA Programming, featuring 10 Java programs. These programs cover various concepts including a simple calculator, array operations, class and object examples, inheritance, exception handling, multithreading, file handling, Java Swing, JDBC connectivity, and a servlet example. Each program includes code snippets demonstrating the respective functionalities.
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

BCA-402T Internet & JAVA Programming

Lab Record – 10 Programs

Program 1: Simple Calculator using Java


import [Link];

public class Calculator {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

[Link]("Enter first number: ");


double a = [Link]();

[Link]("Enter second number: ");


double b = [Link]();

[Link]("Addition = " + (a + b));


[Link]("Subtraction = " + (a - b));
[Link]("Multiplication = " + (a * b));
[Link]("Division = " + (a / b));

[Link]();
}
}

Program 2: Array Operations


public class ArrayExample {
public static void main(String[] args) {
int arr[] = {10, 20, 30, 40, 50};
int sum = 0;

for (int i = 0; i < [Link]; i++) {


sum += arr[i];
}

[Link]("Sum of array elements = " + sum);


}
}

Program 3: Class and Object Example


class Student {
int roll;
String name;

void display() {
[Link]("Roll No: " + roll);
[Link]("Name: " + name);
}
}

public class MainClass {


public static void main(String[] args) {
Student s1 = new Student();

[Link] = 101;
[Link] = "Rahul";

[Link]();
}
}

Program 4: Inheritance Example


class Animal {
void sound() {
[Link]("Animal makes sound");
}
}

class Dog extends Animal {


void bark() {
[Link]("Dog barks");
}
}

public class InheritanceDemo {


public static void main(String[] args) {
Dog d = new Dog();

[Link]();
[Link]();
}
}

Program 5: Exception Handling


public class ExceptionDemo {
public static void main(String[] args) {
try {
int a = 10 / 0;
[Link](a);
} catch (ArithmeticException e) {
[Link]("Cannot divide by zero");
} finally {
[Link]("Program Ended");
}
}
}

Program 6: Multithreading
class MyThread extends Thread {
public void run() {
for (int i = 1; i <= 5; i++) {
[Link]("Thread running: " + i);
}
}
}

public class ThreadDemo {


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

Program 7: File Handling in Java


import [Link];
import [Link];

public class FileDemo {


public static void main(String[] args) {
try {
FileWriter fw = new FileWriter("[Link]");
[Link]("Welcome to Java File Handling");
[Link]();

[Link]("File created successfully");


} catch (IOException e) {
[Link]("Error occurred");
}
}
}

Program 8: Java Swing Example


import [Link].*;

public class SwingDemo {


public static void main(String[] args) {
JFrame frame = new JFrame("Swing Example");

JButton button = new JButton("Click Me");


[Link](100, 100, 120, 40);

[Link](button);
[Link](400, 300);
[Link](null);
[Link](true);
[Link](JFrame.EXIT_ON_CLOSE);
}
}

Program 9: JDBC Connectivity


import [Link];
import [Link];
import [Link];

public class JDBCDemo {


public static void main(String[] args) {
try {
[Link]("[Link]");

Connection con = [Link](


"jdbc:mysql://localhost:3306/test",
"root",
"password"
);

Statement stmt = [Link]();

[Link](
"INSERT INTO student VALUES(1, 'Aman')"
);

[Link]("Data inserted successfully");

[Link]();
} catch (Exception e) {
[Link](e);
}
}
}

Program 10: Servlet Example


import [Link].*;
import [Link].*;
import [Link].*;

public class HelloServlet extends HttpServlet {

public void doGet(HttpServletRequest req,


HttpServletResponse res)
throws ServletException, IOException {
[Link]("text/html");

PrintWriter out = [Link]();

[Link]("<h1>Hello from Servlet</h1>");


}
}

You might also like