What's new

[Tutorial] Getting Started in Java (Eclipse)

iRoflu

Admiral Squatbar
Staff Member
Head Mod
Gold Supporter
Joined
Apr 25, 2016
Messages
983
Reaction score
37
Location
World Martial Arts Championships
Gender
Male
For this tutorial, I'll be using Eclipse, as with any future tutorial I may make. I figure the first thing that you guys need to know, is how to start a Java project using Eclipse. Some may have already figured it out, and some may have already figured it out, or already know, in which case you can skip all of this.
This thread is only to show people how to start a Java project, including creating packages and classes.

Step 1:
First, open Eclipse.
It will ask you to set a Workspace, which is where all of your work will be located. As you can see in the picture, my Workspace is set to my School folder on my desktop, where it's easily accessible in case I ever need to access it. Wherever you decide to put it, it's up to you.
Also, if you want to, you can choose to set as default location and do not ask again. I did not choose this, just in case I ever need to change it without looking through the settings, but it's up to you.
Click 'Ok' once you've selected a Workspace.


Step 2:
After Eclipse is done loading, you might see a welcome page. You can close that out.
To start a new project, go to 'File', then 'New', then 'Java Project'.

Then, this box will pop up:

Type in whatever project name you want, then click Okay.

Step 3:
Now that your project is created, look in the far left panel of Eclipse, in the 'Package Explorer'. Find your newly created project, and click the down arrow next to it to expand it. You'll see two folders: 'src' and 'JRE System Library'. Ignore 'JRE System Library', what we want is the 'src' folder.


Step 4:
In order to actually code something, we need classes, but first, we need packages to store them. If you create a class without a package, it will go under a 'default package', but we don't want that if we're going to be professional, especially if we want proper organization. Right click the 'src' folder, go to 'New', then click 'Package'.

A box will pop up, and all you need to do is fill out the name of the package. There is a naming convention for packages, which can be found (here), and for this example, I will be naming it "com.emucoach.TestProject.model"
The 'com.emucoach." is based off of the site of the developer, or company, etc. The 'TestProject' is, of course, the name of the project. Then, after that, I have the ".model". The model package is where we put our main code, other than our controller class, which will be discussed in a future tutorial.

Now click Okay.

Step 5:
Now look back to the 'src' folder, and you'll notice the package we just created is there. The icon next to it is somewhat blank, meaning there's nothing inside it. So now that we have our package, we need a class. Right click the package, go to 'New', then click 'Class':

A box will pop up, where you can type the name of the class. All of the settings should be exactly where they need to be for now, except for 'Generate Comments'. You don't need to use this, however it really helps in explaining the code to you and future developers. It has other uses, but that's not important right now.

Now click Okay.

Final:
Now, in the center of Eclipse, you'll see some code. If you chose to 'Generate Comments', then you'll see something along the lines of:
Code:
/**
* @author Iroflu
*
*/
The @author is the author of the code. It also helps to have '@version' under that, which for now, it's best to use the current date. So it would be: @version 6/29/2016


As for the actual coding, I'll have to create another tutorial for that later.

I hoped this helped, and feel free to ask any questions.
 

ExO

Administrator
Staff Member
Admin
Joined
Mar 29, 2014
Messages
4,211
Reaction score
108
Very nice! Thanks for the useful thread. :)
 

Rhisk

Senior User
Senior User
Joined
Feb 16, 2016
Messages
67
Reaction score
4
Location
Cuba
jeje you forgot the Hello World.
 

Chief

Mythical User
Mythical User
Joined
Jun 24, 2014
Messages
183
Reaction score
10
Location
Root
Very nice as well! I look forward learning more:)
 

NeoLordan

Member
Member
Joined
Aug 24, 2018
Messages
17
Reaction score
0
thank you for the help full starter tutorial i have to do it for a project im in
 
Top