Hi,
To check if you have done that correctly open Command Prompt,
Verify Java
I hope you have successfully installed Java and eclipse and set up you environment.To check if you have done that correctly open Command Prompt,
- Type java -version and verify that you get the version information of java installed on your machine.
- Check below image.
Getting familiar with eclipse
Check below image,
- This is the perspective that is open right now in eclipse. We need Java for this tutorial.
- This is Project explorer, where you can see all the projects and files within the project in a hierarchical fashion.
- This is main window where you will see opened files and write you code.
- This is a list of views which will be handy later soon.
- Status of what eclipse is doing right now.
OK, so now we are good to go.
Create Hello World!
- Click on File -> New -> Java Project
- Type MyFirstJavaProject and Click Finish button at the bottom.
- Check below image
- Click small arrow symbol as shown in below image.
- Right Click on src folder and select New -> Package.
- Type your package name as myCode.
- Click Finish button at the bottom.
- Right click on myCode package that we just created.
- Select New -> Class.
- Type your class name as HelloWorld.
- Click Finish button at the bottom.
- Congrats, now we will write some code to make our class do something for us.
- For now we want it to print Hello World!
- Double Click on HelloWorld.java file that we have just created.
- You will see it has some code as shown below.
Old Code:
package myCode;
public class HelloWorld {
}
public class HelloWorld {
}
New Code:
package myCode;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
I will explain the code later but for now just write it and run it.
- To run the code right click on the class file you want to run and select Run As -> Java Application.
- A console view will show up with output as Hello World!
- Voila, you have done it.
Some Exercises for you
- Print your name instead of Hello World.
- Print your friends' or siblings name.
- Print your favorite quote or mantra.
Keep smiling & keep reading...
Amit Kumar




No comments:
Post a Comment