OOPS With Java Experiment 1 to 4
OOPS With Java Experiment 1 to 4
Objective: Use Java Compiler and Eclipse platform to write and execute java program.
Related Theory: Eclipse is the most popular IDE for Java application development. In 2001, IBM formed a
consortium to support the development of Eclipse IDE. In 2004, it become the Eclipse Foundation whose main
vision was to guide, implement, and share the development of open-source (software whose source code is
released under a license) Eclipse projects in a vendor-natural environment. It is an open-source Integrated
Development Environment (IDE). It is written in Java. It is used to develop Java applications (Java SE and Java EE). It
is also used to develop applications in other languages, such as C, C++, PHY, Python, Perl, and other web projects
with the help of extensible plug-ins. We can run it on different platforms, like Windows, Linux, and macOS.
Presently, it is the widely used IDE for developing Java applications.
Here are the steps on how to write and execute a Java program using the Java compiler and Eclipse platform:
1. Open Eclipse.
2. To create a new Java project, select File > New > Java Project.
3. In the New Java Project dialog, enter a name for your project and click Finish.
4. To create a new class in the project, right-click on the project name in the Package Explorer and select New
> Class.
5. In the New Java Class dialog, enter a name for your class and select the public static void main(String[] args)
checkbox. Click Finish.
7. To save the class file, click the Save button on the toolbar.
8. To compile the Java code, click the Run button on the toolbar.
9. To execute the Java program, click the Run button on the toolbar.
Program Code:
System.out.println(“Hello World!”);
Output:
Program: 2
The command-line arguments are passed to the program at run-time. Passing command-line arguments in a Java
program is quite easy. They are stored as strings in the String array passed to the args parameter of main() method
in Java.
To compile and run a java program in command prompt follow the steps written below.
• open the command prompt and go to the directory where your file is saved.
Program Code:
class Multvalue
System.out.println(value);
}
Output:
Program: 3
Related Theory:
• Abstraction:
Abstraction is the process of hiding the implementation details of an object and exposing only its essential
features. This allows us to focus on what an object does, rather than how it does it.
• Encapsulation:
Encapsulation is the process of wrapping data and code together into a single unit, called a class. This
protects the data from being accessed or modified in unintended ways.
• Inheritance:
Inheritance is the process of creating a new class that inherits the properties and methods of an existing
class. This allows us to reuse code and create hierarchies of classes.
• Polymorphism:
Polymorphism is the ability of an object to take on many different forms. This allows us to write code that
can work with different types of objects without having to know the specific type of object at compile time.
Related Theory:
Inheritance in Java is a mechanism in which one object acquires all the properties and behaviors of a parent object.
It is an important part of OOPs (Object Oriented programming system).
The idea behind inheritance in Java is that you can create new classes that are built upon existing classes. When
you inherit from an existing class, you can reuse methods and fields of the parent class. Moreover, you can add
new methods and fields in your current class also. Inheritance represents the IS-A relationship which is also known
as a parent-child relationship.
Polymorphism in Java is a concept by which we can perform a single action in different ways. Polymorphism is
derived from 2 Greek words: poly and morphs. The word "poly" means many and "morphs" means forms. So
polymorphism means many forms.
There are two types of polymorphism in Java: compile-time polymorphism and runtime polymorphism. We can
perform polymorphism in java by method overloading and method overriding.
Program Code:
class Area
void area(int r)
obj.area(20,30);
}
Output:
Compile-time polymorphism
int bonus=10000;
}
Output: