- Download, installation, configuration of JDK (and JRE) for Windows
- Download, install and configure Eclipse on Windows
- Setting Workspace directory for Eclipse in Windows
- First startup of Eclipse Integrated Development Environment (IDE) and Welcoming Screen
- Workbench Layout
- Eclipse Package Explorer
- Eclipse Coding area
- Eclipse Workbench menubar
- Eclipse Program menubar
- Workbench flexibility and rearrangement
- Creating a new Project in Eclipse
- Hotkeys in Eclipse useful to know to code effeciently
In this post we will go through how to install and configure/setup one of the most popular Java Integrated Development Environments (IDE) for beginners: Eclipse.
Now to be able to start developing java you first have to download something called Java Development Kit (JDK).
This will therefore be the first section we walkthrough and discuss and we will do so for Windows users primarily in this post, perhaps in the future additions will be made to cover instructions for Mac and Linux users as well, but for now Windows will have to do due to lack of time as well as experience of those operating systems (apologies for this in advance).
Another thing required to work with Java code in Eclipse is a “workspace” directory, this is the directory that you designate to hold all the work you will be producing when coding and saving that code. On startup of Eclipse you will get prompted to select this folder as I will demonstrate with an printscreen image later in this post.
We will also cover how the user interface of Eclipse is setup and what each different section includes and does, as well as how to create your very first java program in Eclipse!
Another post will be published short after this one which will be about our very first official Java program in Eclipse which will be a “testprogram” to demonstrate the basics of Java programming such as:
- Syntax (including indentation what it is and how its used and why)
- Data types
- conditional statements
- various types of loops for interation of code
- basic variables to store information
- more advanced ways of storing information (arrays and arraylists)
- methods, in and out- parameters
- variable scope
- documentation of code and-
- basic interaction with user such as input/output
Download, installation, configuration of JDK (and JRE) for Windows
JDK includes something called JRE (Java Runtime Environment) which is needed to run Java programs, plus development tools (such as compiler and debugger).
– The compiler is a computer program which translates our programming language – in this case Java which is considered a “high-level langauge” which means that it is very abstracted and simplified to ease the coding for humans compared to how machine language which the computers processor actually handles looks like (1’s and 0’s). Lower level coding languages are “closer” to how machine language actually looks like which means less abstraction and simplifications to ease the coding process for humans.
– The debugger is also a computer program with the purpose of testrunning the code you have written to see if its properly coded so its runnable when executed in the CPU (processor) – if your code is not – the debugger will be “trapped” and let the programmer know where in the code this trap occured so that the programmer can rectify the errors and make the code error-free, valid and executable.
Download JDK for Windows
First you need to visit http://www.oracle.com/technetwork/java/javase/downloads/index.html which is the Java SE (standard edition) download site.
Once there, under “Java Platform, Standard Edition” it will say: “Java SE 8u(xx)”, where “xx” is the latest update number, Click the “JDK Download” button.
Then you have to “Accept License Agreement”.
Finally you have to select the operating platform you will be downloading JDK to, whether you are on Windows x64 (64-bit Windows OS), or Windows x86 (32-bit Windows OS).
If you are not sure which Windows OS you have – its easy enough to check by going to the search box in the Start Menu (if you have Windows 7) and typing in the command “dxdiag” and pressing ENTER. This might bring up a prompt that ask if you wish to check if stuff is signed/has certificate – I usually just bypass this by saying that I am Not interested.
Doing so will bring up the following box which is Diagnostic tool for DirectX and has the information you’re looking for:
Another method to check whether you have 32-bit or 64-bit OS is by going to Control Panel > System and check System Type. This might actually be easier for some.
Install JDK and JRE on Windows
Once downloaded the JDK its time to install it on Windows. You do this by running the installer called: “jdk-8u(xx)–windows-x64.exe” for example if you have and chose to download JDK for 64-bit OS. This will install both JDK and JRE!
Accept the defaults installation settings if you’re unsure and dont have a need to specify custom installation location for example.
If defaults are selected JDK will be installed in “C:\Program Files\Java\jdk1.8.9_xx” where xx is the latest upgrade number and JRE in “C\Program Files\Java\jre1.8.9_xx”.
Might need to know this in case Eclipse asks for JDK or JRE at any point in time during your setup of Eclipse Integrated Development Environment.
Download, install and configure Eclipse on Windows
Alright, so now that we got JDK and JRE covered we’re all set on the preparations to start programming in Java, now lets get our Integrated Development Environment of choice: Eclipse.
For this you have to start by visiting Eclipses website: http://www.eclipse.org/downloads/
From there you select “Download xx-bit” (i think it senses what bit operating system you have – it seems to be intelligent like that) under “Get Eclipse Neon”. And click the “Download button” on the page you get redirected to. File you will be downloading is called: eclipse-inst-win64.exe at the time of this post being written (26 of september 2016).
Once downloaded you run the .exe file and this will start the Eclipse Installer.
Once the installer has started, you will be prompted with the option to select one of various development environments. You will be selecting the top listed one called: “Eclipse IDE for Java Developers”.
Once selecting this one you will be asked to choose installation folder- or agree to their suggested default one, and select whether you wish to get a desktop shortcut (could come in handy) as well as Start Menu entry.
Once these options has been chosen, you press “Install”, Accept the agreements, and the installation will Begin! Once done you will get the option to Launch immidiately, if this for some reason doesn’t work and you selected to get shortcut on desktop – simply start it this way instead. Let’s do it! 🙂
Once Eclipse Neon has started first thing it will ask you to do is select the Workspace.
Setting Workspace directory for Eclipse in Windows
Once prompted for this, it will suggest a path, and also offer the option of a checkbox which says “use this as default and don’t ask me again” – check this option and you don’t have to care about this unless changing workspace directories (which can be done manually anyways). But by checking this option during the time you’re using the same workspace you don’t have to be bothered with annoying popup boxes
I will choose to keep their suggested designated workspace location, but if perhaps you have to little space on that suggested location, you can change it to better fit your system setup.
First startup of Eclipse Integrated Development Environment (IDE) and Welcoming Screen
Once this is 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 an option however 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 (apoligies for the icon bug in the image- please try looking beyond it) are as follows:
- Create a Hello world application : which is a standard program for most programming languages demonstrating how to code in its most basic sense by testing the creation of a string and the printout of said string.
- Create a new Java project : Is basically what we will be doing when working with Java on a “more real level”.
- Checkout projects from Git : This is an option to include projects you have managed with the version management tool Git (a bit advanced for beginner).
- Import existing projects : Will allow you to import already created projects into this freshly installed Eclipse Dev environment.
In the right-hand side of the Welcoming screen you will also be able to get “Overview of features”, go through some “Tutorials”, check out “Sample codes”.
In the “Overview of features” you can learn about basic eclipse workbench concepts (probably very useful if you intend to code a lot in Eclipse – then could be a good thing to get familiarized with the workspace layout and environment). You can also learn about: Git with Eclipse, browse eclipse extensions in the “Eclipse marketplace” and learn eclipse program development (all the basics one could possibly need to get started).
Eclipse Package Explorer
Moving on from the welcoming screen and on to the “workbench layout” (accessible in top-right corner of the welcoming screen by the way), you will see the “Package Explorer” to the left side which is where all your projects, code folders and codefiles 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 “Problems, Javadoc, Declaration”. Problems 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 tab of the three by far (at least in my own experience with Java development in Eclipse).
Eclipse Workbench menubar
Above both the Package Explorer as well as the whitespace coding area there is a sort of menubar with options – there is a “bug” option for debugger (green color), a play button (also green) next to it used to actually run the code you write in various ways and configurations, there also is a button for creating new code files, projects etc. to the far left on this menubar.
– Java classes and packages
Options to create “classes” and “packages” also exist in this menubar. Classes are basically the code files you are working with when programming in Java and packages are a way to organize those code files and cluster related code files together (especially useful if you code bigger programs that require a lot of different code files to work as one program – packages bind all the different code files together to the one program).
– Eclipse perspectives
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 coding workbench, debugging perspective, etc.
Eclipse Program menubar
One more level above the first menubar you have the Eclipse official menubar with tabs such as: File, Edit, Navigate, Search, Project, Run, Window and Help.
File option will allow you to create new files, or open already existing ones, save projects and files, as well as switch workspace and import/export projects and last but not least – access and set the properties of Eclipse.
The Edit option offers the basic editorial options such as Ctrl + Z (undo), copy (Ctrl + C), cut (Ctrl + X), paste (Ctrl + V), delete (DELETE-Key) as well as find/replace (Ctrl + F).
The Navigate option I haven’t personally used that much but seem to include options to handle logs and something they call “tasks” which I have yet to learn.
The Run option I’ve used quite a lot in contrast though, since it can be used for both running your code as different confugrations as well as debug your written code.
The Window option is quite useful as well since it offers Window and layout preferences as well as View-switching capabilities which in Eclipse basically is the power to switch between coding, debugging (which can be focused in separate views called “perspectives”) or simply show views which you are currently not able to see in the workbench layout.
The Help option offers options such as access to the Welcome screen once closed, access to Help manuals for Eclipse with tons of information, possibility of checking for updates, finding out installation details and general information about eclipse as well as access Eclipse marketplace to download plugins and extensions for Eclipse to extend its basic functionality.
Workbench flexibility and rearrangement
The Eclipse workbench is also very flexible and will allow you to move stuff around, enlarge, minimize different sections in the workbench as well as remove and add only the parts you personally want to have part of your workbench!
If you move your mouse towards the borders of each different section in the workbench are you will see what I mean when your mouse icon will switch to a “move icon” instead of cursor icon, etc.
For example 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 that I ever have needed those when coding myself, I can choose to remove these alltogether, giving me more room to 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 menubar to help me get these sections back to the interface!
Creating a new Project in Eclipse
You go to File > New and 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 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 Eclipse Package Explorer, you will have the option to expand this folder by pressing the tiny arrow 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, its 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 be able to start our coding. So right-click the “src” folder and goto New > Class.
After having done so, you will get a popup box prompting for the Class name of the Class you wish to create – this should be a name given according to the Naming Conventions of Java programming for classes (which is that first letter of the name should be capital letter for example: ClassName, if more than 1 word use CamelCase which basically means every words first letter gets capitalized).
And as you can see above an option is offered to create a “method stub” called: public static void main(String args) which basically is the so called “Main method” of Java programming which allows programs to be run in general.
Once you press finish you will be presented with something looking like this:
As you can see in the Eclipse Package Explorer to the left, both the package “testproject” was created (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) as well as the classfile (.java).
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 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 contents that a class needs.
More about the actual contents of the file created will come in next post about how to code in Java.
But basically thats it, we’re done now and you can start coding!
Once you have typed the code you wish to have you can press either Run in Eclipse menubar 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: 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 see this:
Hotkeys in Eclipse useful to know to code effeciently
In Eclipse there are a very useful hotkey to know which is:
CTRL + 1 by default which offers you so called “quick fixes” to correct simpler errors that may be caused by the lack of import of a specific class you want to use in your code or such.
Another useful hotkey to know about is “Auto-formatting of code” which is:
CTRL + SHIFT + F, which is used for example when you have coded sloppy or forgot to indent the code or do indentation wrongly on some places – this hotkey will help you correct the indentation in these cases!
Another hotkey that works for almost ANY program no matter where you are is the hotkey to “Search” the code:
CTRL + F.
Enjoy and hope that you got a nice introduction to Java Integrated Development Environment (IDE) Eclipse and how to work with it 🙂
I know I did 😉
I recently just finished another article which in comprehensive and much detail cover all the areas that can be useful to know about when starting programming in Java. Until next time!