Saturday 5 October 2013

Mutuable Immutable Objects/Classes

Immutable objects are those whose contents/field values can't be change after their creation/instantiation, their values remain same up till  they resides in memory. They don't have any setter method, but do have getter methods to access them.
Mutable objects in contrast are those whose fields can be change, they have both setter and getter methods.


Eg of immutable classes in Java : all wrapper classes String, Integer, Byte, Short, Long, Character, Decimal, Float, BigDecimal, BigInteger.

Immutable objects at good parts:
  • Since they don't change their values/state, programmers often use them in multi-threading programs, we can share them with any number of programs without fear of any inconsistency problem. In other words whenever  sharing comes immutable objects play vital role as they are always consistent.They eliminate the code to make mutable objects safe, useful in concurrent programming.
  • They cannot be corrupted by thread interruptions, automatically thread safe.
  • No need of making defensive copies when returning or passing objects to other functions. 
  • String Pooling concept is safe because String objects are immutable.

At bad parts:
  • They can't be modified, thus deferentially a big hurdle when we need to change values of our instances(eg in gaming programs).
  • Always a new object is created, memory and thus performance/efficiency issues can occur.
  • Our perception of the real world is inevitably based on mutable objects. When you fill up your car with fuel at the gas station, you perceive it as the same object all along (i.e. its identity is maintained while its state is changing) - not as if the old car with an empty tank got replaced with consecutive new car instances having their tank gradually more and more full. So whenever we are modeling some real-world domain in a program, it is usually more straightforward and easier to implement the domain model using mutable objects to represent real-world entities.  

How to create Immutable classes(in Java):
Very first the variables/fields in class must be private.
Make class final so that methods inside class can't be overridden.
Set the value of the properties using constructor only and don't use any setter method, otherwise it be no more immutable.
Protect mutable fields in your class(if any):
  •    Don't share references to the mutable objects. Never store references to external, mutable objects passed to the constructor; if necessary, create copies, and store references to the copies. Similarly, create copies of your internal mutable objects when necessary to avoid returning the originals in your methods.
  • Don't provide methods that modify the mutable objects inside class, i.e,  don't forget overload/override the methods of mutable class (whose reference you are using), which can alter values of existing object.

Refrences:
http://programmers.stackexchange.com/questions/151733/if-immutable-objects-are-good-why-do-people-keep-creating-mutable-objectshttp://www.javaranch.com/journal/2003/04/immutable.htm
--
Thanks

Sunday 8 September 2013

Introduction to Data Science(Ws)



What

Data Science refers to an emerging area of work concerned with the collection, preparation, analysis, visualization, management and preservation of large collection of information.
                                                              -- Jeffrey Stanton
                                               Syracuse University School of Information Studies

From wikipedia Data science incorporates varying elements and builds on techniques and theories from many fields, including math, statistics, data engineering, pattern recognition and learning, advanced computing, visualization, uncertainty modelling, data warehousing, and high performance computing with the goal of extracting meaning from data, finding relationships in data and creating data products.


Why

In the 19th century or so there was a major change in the nature of solving problems, apart from becoming more abstract, the primary focus shifted from calculations or following procedures to analysing relationships. The change in emphasis wasn't arbitary, it came about through the complexity of the world. Data Science emphasis on finding unknown relationships among data.

Meanwhile approximately at the same time Internet also come in pace and as the Computer Science era changed from desktop application to web applications, and with more technology enhancement, now *huge*  amount of data is available every where, what needed is only to work on this data! All truths are easy to understand once they are discovered; the point is to discover them.

Lots and lots and lots of data, lots and lots and lots of people, lots and lots and lots of places, constant change, ever increasing data. Data Science is the new reality. Data as programmable resource, versioning, filtering, aggregating, extending, automating, analysing and communicating data becomes a need, not only for business perspective also for human welfare[2].
Data is ever growing, never at rest!



Where

Wherever is data, Data Science is followed. No matter data is small or in large scale, data science is used; For a new start-up with small data to big organizations with huge data, whenever one need to understand, process, extract value from it Data Science is applied.

What reviewed

Following are the three areas of data geeks:



                                                                                       -- Drew Conway

Hacking Skills refers to the programming knowledge and skills.
Math and Statistics refer to the traditional  research, the way one handles data. Math is also described as the science of patterns, thus here applied for pattern of data.
Substantive Expertise refers the basic knowledge about the data itself.


Data Scientist

Three types of Known and Unknowns:
  1. There are  Known Knowns, these are things we know that we know.
  2. There are  Known Unknowns,  things we know that we don't know.
  3. There are  Unknown Unknowns, there are things we don't know we don't know.

Data Scientists is the one who discovers the unknowns and make them known.  He need to find nuggets of truth in data and then explain it to the business leaders.






How it works

Though its never ending knowledge to understand how Data Science is applied on data, because every different set of data may require different technique/algorithm to analyse and interpret it. But still there are under mentioned tasks as a usual procedure followed for data analysis and communication.

Types of tasks in Data Science :
  1. Preparing to run a model: refers to gathering, cleaning, integrating, restructuring, transforming, loading, filtering, deleting, combining, merging, verifying etc.
  2. Running the model.
  3. Communicating the result: means visualization and interpreting final result.







--References:
  1. https://www.coursera.org/course/datasci
  2. http://blog.revolutionanalytics.com/2013/03/what-does-a-data-scientist-do.html