# Learn Java with BlueJ
by Seth Kenlon

An easy criticism to leverage against any programming language is that there's a lot of boilerplate text to memorize.
Before you can get comfortable with starting a project from scratch, you have to remember the preambles that, in theory, ought to be easy to remember since they're usually relatively short and repetitive.
In practice, though, boilerplate text is too obscure in meaning to become an easy habit, but it's essential for a programme to run.

Sometimes the text is just one line.
For example, a shell script opens with a simple "shebang":

```
#!/bin/sh
```

Other times the inttroductory text is more complex.
For instance, a Java method often looks something with this:

```
import java.io.Foo; 

public class Main {
	public static void main(String[] args) {}
	// some code here
}
```

And that's just the hurdle to getting started.
The University of Kent, however, is sensitive to this beginner-level struggle, and develops and maintains the [BlueJ](https://www.bluej.org/), an open source IDE for students of Java.

## Bluej templates 

BlueJ is an integrated development environment (IDE) for beginners.
Its interface is clean and simple, with a mere 4 menus in its main menu bar.
As you build a project, you get to see a sort of mind map of how your Java files fit together.

![Your project layout](bluej-map.jpg)

When you create a new class, BlueJ generates a clean but robust template giving you hints toward what you need to provide.
Using a subdued colour scheme, different code elements are kept separate from one another so it's easy for to tell a class from a method or a comment.

![A BlueJ template](bluej-new.jpg)

## Using BlueJ can help you understand how Java works

If you're new to programming or just new to Java, understanding advanced concepts like variable scoping and loops and conditionals can be difficult. 
It doesn't help that as you're learning to program, most of the code you type basically looks and feels the same: they're all vaguely meaningful, yet oddly similar, words that seem to make as much sense when read backwards as they do when read forwards.
It can be nearly impossible to tell a variable apart from a keyword that's a part of the language, and even with the assistance of indentation and braces and semi-colons, it all starts to blur together.

BlueJ is designed to clear away this confusion.
By using coloured backgrounds, BlueJ helps you visualize the structure of the code you're writing.
You don't have to rely on indentation to see that a Java method falls within a specific class, because you can see the blocks of code.

![Blocks of code](bluej-blocks.jpg)

More importantly, BlueJ helps you trace errors back to their cause.

For instance, if you define a variable called ``foo`` inside of an ``if`` statement, and then refer to ``foo`` outside of that statement, BlueJ correctly alerts you of an error.
It doesn't tell you how to fix the error, and it doesn't offer to correct it for you, but it does make you ponder why the error exists.

![A friendly error](bluej-scope.jpg)

There are plenty of hints in the visual layout, and should you realize through research or reading back through notes that your ``foo`` variable is "trapped" inside the ``if`` loop's scope, then you can make adjustments.

![Fixed it](bluej-fix.jpg)

BlueJ isn't an all-purpose IDE.
It's very much a learning tool, and it's purposefully less helpful than a full IDE like [Eclipse](http://eclipse.org) or [Netbeans](Netbeans). 
It's meant to help you learn the language, not to type faster and more efficiently.

## Installing BlueJ

BlueJ is written in Java, so to run it you must [install Java](https://opensource.com/article/19/11/install-java-linux).
You have to do that to program in Java anyway, so you may already have installed Java in anticipation of learning. 
Howeven, to use BlueJ, you must have the same version of Java used by BlueJ, so check the version you installed against what BlueJ requires.
JavaFX is also required as a separate download, so follow the instructions on the BlueJ site.
After you've installed Java and JavaFX, launch the BlueJ installer.

BlueJ has downloadable installers for Ubuntu Linux, Windows, and Mac OS.
It also offers a "generic" installer, delivered as a JAR file, the usual Java format.
If you're using the generic installer, launch it with Java from a terminal:

```
$ java -jar ./BlueJ*jar
```

Once it launches, point it to the directory to use for installation.
I suggest using ``$HOME/.local/bin`` directory, if it exists, because that's generally in your [path](https://opensource.com/article/17/6/set-path-linux).
Once it's installed, you can launch it from a terminal:

```
$ bluej
```

Or you can create a ``.desktop`` file so it shows up in your applications menu.
This ``.desktop`` file is all you need:

```
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Name=BlueJ
Comment=A simple powerful Java IDE
Categories=Application;Development;
Exec=~/.local/bin/bluej/bluej
Icon=~/.local/bin/bluej/icons/bluej-icon-512-embossed.png
Terminal=false
Type=Application
```

Save the file as ``bluej.desktop`` to ``~/.local/share/applications`` and soon BlueJ will show up in your application menu.

## Painless Java 

Java is a robust language with many [serious fans](https://opensource.com/article/19/9/why-i-use-java) and a staggering variety of applications, from [tabletop gaming](https://opensource.com/article/19/6/how-use-maptools) [utilities](https://opensource.com/article/18/4/pcgen-rpg-character-generator) to [XML processors](https://xmlgraphics.apache.org/fop/) and [PDF generators](https://gitlab.com/pdftk-java/pdftk) and [music applications](https://www.linuxsampler.org/downloads.html), to its credit.
BlueJ aims to make Java easy to learn, regardless of whether you're an experienced programmer or still struggling with you first "hello world".
Install it today, and get started down an exciting cross-platform programming adventure of your own!