How to write a Java program Using Eclipse
Prerequisites:Java Installation and classpath settings and Eclipse IDE installation
1. Open your eclipse IDE. It will ask for a workspace folder where all your work will be stored. You can give any preferred location and press "ok".
(if you want to change your workspace, you can do it using "File" -> "Switch Workspace")
2. File -> New -> Project -> Java Project -> Next
3. Type your project name. In this example, I am giving my project name as "JavaDemo".Cilck on Finish.
4. You can close your welcome screen displayed. Now you should get a screen like this.
5. Select your project, say JavaDemo in my example (This is the project name that you gave early).
File -> New -> Class.
Give your Class Name. In this example, I am giving my class name as "MyFirstJavaProgram".
Check the checkbox "public static void main(String args)"
Click on "Finish"
6. Not you can write your Java program in eclipse. Here we are going to write a Java program which will display a message "Program has run successfully". The program is given below.
1
2
3
4
5
6
7
| public class MyFirstJavaProgram { public static void main(String[] args) { System.out.println( "Program has run successfully" ); } } |
You can see most part of your program is already done by eclipse IDE in this case. You just added the statement System.out inside the public static void main.
7. Now save your program using File -> Save.
8. Now let us run this program. Right Click on your program file (MyFirstJavaProgram in this case)
-> "Run As" -> "Java Application"
9. Once you run the program, you can see the output in console which you can see at the bottom in the below screenshot.
Now you have created and run your first Java program. Note that all the source code you created will be available in your workspace folder which you have selected when you opened eclipse.
No comments:
Post a Comment