Thursday, June 16, 2016

Magic with Computers

The expectation from a computer is always to do something which surprise us, which complement human brain in terms of memory, processing, decision making, thinking and imagining. When I say computer, it includes smart phone, tablets or wearable devices. When we compare it with washing machine, refrigerator or lift, we always expect more out of a computer.
First time when ATM machines were introduced,  people were amazed how banking can be experienced seamlessly. You can deposit money in one location and withdraw from a different location instantly. When we first time sent an email, or did video chat all were magical experience.

But Now a days all these look normal and nothing great about it. So for a programmer whats next ?
what are the things or feature will get that "wow" from the user, keeping in mind now a days almost every one has been introduced to Facebook and google.

I feel below points will help to do the magic.

Simple UI

Its very easy to say simple ui, all of us know and its a quite old rule. But still it holds good and the people consciously or sub consciously decide whether to use or not based on user experience.

There is no rule or some way you can measure whether the one design is better than other. But certainly there are lots of good practices. I believe deeper understanding of the problem and solution based on user perspective, knowing different attribute of your target audience like region, language, age group, popular culture of target audience will certainly help enhance for better user experience.

User experience is so important that, if you skip reading the below points from now, still you can get a wow from the user.

Input / Command

We appreciate some one obey the commands and do our work, But we love and addict to those who do the required task with out the command.
The less input,intervention is required for system to work enhance user experience . While designing system we can follow some philosophy like  don't ask for explicit input, rather than observe it from the environment or historical data.

Prediction

Dare to predict and suggest and improve your prediction based on time. Always try to add some more value to the user.

Its a continuous process, reiterate the above point  time to time.

Let me know your thoughts how to get a wow ....




Monday, June 29, 2015

Java Immutable Object

The simple definition of immutable object is "An object called immutable whose states can't be changed after it constructed". It means every time we need to alter the state we actually end up having a new object. The best example is "java.lang.String".

Some body might be thinking its actually overhead, this practice ends up creating too many objects. Actually over the time with optimization of garbage collection and the cost of creating new objects decreases. So in a situation where you want to define constant, or say a multi threading case immutable objects work well. As the value doesn't change at any stage, we are assured of dirty or inconsistent value.

Lets understand how to create our own immutable object.

1) Make the class final, to stop any other class to extend.
2) All fields in the class should be private and final.
3) Since we don't want the state of the object to change,  there should not be any setter method.
4) Any method which require to change the state, must create a new object with updated state.

For Ex:

final public class MyCar
{
     private final String registrationNumber;
     public MyCar(String registrationNumber)
     {
        this.registrationNumber = registrationNumber;
     }
     public String getRegistrationNumber()
    {
        return registrationNumber;
    }
    public MyCar upgradeCar(String newCarRegNo)
    {
       return new MyCar(newCarRegNo);
    }
}

Sunday, October 26, 2014

String, StringBuffer and StringBuilder

With respect to C or C++ in java String handling is different. Java provides String class to represent Strings. For better memory utilization java treats String as constant and their value can't be changed.
This behavior is popularly known as immutable.The idea is if some one write
String hello = "Hello"; 
String greetings = "Hello";
Internally both refer to same object. In JVM memory area there is a dedicated memory for these String literals, known as String pool.
So in our example hello == greetings will return true.
But if someone write
String str = new String("Hello");
It will create a new object, it won't point to same literal available in string pool.
So hello == str will return false. 
Another advantage of java String is we can use + for concatenation.

String greetMe = hello + "Java";

We can concatenate diffrent type of object other than String with String too. The typecast is automatic.String conversions are implemented through the method toString, defined by Object and inherited by all classes in Java.
As we learned String objects are immutable means the values cannot be altered. So strings are always thread safe. Any operation such as hello.toLowerCase() will result another object. For extensive String manipulation java provides two other classes StringBuffer and StringBuilder. These classes gives us a way to manipulate String efficiently. The only difference is StringBuffer is thread safe while StringBuilder is not. So by design StringBuilder is faster than StringBuffer.

So when to use what

String is used to handle multiple literal, it gives you optimum way to handle duplicate literal for better memory utilization.

StringBuffer is natural choice if we need to do a lots of String manipulation in a thread safe way. If synchronization is not the issue StringBuilder should be used since its faster than StringBuffer.

Have fun with your Strings  ;)