ECLIPSE

Checkstyle is a tool to help programmers write Java code that adheres to a coding standard. This plugin is ideal for projects that want to enforce a coding standard.

Checkstyle does this by inspecting your Java source code and pointing out items that deviate from a defined set of coding rules. Apart from using the Eclipse Checkstyle plug-in you can also use Checkstyle from the command line or as part of an Ant build.

What’s a coding standard:

It can be any convention that you want to enforce e.g All classes names should start with a capital letter.

A rule like ‘All local variables that never get their values changed, must be declared as final’.

Good coding practices like ‘Duplicate code should not be allowed’, ‘a block should not be empty’.

Class design standards like ‘Only static final members may be public; other class members must be private’.

STEP 1: Install the Checkstyle plugin in your Eclipse IDE using-

STEP 2: Configurations

Sun Microsystems (now Oracle) uses some conventions and rules for developing Java; same rules and conventions come along with this plugin to your Eclipse IDE, which means that you can write Java code by following code standards followed by Sun Microsystems. You can always turn off certain checks from this default check configuration or even you can add your own new check.

After plugin installation is successful, just restart the IDE (which is needed to activate the settings). Go to window-> Preferences and click on checkstyle as in this screenshot.

If you want to use default check configuration, click on any of the entries as shown above and set it as default.

But, if you want to turn off certain checks or add your own one, follow the steps below:

1. Make a copy of the checks.

2. Select your new configuration and press Configure.

3. Activate or De-activate the checks.

4. Make this new setting your default one.

You are done. Go to project Explorer, right click on your Java Project, select Checkstyle and click on ‘check code with checkstyle’. Now, in every Java file you will observe Checkstyle highlighting code snippets violating code standards. Enjoy 🙂

I recommend using Checkstyle in your Java project. This will not only adhere your code with a set of standards but also increase your productivity by making the code much more readable and simpler.

Eclipse is one of the best IDEs which developers use for their development tasks. It has provided the shortcuts to the most common actions that they perform. Here, I have listed the most useful shortcuts which result in faster development using the IDE. Enjoy 🙂

Ease of Navigation –Eclipse Shortcuts

CTRL SHIFT R – Open a resource. You need not know the path and just part of the file name is enough.CTRL + SHIFT + T – Open / Search for Types.CTRL PAGE UP or PAGE DOWN – Navigate to previous or next file from within the list of all open files.ALT – Go to previous or next edit positions from editor history list.CTRL E – Open a file (editor) from within the list of all open files.CTRL + SHIFT + P – Go to the matching bracket.

Java Editing with ease– Eclipse Shortcuts

CTRL / – Comment a line.F3 – Go to the declaration of the variable.F4 – Show type hierarchy of on a class.CTRL + T – Show the inheritance tree of the current Java class.CTRL + Shift + F – Format source code.ALT SHIFT Z – Enclose block in try-catch.SHIFT F2 – Show Javadoc for current element.CTRL SPACE – Type assist.CTRL SHIFT U – Find reference in file.CTRL + Space – Content assist/ code completion.CTRL + O – Show all methods of the current class, press CTRL + O again to show the inherited methods.F12 – Focuses on the editor (especially helpful if you work with Fast Views).Ctrl + M – Maximize Java editor.CTRL + Shift + O – Organize the imports; will import the missing import statements.CTRL + Q– Go to position the cursor at the last changed position in the editor.

Some more with Arrow Keys – Eclipse Shortcuts

CTRL + Left – Move one element to the left.CTRL + Right – Move one element to the right.CTRL + ALT + – Up/Down Copy line.ALT + Up / Down – Move line up / down.ALT + SHIFT Up / Down – Select the previous / next syntactical element.ALT + SHIFT Up / Down / Left / Right – Extending / Reducing the selection of the previous / next syntactical element.CTRL + Up / Down – Scroll up / down a line in the editor.

FindBugs is an open source program which looks for bugs in Java code. It performs static analysis for the Java byte-code to identify hundreds of different potential types of errors in Java programs.The software is distributed as a stand-alone GUI application and as a plug-in for IDE’s like Eclipse, Netbeans, IntelliJ IDEA.

Companies like Google, Sun Microsystems(now Oracle) and many more Institutions and Projects are the financial supporters of FindBugs which itself says about its usage and popularity among developers and organizations around the world. In this post I will teach you how to use FindBugs plugin for Eclipse IDE.

What type of errors FindBugs tells:

Any coding mistake, any probable bug, coding bad practices e.g HashCode and Equal problem, code that is confusing, anomalous, or written in a way that leads itself to errors e,g dead local stores, unconfirmed casts, redundant null check of value known to be null, coloneable idiom etc.

You are done. 🙂 FindBugs will run, and problem markers (displayed in source windows, and also in the Eclipse Problems view) will point to locations in your code which have been identified as potential instances of bug patterns.

I recommend using FindBugs to find errors in your Java project. This will not just automatically find bugs but give you alarm of many potential bugs at the early stages of development.

In this post I will show you, how you can debug a remotely deployed java application using eclipse IDE (the post is applicable for a plain java program as well as applications deployed using Web Servers or Application Servers e.g weblogic, websphere etc)

Why you really need to debug a java application which is deployed remotely:

Lets consier my case,

I stay in India and develop java application in windows machine. Project team deploys the same java application to the unix servers in USA and come back to me saying “The Java application is not working there”

But, how this can happen…!!! I tested everything at my windows machine and everything was just fine!!

What you do to resolve this (all possible options) :

1. Using vpn you connect to the remote server/machine and perform the following:

run the process, ftp the logs generated by the application to your windows machine , analyze the logs, would give a fix if possibe just by looking at the logs, deploy the application again in the unix server, go back to step 1 i.e run the process and cycle continues till it gets resolved

2. You create a similar setup of that remote machine next to your desktop… do you really think in practical case you afford doing this?? (I understand in few cases people might do but I would never recommend you doing this)

Beleive me, both the above options are frustrating and time taking to do.Just think, while developing in you IDE, do u really care analysing the logs for every small error you get in a program?? guess NO, The most likey straight forward answer is- YOU DEBUG with the help of your favourite IDE.

Follow the two simple steps to debug using Eclipse IDE

STEP 1: Just restart the remote server (or re-run the simple remote java program ) with the following Java options…