Skip to content

Latest commit

 

History

History
100 lines (80 loc) · 4.85 KB

File metadata and controls

100 lines (80 loc) · 4.85 KB

Object Oriented Programming Lab,CSL203

Set1

Simple Java Programs

  1. Program to print hello world
  2. Program to add two numbers.
  3. Program to check whether a given number is odd or even
  4. Program to check whether a given number is prime or not
  5. Program to find sum of first n natural numbers
  6. Program to find factor of a given number
  7. Program to print fibonacci series upto n
  8. Program to find factorial of a given number

Set2

Familiarization of java Arrays and Strings

  1. Program to find the sum of elements in an array
  2. Program to find the smallest element in an array
  3. Program to replace a particular element in an array.
  4. Program to find the second largest element in an array.
  5. Program to find the largest element in an NXN matrix.
  6. Program to add two matrices.
  7. Program to find transpose of a matrix.
  8. Program to multiply two matrices.
  9. Program to find trace of matrix.
  10. Program to find whether a string is palindrome or not.
  11. Program to search for a particular character in a string.
  12. Program to replace a particular character in a string.
  13. Program to find frequency of a given character in a string.

Set3

Familiarize the concepts of classes, Objects, Methods, Method overloading and constructor overloading

  1. Program to create a student class with name, roll no and marks of five subjects. Write functions to read and display the details.

  2. Write a Java program to calculate the area of different shapes namely circle, rectangle, and triangle using the concept of method overloading.

  3. Write a Java program to calculate the perimeter of different shapes namely circle and rectangle using the concept of constructor overloading.

  4. Java program to create a class employee with details such as empno, name and phone number. Read details of at least 5employees and print.

Set 4

AIM: To implement the concepts of constructors, inheritance, method overloading & overriding, polymorphism

  1. Write a Java program which creates a class named 'Employee' having the following members: Name, Age,Phone number, Address, Salary. It also has a method named 'print-Salary( )' which prints the salary of the Employee. Two classes 'Officer' and 'Manager' inherit the 'Employee' class. The 'Officer' and 'Manager' classes have data members 'specialization' and 'department' respectively. Now, assign name, age, phone number, address and salary to an officer and a manager by making an object of both of these classes and print the same.

  2. Write a java program to create an abstract class named Shape that contains an empty method named numberOfSides( ). Provide three classes named Rectangle, Triangle and Hexagon such that each one of the classes extends the class Shape. Each one of the classes contains only the method numberOfSides( ) that shows the number of sides in the given geometrical structures.

  3. Write two Java classes Employee and Engineer. Engineer should inherit from the Employee class. Employee class to have two methods display() and calcSalary(). Write a program to display the engineer salary and to display from Employee class using a single object instantiation (i.e., only one object creation is allowed).

a) display() only prints the name of the class and does not return any value. Ex. “ Name of class is Employee.”

b) calcSalary() in Employee displays “Salary of employee is 10000” and calcSalary() in Engineer displays “Salary of employee is 20000.”

Set 5

Aim: To Familiarize with exception handling mechanism in java

  1. Write a program that demonstrates exception handling mechanisms.

(a) Arithmetic exception

(b) Array out of index exception

Set 6

Aim : To familiarize with multithreading in java

  1. Write a Java program to create two threads: One for displaying all odd number between 1 and 100 and second thread for displaying all even numbers between 1 and 100.

Set 7

Aim: To familiarize file operations in Java

  1. Write a Java program that reads a file and displays the file on the screen, with a line number before each line by handling all file related exceptions.

  2. Write a Java program that reads a line of integers from a file, and then displays each integer, and the sum of all the integers (Use String Tokenizer class of java.util).

PRACTICE QUESTIONS (INTERVIEWS)

SLIDING WINDOW

  1. find the first negative number in each window of size k
  2. Get the number anagrams of string2 in string1
  3. Get the anagrams itself of string2 in string1
  4. shortest subarray with Sum equal to target
  5. Minimum window containing all the characters in the target string
  6. find the count of subarray with given min and max elements