It is obviously import to indent and format your code properly in order to allow you and others to read and understand it well. Sometimes this is not always easy to do unless you use an IDE such as Eclipse or (for Java) Netbeans.

Certainly in the case of Java, I personally don't think that it's a good idea for people who are relative newcomers to the language to use an IDE. Firstly, it gives you a double learning curve and secondly it conceals important knowledge from you, in particular, matter such as how the classpath and packaging work.
You will acquire a deeper knowledge of Java more quickly by using the command line tools such as javac, java, jar and javap.

If you are using these tools, along with a good text editor, it is essential to have a command line formatter. This kind of thing can be difficult to acquire and free formatters such as Jalopy quickly go out of date as Java is quite a moving target for formatting software as the language is evolving quickly.

Because the formatter I've worked on HERE, based on the work of Julien Rialland and actually using the same underlying software as the Eclipse IDE, supports the latest Java language additions it does require Java 1.8 as a minimum runtime. The jar is executable so is easily included in a script that will pass its parameters to the jar.
The Git repository for this code is at https://github.com/cehjohnson/javaformatter-cli

This is available under GPL 3 but please, if you like it and find it useful, consider donating using the button below.