What I Learned in Java Practical - Experiment 1
In this practical, sir explained the topic of classes and objects in Java. We worked on 5 programs
related to this concept. He first taught us the theory and then told us to write and run the programs
on our computers.
The first program was about creating a class named Student. It had two fields: name and rollNo. We
created an object and displayed the student details using a method. This helped me understand
how to create a class and how objects work.
In the second program, we learned about constructors by creating an Employee class. The
constructor was used to initialize the name and salary of the employee. It was good to learn how
values can be set directly when an object is created.
The third program was based on a Car class. We made two objects with different brand and price.
Then we used a method to display their values. This showed how we can create multiple objects
from the same class, each with different data.
In the fourth program, we used the Scanner class for the first time. The program was to calculate the
area of a circle. We took the radius from the user and used a method to calculate and print the area.
This program taught me how to take input from the user in Java and how to perform simple
calculations.
The last program was a bit more interesting. It was about a Rectangle class where we had to
compare the area of two rectangles. We passed one rectangle object to a method of another object
and compared their areas. This taught me how to pass objects as parameters and how we can use
object-to-object communication.