Monday, September 29, 2014

Overview of Exceptions In Java and Some SonarQube Recommendations

...So I had a chat with SonarQube earlier today. She was a little unhappy with the way things were in a project I was working on, and since I can't push this conversation away forever, I decided to bite the bullet and just hear her out. I figure that, apart from hearing what she has to say and making her happy, I could learn one or two things from her recommendations...

And sure I did. Especially when it came to Exception Handling. Got reminded about stuff I already know. Also picked up some one or two good things to always keep in mind when thinking/working with Exceptions in Java.

Since I have been able to get her Rules Compliance to 99.3%, I guess I could penned down some of the wisdom I gleaned from her: some new, some already known.

Saturday, September 20, 2014

Two Life Hacks: Dump Your Smart Phone. Eradicate Facebook's News Feed

I latch on to things; mentally: sometimes, I suspect it bothers on being obsessive. If a concept catches my fancy, I could latch on to it till I wear myself out. If I am confronted by a problem which I can't immediately solve, I find it really hard to get it out of my mind until I have it figured out.

This tendency is not necessarily a bad thing; at least it guarantees the tenacity and tunnel vision often required to crack through problems and grok non trivial concepts...

But...

it also has it's downsides: I realized that, yes, I could develop tunnel vision easily and focus on stuff, paradoxical as it may sounds, it also leads to a state where I find it hard to concentrate. It seems I get so consumed over a thing, the patience required for the state of mind needed to concentrate flies off the window.  And as everybody soon get to discover, tunnel vision isn't always the answer: sometimes you need to let go, take a step back and look at things from a different point of view; a thing that may not come easily when locked in a latching mode I am quick to slip into.

And then when you find yourself latching on to activities that benefits little, then the mental and emotional exhaustion comes real quick and swift.

Saturday, September 06, 2014

Remote Debugging Of Tomcat Via Intellij

A couple of moons back, I put fingers to keyboard and punched out a post on how to debug, from asunder, a running tomcat application, from within Intellij IDEA.

The post shall remained chronicled, for as long as it is possible, over on the company's blog.

For your perusal and to gain of the wisdom shared, hesitate not, and proceed to HOW TO REMOTELY DEBUG APPLICATION RUNNING ON TOMCAT FROM WITHIN INTELLIJ IDEA

Saturday, August 23, 2014

How to Inject Objects Into Spring MVC Controller Using HandlerMethodArgumentResolver


This post shows how to implement HandlerMethodArgumentResolver in other to resolve and inject objects into Spring MVC controllers, but before we get to the actual implementation procedure, a little trivial overview of Spring MVC would be good.

Spring MVC is designed around the Front Controller Pattern which it uses to implement the Model View Controller pattern.

Since you are reading this post, I can rightly assume you already use Spring MVC and you know how it generally works: You register the DispatcherServlet -Spring MVC's Front Controller, write your controller class and map requests to controller methods using @RequestMapping, then put the necessary configuration in place which would enable Spring to pick the written controller class and have it as a spring managed bean.

A trivial controller class may look like this:

package com.springapp.mvc;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
public class HelloController {


    @RequestMapping("/index")
    public String doGreeting(Model model) {
        model.addAttribute("greet", "Hello World");
        return "helloView";
    }
}

So when a request hits /index, doGreeting(...) method is invoked with an object of Model (the M in MVC) passed into it, which is populated with the greet property which can then be accessed in whatever view technology in used. The view is located using the "helloView" string returned by the controller.

Tuesday, August 05, 2014

Configuring Maven to Fetch Artifacts from Multiple Repositories

It is quite common to have a situation where a project needs to source for artifacts from more than one source. This post quickly explain 3 different ways to achieve this.

Repositories settings in pom.xml


In pom.xml, you have the <repositories/> tag which can be used to specify the repositories a project should search and download artifacts from. For example:

Sunday, July 20, 2014

Common Date-Time Operations In Java - Formatting and Parsing Date-Time

In Date and Time With Java, a general overview of date/time related API was given. This post walks through formatting and Parsing Date-Time in Java.


Parsing and Formatting Date and Time.


What is the difference between December, 04, 1984 and 12/04/1984, and 04/Dec/1984 and ... or difference between 13:00hr and 1PM and...

Formating. They all represent the same date and time but are formatted differently.

Formatting date/time values as string, and parsing date/time values expressed in string into objects, are one of the common tasks when dealing with date/time. 

Formatting allows you to take a Java object that represents date or time and convert it into a string represention using a predefined formatting.

Conversely, with parsing, you take date or time values expressed as strings and have it converted it into valid Java date or time objects.

We quickly go over how to accomplish these tasks:

Saturday, July 19, 2014

Date And Time With Java

How do you deal with dates and time in Java and perform common operations like finding difference between two dates or translate dates into a particular string formats?

This post seeks to provide an answer to those questions.

I would start off by giving a brief description of the available date related classes and packages you might encounter on the Java platform and then do follow up posts exploring some of the common date/time operations like how to format date-time, dealing with time zones and locale, finding differences between dates/times etc.