Writing your first program using Eclipse

To begin, startup Eclipse. You can do this by typing in 'eclipse &' into the command prompt

Once Eclipse starts up, if you see this welcome screen, click on the workbench button.


Next, you will be asked to select a workspace. This is important! This is the root directory to which all of your programs will be saving to, so make sure you know where it is. In my case, I clicked Browse... and created a directory called 'CSE1030'.


Now we need to create a Java Project. You can do this by doing: File -> New... -> Project... -> Java Project. The project wizard looks like this - click on Java Project.


Now, you will see a window like the one shown. I have named my project 'Tutorial'. You can name your project whatever you like. Note that doing this now creates a directory in your previously created workspace directory. Keep the default settings and click finish.

You may then see a popup window like the one showed here. Click Yes if that is the case.


The next step is to create a package. To do this, right-click the new project you just created that will now appear in the Package Explorer on the left side, and then click New -> Package. I will name my package 'cse1030'.

Packages are nothing more than directories. So just now, I created yet another directory. This will be useful for when your projects become very large. Also, note that there is a naming convention for packages that we are not demonstrating here. To learn more about packages, refer to this Java Tutorial. But for now, our package named 'cse1030' serves our purposes adequately.


Now if you look in the Package Explorer, our 'cse1030' package is under Tutorial -> src -> cse1030. 'src' is the source foulder. Hence, when it comes time to submit your files and you want to locate your source file, it will be in workspace->Project->src->package->file. So in our case, it would be: CSE1030->Tutorial->src->cse1030->HelloWorld.java

Now, to finally create our HelloWorld.java, we must create a class. You can do this by right-clicking the package, then clicking New, and then Class.


You will see this window. Enter the name of your class, in this case 'HellloWorld', and check off the 'public static void main(String[]args) box - this will create the main method in your class for you. Our simple program does not inherit from any other program, so the other two boxes don't really matter.


You should now see something like this:

The TODO comment is unnecessary, so you can delete it, and the '/***@param args*/' is starting the javadoc documentation for you.

Type in 'System.out.print("Hello World");' into the main body and then save your program by pressing ctrl+s on your keyboard.


Now you can run your program by either clicking the green run button on the toolbar, or by right-clicking your package in the package explorer->Run As...-> Java Application

Now your output will display in the console at the bottom!

Now, if you want to submit this file, open up your console. By default, you will be in your home directory (/cse/home/cse##### - where ##### is your cse account number). Recall that we created our workspace, called 'CSE1030' in the home directory! so we will first go into our workspace directory by typing 'cd CSE1030'.

Now, if you type ls, you will see the contents of our workspace, which, for now, consists of the project we created - 'Tutorial'.

If we type ls again, we will now see bin and src. the src directory will have our source files, so navigate into src. THEN, inside src, we will find our package 'cse1030'. Submit the entire package with the line 'submit 1030 Tutorial cse1030', where 'Tutorial' is the name specified by your instructor for the submission, and 'cse1030' is what we submit (i.e. the package).