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.

Sunday, July 06, 2014

Hooking Into Container and Bean Life Cycle in Spring.

"What is the difference between BeanFactoryPostProcessor and BeanPostProcesser" This, said one of my colleagues, was part of his interview question, a question to which he promptly replied: "I don't know".

Once you pass the stage of actually getting Spring to work, passing the configuration huddle, in no time, the next couple of things you would probably run into would involve using or hooking into the various life-cycles in Spring and you start seeing things like BeanFactoryPostProcessor, BeanPostProcessor, DisposableBean, InitialzingBean, PostConstruct etc, which all seems to be callbacks mechanism that enables you plug in, somehow, into all the magic going on in Spring.

...And probably just like me, it all starts feeling like too much to grasp...Also, sooner or later, you run into the *Aware sets of interfaces.

Dang! What are all these, How do they fit into the picture? I just want to write a web application, why do I have to grapple with all these what not?

I initially had all these concepts swirling all about without having any concrete mental model to attach them to or a good understanding of what actually is going on. I knew about the @PostConstruct annotation and maybe what it does, I also have come across various *Post Processors and maybe the IntializingBean interface a couple of times, but actually grokking and understanding where they fit did not happen until after spending some time working with other parts of Spring which allowed for a broader view of what is going, helping create some sort of mental model.