Saturday, September 23, 2023
BCA and B.Sc Programs - Programming in Java Lab - Bharathiar University - Practical Program 6- Write a Java Program to create a frame with four text fields name, street, city and pin code with suitable tables. Also add a button called my details. When the button is clicked its corresponding values are to be appeared in the text fields.
import javax.swing.*;
Thursday, September 14, 2023
BCA and B.Sc Programs - Programming in Java Lab - Bharathiar University - Practical Program 4- Write a Java Program which open an existing file and append text to that file.
Bharathiar University
Programming Java LabJava Program 4Write a Java Program which open an existing file and append text to that file.
Source Code
import java.io.BufferedWriter;import java.io.FileWriter;import java.io.IOException;import java.util.*;
public class AppendFile { public static void main(String[] args) {
String filePath;
// The text you want to append String text; try { Scanner in =new Scanner(System.in); // Specify the file path you want to append to System.out.println("Enter File Path (use double slash):"); filePath=in.nextLine(); // Create a FileWriter in append mode FileWriter fw = new FileWriter(filePath, true);
// Create a BufferedWriter for efficient writing BufferedWriter bw = new BufferedWriter(fw); // The text you want to append System.out.println("Enter text to append the File:"); text=in.nextLine(); bw.newLine(); // Append the text to the file bw.write(text); bw.newLine(); // Add a newline for clarity
// Close the BufferedWriter to flush and release resources bw.close();
System.out.println("Text appended to the file successfully."); } catch (IOException e) { System.err.println("An error occurred: " + e.getMessage()); } }}
OUTPUTsample.txt file before appending text

sample.txt file after appending text



Tuesday, September 12, 2023
BCA and B.Sc Programs - Programming in Java Lab - Bharathiar University - Practical Program 4- Write a Java Program to implement the concept of multithreading with the use of any three multiplication tables and assign three different priorities to them.
Bharathiar University
Programming Java LabJava Program 4Write a Java Program to implement the concept of multithreading with the use of any three multiplication tables and assign three different priorities to them.
Source Code
import java.util.*;
public class MultiThread extends Thread {
private int tableNumber;
private int max;
public MultiThread(int tableNumber, int max) {
this.tableNumber = tableNumber;
this.max = max;
}
// @Override
public void run() {
for (int i = 1; i <= max; i++) {
System.out.println(tableNumber + " x " + i + " = " + (tableNumber * i));
try {
Thread.sleep(1000); // Add a slight delay to better visualize the output
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
int limit = 10;
Scanner in =new Scanner(System.in);
System.out.println("Enter three numbers for multiplication tables: ");
int x=in.nextInt();
int y=in.nextInt();
int z=in.nextInt();
// Create three threads with different priorities
MultiThread t1 = new MultiThread(x, limit);
MultiThread t2 = new MultiThread(y, limit);
MultiThread t3 = new MultiThread(z, limit);
// Set different priorities to the threads (MIN_PRIORITY = 1, MAX_PRIORITY = 10)
t1.setPriority(Thread.MIN_PRIORITY);
t2.setPriority(Thread.NORM_PRIORITY);
t3.setPriority(Thread.MAX_PRIORITY);
// Start the threads
t1.start();
t2.start();
t3.start();
}
}
OUTPUT:
Tuesday, September 5, 2023
BCA and B.Sc Programs - Programming in C Lab - Bharathiar University - Practical Program- C Program to Write a C Program to convert decimal number to binary number
BHARATHIAR UNIVERSITY
BCA and B.Sc Programs - Programming in C Lab - Bharathiar University - Practical Program-
C Program to Write a C Program to convert decimal number to binary number
Source Code
#include <stdio.h>
#include <conio.h>
void decimalToBinary(int decimal)
{
int binary[32];
int index = 0,i;
while (decimal > 0)
{
binary[index++] = decimal % 2;
decimal /= 2;
}
printf("Binary representation: ");
for (i = index - 1; i >= 0; i--)
{
printf("%d", binary[i]);
} printf("\n");
}
int main()
{
int decimal;
clrscr();
printf("Enter a decimal number: ");
scanf("%d", &decimal);
decimalToBinary(decimal);
getch();
return 0;
}
Thursday, August 31, 2023
BCA and B.Sc Programs - Programming in Java Lab - Bharathiar University - Practical Program 3- Write a Java Program to create an Exception called PayOut of Bounds and throw the exception.
Bharathiar University
Programming Java LabJava Program 3Write a Java Program to create an Exception called PayOut of Bounds and throw the exception.
Source Code import java.util.*;//user defined exception class for pay out of bounds Exceptionclass PayOutOfBoundsException extends Exception { //Constructor public PayOutOfBoundsException(String s) { super(s); //calls Exception class Constructor }}//Main class for User defined Exceptionpublic class Salary{ public static void main(String args[]) { Scanner in =new Scanner(System.in); System.out.println("Enter Employee Salary: "); //Get Employee salary from User int esal=in.nextInt(); try{ //Check if employee salary not between 3000 and 10000 if(esal<3000 || esal>10000) { // throw pay out of bounds exception with a message throw new PayOutOfBoundsException("Salary must be 3000 to 10000"); } //print employee salary if given salary is within bounds System.out.println("The given salary of Employee is "+esal); } //catch block for payoutof bounds exception catch(PayOutOfBoundsException e) { //catch the exception and prints the error message System.out.println(e); }}}
Output:
Program 12 BCA Madras University BCA Object Oriented Programming using C++ Practical Madras University Program 12 Implement a telephone directory using files
BCA Object Oriented Programming using C++ Practical Madras University Program 12 Implement a telephone directory using files SOURCE CODE...
-
Write a C Program to Find Sum, Average and Standard Deviation for a Given Set of Values Source Code: #include<stdio.h> #include<co...
-
Bharathiar University Programming Java Lab Java Program 1 Write a Java Applications to extract a portion of a character string and print t...
-
Bharathiar University Programming Java Lab Java Program 2 Write a Java Program to implement the concept of multiple inheritance using Inte...







