Practical: Use Java Compiler and Eclipse Platform to Write and Execute a Java Program
Objective:
To write, compile, and execute a simple Java program using the Java compiler and Eclipse IDE.
Tools Required:
- JDK (Java Development Kit)
- Eclipse IDE
1. Using Java Compiler (Command Line):
Open a text editor (Notepad/VS Code) and write the following Java program:
// HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
Save the file as HelloWorld.java.
Open Command Prompt (cmd) and navigate to the folder where the file is saved.
Compile the program using: javac HelloWorld.java
If no error occurs, it will generate HelloWorld.class.
Run the program using: java HelloWorld
Output: Hello, World!
2. Using Eclipse IDE:
Open Eclipse.
Go to File > New > Java Project.
- Project Name: MyFirstJavaProject
- Click Finish.
Right-click on the src folder -> New > Class.
- Name: HelloWorld
- Check 'public static void main(String[] args)'
- Click Finish
In the editor, write the following code:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
Click the green 'Run' button (Run) on the top toolbar.
Output in Eclipse Console: Hello, World!
Conclusion:
Successfully created, compiled, and executed a Java program using both the Java compiler (CLI)
and Eclipse IDE.