Table of Contents
This article will cover how to download, install and configure one of the most popular IDE’s for Java – namely the Eclipse IDE.
To start developing programs with Java, you first have to download something called the Java Development Kit (also known as JDK).
And we will go through the steps of:
- Configuring JDK for Windows users
There might be additional step by step instructions in the future for Linux and Mac users. But for now Windows step by step instructions will have to do due to personal lack of experience with the other systems (apologies for this in advance for those of you that this means hardship to follow along in our articles).
Another thing Eclipse requires to start developing Java programs is a so called “workspace directory” – This is the directory where all of your project code and files will be stored on your computer.
On first Eclipse startup Eclipse will prompt you to select a “workspace directory” as you can see from one of my screenshots later in this article.
We will also cover how the user interface in Eclipse is set up and what each one of the different sections includes and does. As well as demonstrate how you create your very first Java program in Eclipse!
Downloading, installing and configuring JDK (and JRE) for Windows OS
JDK includes something called JRE (Java Runtime Environment), which is required if you want to run Java programs. JDK also includes development tools such as compiler and debugger.
The compiler is a computer program which translates our programming language (Java in this case) from human-readable code to so called “machine language” (1’s and 0’s) or machine code so that the computer can understand our program code (instructions).
The debugger is also a computer program with the purpose of testrunning the code you have written to see if its properly coded to ensure that it is runnable when executed in the CPU (Central Processing Unit/computer processor).
If your code is not properly written the debugger will become “trapped” and let the programmer know where exactly in the code this “trap” occurred so that the programmer can fix the errors and make the code error-free, valid and runnable.
Download JDK for Windows
First you need to visit: http://www.oracle.com/technetwork/java/javase/downloads/index.html, which is the website to download Java SE (Java Standard Edition).
This includes Java API’s, the Java Class Libraries that your programs can access to work with (reusable code already developed by other people).
It also includes the Java Language Specification which defines the rules for how Java is to be coded – and in turn interpreted by a computer when translated into machine code as well as a Java Virtual Machine Specification.
Once on the website you will be met by this page:
Press the “JDK Download” button and you will come to this page:
Scroll down until you see the following:
For me, sitting on a Windows 64-bit computer, I will go ahead and select “Windows x64 Installer”.
Once you select this a popup with terms and conditions comes up and needs to be accepted before you can actually download the installer .exe file.
There used to be an option on this site to get a 32-bit version of the installer as well – named x86 for 32-bit.
If your not sure which bitversion of Windows operating system you have, it’s easy to find out. Go to your Windows Searchbox in the startmenu. Type in the command
dxdiag and press
This might bring up a prompt asking if you wish to check if stuff in your computer is signed/has certificate – I usually just bypass this by clicking “Not interested”. After doing so, a dialog popup will appear filled with computer-related information.
This popup is a Diagnostic Tool for DirectX and has the information about your Windows bitversion that you might be looking for!
Another alternative method to look up your Windows bitversion for your computer is by visiting “Control Panel” in Windows, then go to “System” and check for “System Type”.
Installing JDK and JRE on Windows
Once you have finished downloading the JDK its time to install it on Windows. You do this by running the installer (the .exe file you just downloaded). This in turn will install both JDK and JRE!
Accept all the default installation settings, if you’re unsure and don’t have a need to specify a custom installation location for example.
If defaults were selected JDK will be installed in “C:\Program Files\Java\name-of-installer” and JRE in “C:\Program Files\Java\jre-versionnumber”.
This might be useful to keep track of for later when we install Eclipse IDE, since it might ask you where JDK and JRE are located at some point during your setup of Eclipse.
Downloading, installing and configuring Eclipse on Windows OS
Alright, so now that we have JDK and JRE installed and ready, we’re all set on the preparations to start our programming journey in Java with Eclipse – next up we will download and install our IDE of choice: Eclipse.
For this you have to visit the Eclipse website: https://www.eclipse.org/ and click the big orange button in the top-right corner that says “Download”.
Once on the Download page, download the Eclipse IDE on the orange button.
Make sure to check so that you download the bitversion you need for your computers operating system.
If you can’t find the Windows bitversion you need for Eclipse on Eclipse’s own website, try Googling it maybe. Although I believe the Eclipse download page automatically “senses” what your Windows bitversion is and selects it automatically for you, I believe it’s clever like that :P
Step 1 in installing Eclipse IDE:
Once you click the orange button, you will be redirected to another page where yet another orange button for the actual Download will be found!
The file you will be downloading is another executable .exe installer file.
Step 2 in installing Eclipse IDE:
Once the download is complete, run the Eclipse Installer.
Step 3 in installing Eclipse IDE:
When the Eclipse Installer starts up you will be prompted with the option to select one of various development environments. You will be selecting the one listed as “Eclipse IDE for Java Developers”.
Once this one has been selected you will be asked to choose the installation folder – or agree to their suggested default one, and select whether you wish to ge a desktop shortcut (could come in handy) as well as Start Menu entry.
Once these options have been chosen, you press “Install”, and accept the agreements – then the actual Eclipse installation will begin!
When Eclipse installation is complete
When the installation is complete, you will get the option to Launch immediately, if this for some reason doesn’t work and you selected to get a shortcut icon on your desktop – simply start it this way instead!
Once Eclipse has started, first thing it will do is ask you to select “the Workspace” that we discussed earlier in this article.
Setting up the workspace directory for Eclipse on Windows
Once Eclipse prompts you to select workspace, it will suggest a path, and also offer you the option of a checkbox which says “use this as default and don’t ask me again”.
Check this option so you don’t have to deal with this in the future, unless you need to change workspace directories for some reason (which can be done manually anyways).
By not checking this option during the time you’re using the same workspace, you will be bothered with annoying popup boxes constantly which can become a bit tedious after a while.
I will choose to keep their suggested workspace location, but if perhaps you have too little space on that suggested location, you can change it to better fit your system setup.
First startup of Eclipse IDE and the Welcoming Screen
Once this is all done, you will be greeted by a “Welcoming screen” with various options for how to get started with Eclipse.
In the bottom-left corner there is a checkbox with an option that you can de-select if you do not wish to have this welcome screen greet you every single time you start up Eclipse!
A few of the options you are presented with as you can see above (apologies for the icon bug in the image, please try looking beyond it) are as follows:
- Create a Hello world application
- This is a default starter program for most programming languages – demonstrating how to code in the most basic sense by testing the creation of a String (text variable) and then printout the string to the user
- Create a new Java project
- This is basically what we will be doing when working with Java on a “more real level”, your Java project will hold all files and code relevant for your Java project
- Checkout projects from Git
- Import existing projects
- This will allow you to import already created projects into this freshly installed Eclipse Dev Environment from someplace else
In the right-hand side of the Welcoming screen you will also be able to:
- Get an “Overview of features”
- Go through some “Tutorials”
- Check out “Sample codes”
In the Overview of features section you can learn about Basic Eclipse workbench concepts – probably very useful if its the first time you’re using Eclipse and if you intend to code a lot in Eclipse. Then it could be a good idea to get familiarized with the workspace layout and environment in general.
You can also:
- Learn about: Git with Eclipse
- Browse Eclipse extensions in the “Eclipse marketplace”
- Learn about Eclipse program development
- Here you will find all the basics one could possibly need to get started
Workbench layout overview
In the following sections you can read more about every section we marked in this picture.
Eclipse Package Explorer
Moving on from the Welcoming screen and on to the “workbench layout” (accessible in the top-right corner of the Welcoming screen). You will see the “Package Explorer” to the left side which is where all of your:
- code folders
- code files
… will be hierarchically presented and accessible to work with.
Eclipse Coding Area
The white area in the center is where you type in your code, once a file has been created for this. In the bottom of the centered whitespace area you can see tabs called:
The “Problems”-tab will list any- and ALL errors that might occur when you try to run incomplete or invalid program code.
This will be the most useful tabs out of the three by far (at least in my own experience with Java development in Eclipse).
Eclipse Workbench Menu Bar
You can hover all buttons to get a tooltip what each button does.
Above both the “Package Explorer” as well as the whitespace coding area there is a sort of menu bar with options:
- There is a “bug-like” icon which represent the option for debugger (green color)
- A play-like button (also green) next to it that is used to actually run the code that you write in various ways and configurations
- There is also a button for creating new code files, projects, etc. to the far left on this menu bar
Java classes and packages
Options to create “classes” and “packages” also exist in this menu bar.
What are Java classes?
Classes are the code files you will be working with when programming in Java.
What are Java packages?
Packages are a way to organize those code files and cluster related code files together (this is especially useful if you code bigger programs that require a lot of differnet code files to make up the whole program – packages bind all the different code files that are related together).
To the far right there also is an “open perspective” shortcut button which will allow you to switch between available so called “perspectives” such as:
- The coding workbench
- Debugging perspective
Eclipse Program Menu Bar
One more level above the first menu bar you will find the Eclipse “official menu bar” with tabs such as:
# The File option
The “File option” will allow you to:
- Create new files
- Open already existing files
- Save projects and files
- Switch workspace
- Import/export projects
- Access and set the properties of the Eclipse program
# The Edit option
The “Edit option” offers the basic editorial options such as:
- CTRL+Z (undo)
- CTRL+C (copy)
- CTRL+X (cut)
- CTRL+V (paste)
- DEL-key (delete)
- CTRL+F (find/replace)
# The Navigate option
The “Navigate option” I haven’t personally used that much myself yet, but it seems to include options to handle logs and something called “tasks” which I have yet to work with.
# The Run option
The “Run option” is one I’ve used quite a lot, since it can be used for both running your code as different configurations as well as debug your written code.
# The Window option
The “Window option” is quite useful as well since it offers Window- and layout preferences as well as “View-switching” capabilities. Which in Eclipse is switching between coding and debugging views (Both of these can be focused in separate views called “perspectives”).
# The Help option
The “Help option” offers options such as:
- Access to the Welcome screen once closed
- Access help manuals for Eclipse with tons of information
- Checking for updates
- Finding out installation details and general information about Eclipse
- Access to Eclipse marketplace to download plugins and extensions for Eclipse to extend it’s basic functionality
Workbench Flexibility and Rearrangement in Eclipse
The Eclipse workbench can be quite flexible and will allow you to move stuff around, enlarge/minimize different sections in the workbench as well as add and remove only the parts you personally want to have as part of your workbench!
If you move your mouse towards the borders of each different section in the workbench you will see what I mean when your mouse icon will switch to a “move icon” instead of a cursor icon.
The starting workbench layout has both taskbar as well as an area to the right called “outline” and since I don’t recall what these are used for or even if I ever have needed those when coding myself, I can choose to remove these alltogether.
Giving me more room for the Java Coding Area, and if I ever were to discover that these areas in fact were necessary for something, I have the Window tab in the Eclipse menu bar to help me get these sections back to the interface!
Creating a new (Java) project in Eclipse
You go to
File > New and then select
Java Project and will then be prompted to type in the name of your new Java Project.
Then you click
Next (which will be enabled after having typed in the name!) And then
Finish and Eclipse will then create the necessary folders and paths for your new Project so you simply can start working right away!
Once you press
Finish your project will show up in the Eclipse Package Explorer that we looked at earlier in this article. You will have the option to expand this folder by pressing the “tiny arrow” icon to the left of the folder.
Doing so will reveal an internal folder called
"src" as well as a “Library” called JRE System Library which you basically can ignore, it’s just there to let you run the code you write.
At this stage the
"src" folder is empty, but we need a
Class file to able to start out coding. So right-click the
"src"folder and goto
New > Class.
After having done this, you will get a popup box prompting you for the Class name of the Class you wish to create – this should be a name given according to the Java Naming Conventions for Classes.
They say that the first letter of the name should Always be a Capital letter, for example:
ClassName. This naming convention is sometimes referred to as PascalCase.
A more common term is the camelCase – which means every word that follows the first word have a Capital first letter.
And as you can see above an option is offered to create a “method stub” called:
public static void main(String args) – which is the so called “Main method” in Java.
The Main-method in Java is required for your program to run! So make sure to check this for now.
Once you press
Finish you will be presented with something that looks like this:
As you can see in the Eclipse Package Explorer to the left, both the package
"testproject" was created as well as the classfile
"testclass.java" (.java files = classfiles – they can be found in the workspace folder).
If you look at previous image you will see a field allowing you to name the package created for the class under
"source folder" at the top of the prompt window for creating a class.
Anyhow, a package was created to “house” our class files, and a .java file was created to hold our java programming code which in turn will be a part of our program.
And in the Eclipse Coding Area you will now see that the Java file that was just created has been automatically opened to work with and it contains some basic content that a class needs.
More about the actual contents of the file created will come in future articles about how to actually write code in Java.
But basically thats it, we’re done now and you can start coding! :D
Once you have typed the code you wish to have, you can press either
"Run" in Eclipse menu bar or the
"green Play-button" to run the code you have just written.
For quick introduction purposes, lets create the simplest version of a program: The Hello world! program real quick:
Where it now says:
// TODO Auto-generated method stub – you can replace this with the following code:
And then run the program like so:
Once you press
"OK" you will then see this:
Hotkeys in Eclipse that are useful to know for efficient coding and program use
Quickfix hotkey in Eclipse
In Eclipse there is a very useful hotkey which is:
CTRL + 1 by default, which offers you so called “quick fixes” to correct simpler coding errors that may be caused by the lack of
import statement to properly reference external files, or a specific class or library that you wish to use in your code but haven’t yet – or have forgotten to include or such.
Duplicating the row you’re standing on in Eclipse
CTRL + D hotkey can be used to duplicate the row you’re standing on :) Very useful and saves quite a bit of time in many situations.
Auto-formatting code in Eclipse
Another useful hotkey to know about is “Auto-formatting of code” which is:
CTRL + SHIFT + F, which is used when you have coded sloppy (try to avoid this to save time) or forgot to indent the code or did the wrong indentation in some places (even if you code everything correctly, this can still occur if you for example copy-paste code from another document where the indentation is different for that piece you copied). This hotkey will help you correct the indentation in these cases!
Search code hotkey in Eclipse
Another hotkey that works for almost ANY program, no matter where you are, is the hotkey to “search” the code:
CTRL + F
Infamous CTRL+Z (undo) also exist in Eclipse as well as Reverse-regret (redo)
CTRL + Z will regret the last thing you did and
CTRL + SHIFT + Z will take back your regretting of the last thing you did (undo and redo).