Posts

Showing posts from September, 2025

Practical Implementation of Singleton Class

Image
Practical Implementation of Singleton Class   class Singleton {     public static void main(String args[])     {         Thread t = new Thread(new Runnable(){             public void run()             {                 DatabaseConnection obj = DatabaseConnection.getInstance();             }         });         Thread t1 = new Thread(new Runnable(){             public void run()             {                 DatabaseConnection obj = DatabaseConnection.getInstance();             }         });         t.start();         t1.start();     } } class DatabaseConnection{     pri...

TYBSc (CS) Sem V : Object Oriented Programming Using Java I Practical Slips Solutions

Image
  SAVITRIBAI PHULE PUNE UNIVERSITY, PUNE T. Y. B.Sc. (Computer Science) Semester V Practical Examination       SUBJECT: CS-359 Practical course based on CS355 (Core Java) /* Q1) Write a Program to print all Prime numbers in an array of ‘n’ elements.  (use command line arguments) */ class Slip1 { public static void main(String args[]) { System.out.println("The prime numbers are: "); for(int i = 0; i < args.length; i++) { boolean isPrime= true; int num = Integer.parseInt(args[i]); for(int j = 2; j < num; j++) { if(num%j == 0) { isPrime = false; break; } } if( isPrime == true) { System.out.println(num); } } } } How run it: /* Q. 2 - Define an abstract class Staff with protected memebers id and name.  Define a parameterized constructor. Define one subclass OfficeStaff with member department. Create n object of OfficeStaff and display all details.*/ import java.util.*; ab...