When we write java code with Eclipse tools the very first thing you will have to do is to create the project. Open Eclipse and then click on FILE and then NEW and then PROJECT. Click on it to open. In the new NEW PROJECT windows select JAVA PROJECT from WIZARDS menu. Then click on NEXT. In the new windows namely NEW JAVA PROJECT in the first space after PROJECT NAME , you can provide any project name and here we will write it as ‘FirstProject’.
Then, inside NEW JAVA PROJECT keep everything as it is. Use default location, that is in the location where eclipse is installed and then in JRE the default selection such as USE AN EXECUTION ENVIRONMENT JRE and in PROJECT LAYOUT select the default selection such as CREATE SEPARATE FOLDERS FOR SOURCES AND CLASS FILES and finally select NEXT and then select FINISH.
After performing all of these functions you will reach to the default Eclipse window where on the left side in the ‘Package Ecplorer’ you have one consolidated folder namely FIRST PROJECT. Click on the arrow tab against the project and here FIRSTPROJECT and this will expand and provide you two more folder. Name of one folder is ‘src’ which is known as source folder. Remember while doing programming with Android Studio we do see similar sort of set ups out there.
In ‘src’ which is the source folder where you can store all o yours java programs. Inside source folder we can create package. In java package is known as folder in source folder. Right click on ‘src’ and then NEW and then PACKAGE.
A new window namely NEW JAVA PACKAGE will be shown out there. It has two columns. The first one is for SOURCE FOLDER and the second one is for NAME. Leave the first column as it is and we have to write in the second column that is NAME of package supposedly as ‘day1.examples’ without quotes. Then click FINISH. Now inside PACKAGE EXPLORER and ‘src’ we have new package or folder namely ‘day1.examples’. You can check this by going to installation folder of eclipse and then go to FIRST PROJECT folder and then to ‘src’ folder and then inside of it you can see day1 and folder and inside day1 you have examples folder.
The package explorer is nothing but the series of folders are the folders. Now we are ready to write down a small java program.
For any Java program to work you need class. If you are using MyFirstClass as class then all the wordsin fact the main words should have been in capital and there should not be any space between the name of class. Right click on day1.examples package and then new and then select class and this will lead to another windows namely JAVACLASS. In the NAME segment write down ‘MyFirstClass’ and in the method segment click on ‘public static void main’ and then click on FINISH. After click on finish it will compile and then show you the default window.
Now, inside main window of Eclipse we have out part of first Java code which is named similar to that of class which is ‘MyFirstClass’. Here we see there are signs of two slashes // which is known as comments which are the way to intimate users about the information that are put inside codes. Here we see just after public static void which is a method and it is an auto generated method and this methods comes automatically as we know while creating the new class. That is why the two double slashes with comments are written here.
If you want to learn more about Java comments then you can browse previous articles of mine and learn about it. In short we have multi line comment and single line comment. You can write comments anywhere in the class and that is not going to affect the state of code you are writing there. This code will not be shown in console as we have to write down the println functions in order to work in that way.
Now after method we write down the code that should convey the console to print out some words. This would be ours first program. In order to write that code you will have to write:
This means you have to write System with beginning with capital letter and then put dot and then a pop up window will open and this means you are writing the code in the correct manner and then write down out in small and then dot and then println in small and then two brackets and within brackets as written above write down anything as this is the first program then write down Hello World and then every statement in java ends with semi colon and this means you have written your first statement.
Then, save this program by clicking on the save button of Eclipse and then right click anywhere on the code console of Eclipse and then go to RUN AS and then click on JAVA APPLICATION to run the program.
Then another window should open and this should be as ‘SAVE AND LAUNCH’ windows and then click on OK . The console window is just at the below of coding window and there you can see the code running as ‘Hello World’ could be seen there and this means ours processing of creating the first program is now successful. In that console window you can see the location of java application and the name of class as java application and the print word. For the sake of testing you can write anything in the place of ‘Hello World ’ to check this out of the results out there.
In that console window there are some other options such as the problems with code or even while writing code inside Eclpise behind each and every line you should see that after the line numbers there are some cross signs which means something you forgot while writing the code. In this manner there are various steps where you can check about the progress of codes and its correct version. In the next tutorial we will be reading in depth about the adding numbers to java codlings and detailed and comprehensive explanation about strings and integers of Java.