Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Preparing the Development Environment for Java – Windows and Ubuntu

, 18 Nov 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
How to prepare the development environment for Java - Windows and Ubuntu

Introduction

Unlike .NET development where everything is streamlined and well-aligned, starting from the OS, the framework, the tools, the IDE and all others being written by one company, in Java development, you’ll experience “freedom”(1) of choice. I’ll start with a gentle introduction which the experienced may very well skip to avoid getting bored.

In order to get started developing in Java, we’ll need the following:

  1. An OS. I’ll showcase Windows and Ubuntu (Linux).
  2. A Java JRE. This is the most basic component required to run Java programs.
  3. A Java JDK. The JDK or Java SDK (IBM calls it that way) typically includes the JRE plus a compiler, tools for running various types of Java programs, packaging tools, extra class libraries and many more.
  4. An IDEIntegrated Development Environment. This is typically an MDI (Multi-Document Interface) application which provides certain convenience features for the developer:
    • Syntax highlighting – keywords are displayed in a certain color, local variables in another, etc.
    • Code completion – instead of having to type the whole keyword, or class identifier, a member and so on, an autocompletion prompt will appear (usually triggered by the user typing a dot or other notable event) easing your typing and avoiding typos.
    • Interactive debugging – Allowing the user to control the execution of the program by inserting breakpoints, stepping over, into or out of code, watching expressions (variables, fields, etc.), modifying internal data or even (very few IDEs allow) stepping back.
    • Tracing – in case you need to inspect internal data but breaking into the debugger cancels the bug or triggers other unwanted condition or the data changes too fast, you can watch expressions in a specially designed tool window without interrupting the flow of the debugged program
    • Source control integration – allows the user to send/push/checkin/etc changes to file(s) into a repository, obtaining the latest version, comparing versions, merging, branching and many more operations
    • Visual designers – For UI modules or elements, most IDEs offer some kind of preview of the developed interface, showing the developer pretty much how things will look and behave without needing to recompile, run and browsing to that particular interface
    • Packaging and deployment – Features for creating a package of the application, be it JAR, WAR, DLL, ZIP, APK etc. Furthermore, many IDEs will help you push a site to a webhosting provider, cloud service and so on.
    • .. and a whole lot more but let’s try to keep things shorter

The OS

There’s not much to cover, in my opinion, here. I guess if you reached the level of developer, you’ll be able to install an OS. In fact, just reading this article on a PC usually means that you already have an OS installed. Both Windows and Ubuntu have a simple install process, shipped as a CD or ISO image that you can boot from a USB drive, a DVD, or insert into a Virtual Machine.

In my experience, I’ve used Windows 8.1 64 bit and Ubuntu 13 in a VMware virtual machine. Recommended hardware specs, IMHO would be:

  • 1.5GHz+ Quad-core CPU
  • 4 GB RAM
  • A decent SSD

Sure, these aren’t the bare minimum requirements. All presented here could run on a single-core 1GHz CPU with 1GB RAM and 5400rpm HDD. The recommended specs are here to tell you where the comfort zone begins.

Java 7 (the latest at the time of this writing) supports Windows down to XP SP3 and Ubuntu since 10. The details of the system requirements are quite interesting, the minimum amount of RAM being 64 MB.

Since Java has this promise of Write Once Run Everywhere (contradicted in practice by almost all my Java fellow developers but let’s skip that part) I’ve had installed both OSes so I can see how well this goes.

One notable part is that Ubuntu (like most of the *NIX platforms) is not so friendly when installing certain pieces of software even with the advent of apg-get, rpm and so on.

JRE

Windows does not come by default with any JRE or JDK, the Java support being null. Ubuntu 13 comes pre-loaded with OpenJDK JRE. This is just the JRE and not a JDK in spite of its name. Furthermore, it will not support JavaFX and IntelliJ IDEA IDE will pretty much reject it. So, IMHO, Ubuntu has, at least for me, no Java support out-of-the-box either.

JDK

Since we have to install a JDK anyway (which typically includes a JRE), I chose the ‘original’ vendor, Oracle (former being Sun but acquired a few years ago by Oracle). Typically the Oracle JDK has the widest support for Java technologies (such as JavaFX) and it’s well maintained. Others, such as IBM, do not even support the #1 OS on the market, Microsoft Windows. The Ubuntu Software Center, which simplifies installing of software, having a graphical interface, does not encourage the installing of the Oracle JDK. More on this shortly.

Windows has a clean experience, you just go to the JDK downloads page (you don’t need to bookmark this link, just type ‘download jdk’ in your favorite search engine, get the first Oracle link and choose JDK when confronted with JDK, JREs and others). Select your platform (Windows x64 in my case), download the .EXE file, run it, next -> next -> finish.
Be careful that recently Oracle has started to bundle some crapware – like Ask Toolbar extension along with the JDK, uncheck the necessary boxes :

OracleIsLame

Let’s get back to Ubuntu now. There are two ways to install the Oracle JDK on Ubuntu, that I know of and have tried: the hard one and the easy one. The hard one means doing it manually all the way, by downloading the .tar.gz package from Oracle, unpacking it, placing the files in the right directories, editing the JAVA_HOME environment variable, setting up alternative aliases and many more manual steps that are prone to mistyping and hair pulling during and after the process. If for some reason, you want to know the details or you are constrained to use this route, then follow this link (“don’t worry” there are “only” 17 steps).

The easy one is described at ‘Install Java JDK 7 on Ubuntu 12.04 (JavaFX is included in the installation)‘. Basically you just open up a terminal window and:

  • sudo add-apt-repository ppa:webupd8team/java
  • sudo apt-get-update
  • sudo apt-get install oracle-jdk7-installer

The first command adds a new APT repository so the third command will be able to get the Oracle JDK 7 Installer. The second command updates all APT packages so all dependencies will be up to date. Finally, the third command will install the Oracle JDK 7 Installer. This will self-start after download and will display a text-GUI which will do all those 17 steps in the manual way described above. The bulk of the work will be downloading the .tar.gz from Oracle and will display a kind of progress bar. Finally the JDK will be installed and operational.

On both OSes listed above the JDK will be operational without needing to restart the OS or do anything else. Regardless of the OS, open up a terminal window (Win-R -> CMD [ENTER] for Windows) and type:

java -version

This will test that the Java executable, part of the JRE is correctly installed, accessible in the PATH and if these conditions are met, it will display the exact version similar to:

[Windows]

java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

[Ubuntu]

java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

Notice that the versions differ slightly (update 25 vs update 45) but this is irrelevant. The same features are present, the newer one just has a few more bugfixes.

Do the same for:

javac -version

This will test the same about the Java compiler (that’s what the final c stands for). The compiler will probably be less verbose but that’s not an issue.
Having finished this, we’re left just with installing the IDE.

IDE

There are three popular Java IDEs available (and countless other less heard-of):

Eclipse seems bloated to me and a bit alien, NetBeans ok-ish but coming from a .NET development background with many years of ReSharper (Visual Studio plug-in developed by JetBrains, makers of IntelliJ IDEA), I’ve chosen IntelliJ IDEA. Pretty much the same keyboard shortcuts, same behavior, feeling. Of course, I’ve tried them all and there were a few advantages which NetBeans had over IntelliJ IDEA, mainly at JavaFX templates and JavaFX autocompletion support. But that’s pretty much from the fact that both JavaFX and NetBeans are being developed by the same company, Oracle.

On Windows, NetBeans and IntelliJ IDEA provide smooth installers while Eclipse provides a simple archive that you just extract somewhere and just run eclipse.exe (you might create a shortcut somewhere to ease startup the next times).

On Ubuntu, you can install any of the three main IDEs via Ubuntu Software Center but you’ll get old versions. For Eclipse, it’s 3.8.1 vs 4.3.1 (significant differences, I assure you), for NetBeans it’s 7.0.1 vs 7.4 (this was quite touchy since 7.0.1 doesn’t include JavaFX support, and I played with JavaFX for a while) and finally, for IntelliJ IDEA it’s 12.1.0 vs 12.1.6

JetBrains had the most care of updating the Ubuntu Software Package and they have much better technical support for it. Therefore I just installed it using Ubuntu Software Center. For NetBeans, I had to download it manually, tried to start the .sh file directly but there was a glitch, it seemed to require chmod-ing to make it executable. I thought you could just ship it executable directly from within the .tar.gz but my Linux skills are quite lacking so it could be either way. In the end, it starts and works. Eclipse did not get tested.

Of course, subjectively, I had a lot of glitches and misunderstandings working on Ubuntu after 18 years of using Windows. Things ranging from having the control icons in the left side of the title bar (a la Mac), snapping windows to the edges of the monitor involves keeping them there for, what seems like, 500ms in order to stay snapped. At least, the bash tab autocomplete works quite well.

All in all things went ok, I’ve developed a toy app on JavaFX (on Windows), JAR’d it and dragged it over in the Ubuntu machine and it worked excellent. Maybe it’s because the app is extremely simple or maybe that promise of Write Once Run Everywhere is respected in most cases.

While toying around in IntelliJ, I’ve assembled the most common (at least for me) commands and their associated shortcuts. Most mature IDEs offer these features or similar ones. Here is my set:

  • Force completion – CTRL-Space
  • Type lookup (independent of current imports) – CTRL-ALT-Space
  • Line-comment selection – CTRL-/
  • Increase / decrease indent – TAB / SHIFT-TAB
  • Quick-fix / Intent – ALT-ENTER. Really often used!
  • Reformat file – CTRL-ALT-L
  • Duplicate line – CTRL-D
  • Cut current line (“delete to clipboard”) – SHIFT-DEL without selection
  • Debug project – SHIFT-F9
  • Step over – F8
  • Step into – F7
  • Step out – SHIFT-F8
  • Resume – F9
  • Go to type (class) – CTRL-N
  • Go to file – CTRL-SHIFT-N
  • Go to declaration – CTRL-B
  • Go to implementation – CTRL-ALT-B

For more shortcuts, consult the official “cheatsheet” from JetBrains.

At this moment, I consider to have at least two development environments set up and ready to run. In the next posts, I’ll tackle some Java syntax and platform peculiarities with examples and cautionary tales.


(1) – There’s enough freedom of choice on Windows / .NET too. What really bothered me is that this freedom means usually having a lot of components developed in every other imaginable way/style and assembling them together is sometimes harder than solving a murder mystery. Things get better over time with the help of Maven, Apache Software Foundation and even Oracle.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Andrei Ion Rînea
Software Developer (Senior) IBM, Business Analytics
Romania Romania
No Biography provided

Comments and Discussions

 
GeneralNice instructions and fairly even descriptions of the IDEs PinmemberMike Riley - QUSA19-Nov-13 12:57 
GeneralRe: Nice instructions and fairly even descriptions of the IDEs PinmemberAndrei Ion Rînea20-Nov-13 0:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 18 Nov 2013
Article Copyright 2013 by Andrei Ion Rînea
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid