Formatting Java code
In the past I was using Eclipse as a tool for Java formatting. Eclipse allows you to call formatter from CLI which makes it super convenient to format lots of files easily. You can find description here.
But, I think that Eclipse’s time approached. I have found something called: Google Java Format. It’s very handy when it comes to quick formatting of the code. Take a look here.
/* PassLong.java */
package recipeNo004;
public class PassLong {
/* This is the native method we want to call */
public static native void displayLong(long value);
/* Inside static block we will load shared library */
static {
System.loadLibrary("PassLong");
}
public static void main(String[] args) {
/* This message will help you determine whether
LD_LIBRARY_PATH is correctly set
*/
System.out.
println("library: "
+ System.getProperty(
"java.library.path"));
long value = 1234;
/* Call to shared library */
PassLong.displayLong( value );
}
}
All you have to do, is to call it like this:
java -jar google-java-format-1.5-all-deps.jar PassLong.java
and here you go. Nicely formatted, beautiful, Java code.
/* PassLong.java */
package recipeNo004;
public class PassLong {
/* This is the native method we want to call */
public static native void displayLong(long value);
/* Inside static block we will load shared library */
static {
System.loadLibrary("PassLong");
}
public static void main(String[] args) {
/* This message will help you determine whether
LD_LIBRARY_PATH is correctly set
*/
System.out.println("library: " + System.getProperty("java.library.path"));
long value = 1234;
/* Call to shared library */
PassLong.displayLong(value);
}
}