List of Programs Updated

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

17 CS 2004 - OBJECT ORIENTED PROGRAMMING LAB

LIST OF PROGRAMS

Lab
Session
No/Week List of Programs
No
In Lab:
1. Write a Java Program to read different data type values form user by using Scanner class and print the same.
1
2. Write a Java program that reads an unspecified number of integers, determines how many positive and
negative values have been read, and computes the total and average of the input values (not counting zeros).
Your program ends with the input 0. Display the average as a floating-point number.
In Lab:
1. Write a Java Program to demonstrate
a)Implicit Type Casting
2
b)Explicit Type Casting

2. Write a Java Program to find sum of elements in a given array


In Lab:
1. Write a Java Program to create an 'Employee' class with variables are used to store first name, last name,
annual salary, and number of dependents.
There are two methods; First method is to initialize the variables (first name, last name, monthlysalary, and
number of days present as parameters.). Second method to returns the total salary based on no.of days present.
Use classes and object scenario to solve this.

2. Write a Java program to find the maximum number of two integer values, two double values and three
double values by using method overloading mechanism.

3 Post Lab:
1. Write a Java program to design a class named 'Rectangle', contains: two double data fields named width and
height that specify the width and height of the rectangle and one string data field named color that specifies the
color of a rectangle.
There are three methods; first method set the data values for all the three fields. Second, a method named
getArea() that returns the area of this rectangle, third a method named getPerimeter() that returns the
perimeter.
Implement RectangleMain class, create minimum two objects of Rectangle to invoke all the methods and print
the result.

2. Write a Java program to demonstrate the call by value and call by reference.
In Lab:
1. Write a Java program to create a class named 'StudentData' with data members stuID,stuName,stuAge; and
get(), set() methods to access and assign values. The class has two constructors which are:
a. no parameter
b. three parameter,
and assign the values by using 'this' keyword. Now create objects of the 'StudentData' class having none and
4 two parameter constructors, and print the result

2. Write a Java Program to invoke a Garbage Collector and call the finalize() method on an object, and show
that it ignores all the exceptions raised in the method and program will terminate normally.

Post Lab:
1. Write a Java program to create a class named 'Rectangle' with two data members- length and breadth and a
method to claculate the area(). The class has three constructors which are:
a. having no parameter - values of both length and breadth are assigned zero.
b. having two numbers as parameters - the two numbers are assigned as length and breadth respectively.
c. having one number as parameter - both length and breadth are assigned that number.
Now, create objects of the 'Rectangle' class having none, one and two parameters and print their areas.

2. Write a Java program to perform garbage collection by creating a class with the name GarbageCollection and
print the free memory in java virtual machine using gc() method of RunTime class, also use getRunTime()
method to get reference of current RunTime object.
In Lab:
1. Write a Java program to demonstrate usage of static keyword, with help of static variables, static methods,
and static block.

2. Write a Java program to demonstrate Nested/Inner classes concept, by creating an outer class Outer and
inner class Inner, and by creating a main class NestedClassesDemo, create objets for Outer and inner to access
fields and methods of Outer and Inner classes.
5
Post Lab:
1. Write a Java program to demonstrate usage of final keyword

2. Write a Java program to demonstrate Nested/Inner classes concept, by creating


an outer class Car having data fields carName, carType, and getCarName() method; and
an inner class Engine having data field engineType, and setEngineType(), getEngineType() methods. and access
outer class members with inner class by 'this' keyword. create CarMain class to complete the rest of the
program.
In Lab:
1. Write a Java Program to create a class called Amphibian. From this, inherit a class called Frog. Put
appropriate methods in the base class. In main( ), create a Frog and upcast it to Amphibian, and check that all
the methods still work.
6
2. Write a Java program to demonstrate method overriding by creating a class Dog, and two sub classes of that
Labrador & Yorkshire, create methods name() and bark() in subclasses, use InheritanceDemo class to invoke
methods by creating objects of those subclasses.
In Lab:
1. Write a Java program to create abstract class Car, with instance variable regno, Car constructor, concrete
method fillTank(), abstract methods steering(int direction), braking(int force).
Create two subclasses Maruthi and Santro to implements abstract methods in it. Create a AbstractDemo class to
for testing.
7
2. Write a java program to create an abstract class Shape with Data members: numSides; Constructor: Shape()
to initialize numSides; Concrete method: getNumSides(); Abstract Methods: getArea(), getPerimeter()
Write a concrete subclass Rectangle with Data members: width, height
Write a concrete subclass RtTriangle with Data members: width, height
In another class, write a main method to define a Rectangle and a Triangle.
In Lab:
1. Write a Java program to demonstrate String class and its methods. Use length(), indexOf(), toUpperCase(),
toLowerCase(), equals(), equalsIgnoreCase(), compareTo(), charAt(), replace(), trim() methods.

2. Write a java program to use append() method that concatenates the passed String argument with the
existing declared string. Use insert(), replace(), delete(), reverse() methods of StringBuilder class to perform
various operations on string.
8
Post Lab:
1. Write a Java program to demonstrate StringBuffer class and its methods. Use length(), capacity(), append(),
insert(), delete(), charAt() methods.

2. Write a java program to create StringBuilder class returns the current capacity of the StringBuilder object.
The default capacity of the Builder is 16. If the number of character increases from its current capacity, it
increases the capacity by (old_capacity*2)+2 e.g. at current capacity 16, it becomes (16*2)+2=34.
In Lab:
1. Write a Java program to by creating a class with one private member variable and declare two methods set()
and print(). For set() set a value through the main method and test with different access specifiers.
9
2. Write a Java program to create a class name Test, and take 3 variables declared as one public, one private and
one as default. By creating class named AcessTest define two methods setc() and getc(), to pass the value
through main method and check differences between public, private and default access modifiers.
In Lab:
1. Write a java program to create and access a user defined package where the package contains a class named
CircleDemo, which in turn contains a method called circleArea() which takes radius of the circle as the
10 parameter and returns the area of the circle.

2. Write a Java program to create a package for Book details giving bookName, authorName, price and
yearOfPublish, use that package in another program to perform operation on the data.
In Lab:
1. Write a Java Program to define an Interface called "Vehicle" with abstract methods changeGear(int),
speedUp(int). You have to implement two classes "Car" and "Bike" which define code for abstract methods of
the Interface Vehicle.

2. Write a Java Program to demonstrate different types of arithmetic exceptions supposed by java. Illustrate
using an example, the use of arithmetic exceptions.
11
Post Lab:
1. Write a Java program to Demonstrate STACK using Interface Concept. You need to define an interface
"StackInterface", abstract methods void push(int), int pop() and void dispStack(). Define a class "MyStack" that
implements the interface and write code to push (), pop() and dispStack() methods

2. "The finally block will execute whether or not an exception is thrown”. Analyze the meaning of this
statement. Develop a java program to demonstrate finally.
In Lab:
1. Write a Java program to create a thread by extending Thread class. Define a job for child thread to print a
message “child thread” for 10 times. Define a job for main thread to print a message “main thread” for 10 times.
Create a class ThreadDemo define main method in this class create child thread form this class.

2. Write a java program which contains an employee database having the fields like name, number and basic
salary for number of employees which has to be saved with the file name called scores.txt.
12
Post Lab:
1. Write a Java program to create a thread by implementing Runnable interface. Define a job for child thread to
print a message “child thread” for 10 times. Define a job for main thread to print a message “main thread” for
10 times. Create a class ThreadDemo define main method in this class create child thread form this class.

2. Write a java Program to Create a Student file which should contain fields like regNo,name and Internal Marks
, where all the details have to be entered through keyboard. If a student id is not matched in contents of a file
compiler has to generate a message saying that wrong details entered.
In Lab:
1. Write a java Program that uses HashSet to remove duplicate values from array of Strings. Use
printNonDuplicates method which have to be called from constructor by passing Collection argument.
Construct HashSet to remove duplicates. Call Iterator methods hasNext and next to access the Set elements and
output their values.
13
2. Write a java program which uses HashMap and TreeMap . Create a HashMap which should be assigned to
map. User should able to enter a text in textarea at the top of the window and should press GO button to invoke
actionPerformed. Write methods createMap and createOutput to store no.of occurences of each word and to
create a string with all the entries in the map.
In Lab:
1.Write a Java Program to create a form with 3 buttons and
-> Set label for first button is RED
-> Set label for second button is GREEN
-> Set label for third button is BLUE
Then apply action for every button as shown below:
a) if we click RED button form background color also change to RED
14 b) if we click GREEN button then background change to GREEN
c) if we click BLUE button then background change to BLUE"

2. "Write a Java program to create a login form which contains


-> 2 labels for user name and password
-> 2 TextFields for username and password
-> 1 button for submit
and display username and password details in next page when we click the submit button."

You might also like