Skip to main content

Posts

Showing posts from 2013

New Features and Enhancements from JDK-5 to JDK-7

As Oracle is preparing for JDK-8 release with most awaited language features " lambda expressions", I was thinking about the java language evolution since I started my IT career.

New features released in JDK-5 were really impressive, and it created lots of interest in language again.

JDK-5 (September 30, 2004)
GenericsEnhanced for LoopAutoboxing/UnboxingTypesafe EnumsVarargsStatic ImportMetadata (Annotations) Collections Framework
JDK-6 (December 11, 2006)
Collections FrameworkScriptingI/O SupportMonitoring and Management for the Java Platform
JDK-7 (July 28, 2011)
Binary LiteralsStrings in switch StatementsThe try-with-resources StatementCatching Multiple Exception Types and Rethrowing Exceptions with Improved Type CheckingUnderscores in Numeric LiteralsType Inference for Generic Instance CreationIO and New IOConcurrency Utilities
Over the past few years, java has become more relevant. It has quietly become the primary foundation for really big companies like Google, LinkedIn,…

JavaScript [ExtJs3]: Avoid default filtering in ComboBox

We had a requirement where we wanted to avoid default filtering provided by the ExtJs ComboBox. Instead we wanted to control it based on our business rules. To avoid default filtering we added “editable:false”, but it didn’t help much. As after selecting any value user cannot clear the value from field. We tried few more permutation-combination to achieve all the behaviour we wanted, but nothing worked. Use-Cases we wanted to achieve in combo boxForce user to select value from drop down list User can clear the value Disable the default filtering as filtering is applied based on some business rule and default filtering was clearing itHere is the final outcome, which satisfied all the use-cases. var combo = new Ext.form.ComboBox({ store : store, displayField : displayField, mode : 'local', triggerAction: 'all', forceSelection: true, autoSelect: false, // don't allow u…

Think “SOLID”

S  → Single responsibility principle : One class one responsibilityO → Open/closed principle : Open for extension, but closed for modificationL  → Liskov substitution principle : Design by contract [Link: Liskov substitution principle]I   → Interface segregation principle : Many client-specific interfaces are better than one general-purpose interfaceD → Dependency inversion principle : Abstraction on object and their dependency creation


Debugging common errors in ExtJs

If you check ExtJs form, you will find some issues commonly faced by developers. I have seen people spending hours to solve these issues without any clue.
Here is the list of few errors and expected root cause. Hope it will help someone.  this.addEvents is not a functionCheck instantiation of the class. Most probably you forgot to write “new” keywordwhile creating a class object. namespace.MyClass is not a constructorCheck for typo in class definition or class instantiation.Did you forget to include the js file in html page or in jsb configuration?this.el is undefined / this.el is nullIn ExtJs “el” variable hold the reference of DOM element. And DOM element only initialize, when UI render correctly on web browser. If you are getting this error,  then their is major chances of accessing “el” variable before UI component layout or render properly. Component is appearing as gray out or it is hanging somewhere elseIt can happen because of many other issue, but major reason is same id of …

“Bloom Filter” to optimize expensive data lookups

Bloom Filter is very useful when you want to optimize the functionality with following constraints
Data lookup is very expensive False positive is acceptable and False negative is un-acceptable
A Bloom filter, conceived by Burton Howard Bloom in 1970, is a space-efficient probabilistic data structure that is used to test whether an element is a member of a set. False positive retrieval results are possible, but false negatives are not; i.e. a query returns either "inside set (may be wrong)" or "definitely not in set".wikipedia.org


It stores only value hash in it’s data structure, so it take very less memory against the very huge data.
For example if you have set of raw data with
107 elements 105 distinct value and size ~40MB Bloom filter will store same data as hash in just ~0.6MB. (ref.)
And because of the same reason it is quite fast.

Bloom Filter implementation
Guava library has bloom filter implementation
.Net implementation

Bloom Filter In Use
Chrome uses Bl…

"Stop Words" in full text search

Stop words are the words without significant information. You can consider these words as a filler words. If these words are used in search statement, then result could potentially contain all the record from data store. 



It is always a good idea to filter out these words before constructing the search query. It will make the search query smaller, faster and result will be more relevant.







One of our major performance optimizations for the “related questions” query is removing the top 10,000 most common English dictionary words (as determined by Google search) before submitting the query to the SQL Server 2008 full text engine. It’s shocking how little is left of most posts once you remove the top 10k English dictionary words. This helps limit and narrow the returned results, which makes the query dramatically faster.” - stackoverflow.com


English stop word list :
http://jmlr.csail.mit.edu/papers/volume5/lewis04a/a11-smart-stop-list/english.stop


Some interesting articles
http://www.codi…

[JavaScript] Updating the existing function behaviour

Ever find a situation when you want to change the function behaviour without duplicating the existing function code. Then you must be looking for this example.

Our test data object
var user = { name: 'testWorker', isOnLeave: true };
Original function behaviour
var startWork = function(user){ console.log('working...'); } [run] ->startWork(user); [output]->working...
Now if we want to change the function behaviour based on our data object.
startWork = (function(){ //backup original function in private scope var _originalFn = startWork; //assign new behaviour return function(user){ if(user.isOnLeave){ console.log('on leave...'); } else { _originalFn(user); } } })(); [run] ->startWork(user); [output]->on leave... //change data object user.isOnLeave = false; [run] ->startWork(user); [output]->working...
Note: It is not suggested to update the existing func…

JavaScript [Q.JS] Are you stuck in nested callback functions?

If you have seen situation when one asynchronous call result used in another asynchronous call. And you tried to make that code look less scary and more readable then you must go through this library and understand it’s nice tricks and syntax. Just want to give the same example from its site which clearly shows the problem it is trying to solve. step1(function (value1) { step2(value1, function(value2) { step3(value2, function(value3) { step4(value3, function(value4) { // Do something with value4 }); }); }); }); With QJS libraryQ.fcall(step1) .then(step2) .then(step3) .then(step4) .then(function (value4) { // Do something with value4 }, function (error) { // Handle any error from step1 through step4 }) .done(); If you want to see its potential uses then you should see one of the WCF data API  breezejs.To test this library i have created a dummy Ajax function which simulate the Ajax asynchronous behaviour. var Ajax = …