Experiment No.
-01
Objective:
Use Java compiler and Eclipse platform to write and execute Java program.
Steps:
- Step 1: Install Eclipse IDE
- 1. Download Eclipse: Visit the official Eclipse download page and choose the version suitable for
Java development.
- 2. Install Eclipse: Run the installer and follow instructions.
- Step 2: Install Java Development Kit (JDK)
- 1. Download JDK from Oracle or install OpenJDK.
- 2. Set up JDK in Eclipse via Window > Preferences > Java > Installed JREs.
- Step 3: Create a Java Project in Eclipse
- 1. Go to File > New > Java Project, enter name and click Finish.
- Step 4: Create a Java Class
- 1. Right-click src > New > Class, enter class name and select main method option.
- Step 5: Write Java Code:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
- Step 6: Run using Run button.
- Step 7: Compile and Debug if needed.
Experiment No.-02
Objective:
Creating Simple Java program using command line arguments.
Code:
public class Greet {
public static void main(String[] args) {
if (args.length > 0) {
System.out.println("Hello, " + args[0] + "!");
} else {
System.out.println("Hello, user!");
}
}
}
Expected Output:
> java Greet Harpal
Hello, Harpal!
> java Greet
Hello, user!
Experiment No.-03
Objective:
Understand OOP concepts and basics of Java programming.
Topics Covered:
- Encapsulation: Wrapping data and methods in a class.
- Inheritance: Using extends keyword to inherit from another class.
- Polymorphism: Overriding and overloading methods.
- Abstraction: Hiding implementation details using abstract classes or interfaces.