4 JavaScript trivia questions that may help you understand the language a bit better

The next 4 Javascript questions may seem easy to some of you, but I am sure that more than a few will get confused. I believe that these 4 simple questions will help you understand a key feature of the language. Question: What will happen after executing the next JS code? 1. Nothing 2. alert ‘>undefined’ 3. alert ‘>1’ 4. alert ‘>2’ Answer: Nothing, because outer() returned a function but it wasn’t executed. Question: What will happen after executing the next JS code? 1. Nothing 2. alert ‘>undefined’ 3. alert ‘>1’ 4. alert ‘>2’ Answer: alert ‘>2’, because the x that inner() uses is the same x the outer() uses. Question: What will happen after executing the next JS code? 1. Nothing 2. alert ‘>undefined’ 3. alert ‘>1’ 4. alert ‘>2’ Answer: alert ‘>undefined’. Inner uses a variable x which is different than the outer x. The inner x is never initialized Question: What will happen after executing the next JS code? By now the answer should be obvious: alert ‘>3’ .

Use Clover to generate code coverage reports of your integration/automation tests

Clover is a great tool for generating code coverage reports from your unit tests. It can be executed as a plugin in Eclipse, Maven or Ant. However, not everyone knows that it can also be used to collect coverage data of integration tests. This post explains how to collect coverage data with clover at runtime. This post assumes that you already know what are unit and integration tests. This post assumes that you know what Clover is, and already used it either with Eclipse, Ant or Maven. *Let me assured you that even though the directions bellow seems complicated and clumsy at first, after doing them once or twice it is really easy to repeat them. Motivation The default action of Clover is to gather code coverage information during build time or compile time. Therefore, This information includes just the coverage data created by unit tests. If you are developing web applications, you probably use more technologies to test your applications beside unit tests. These technologies may include HTTPUnit/HTMLUnit or automation technologies (like Selenium). These technologies do not work at build time, they can only work during run time, where a web server is up and running and HTTP calls Continue reading Use Clover to generate code coverage reports of your integration/automation tests

Android development – Custom Animation

Android developers web site provide you with 2 predefined animation techniques which you can use in your applications – Tween animation and frame animation. They are super easy to implement and work quite nice. If you are using Android 3.0 or above, you should check out Property Animation technicqe. But what if you need to create your own customized animations and you are using older versions? Don’t worry, that is easy to do as well, here is how you do it. To create a customized animation you need to follow these 3 steps. For the explanation, we will create a simple animation that changes the background of a button gradually from black to red. Step 1 – Extend the Animation class and set the properties Create a class which extends Android Animation class. This class will hold the logic of your animation. See my example: As you see, there is not much in this class since my animation is not that complicated. Notice that I have made all the necessary animation parameters initialization from inside the constructor, but you can defiantly initialize them from outside the class. There are 2 important parameters which determines the behavior of the animation: RepeatCount Continue reading Android development – Custom Animation

Android quick tip: use System.arraycopy()

Well it’s a well known fact that the java native function System.arraycopy() is a useful way to copy one array to another since it is native, but is that also the case for Android? And if so, how much more useful is it? To answer these questions I have made a simple test and ran it as a java program on my PC and than as an Android activity. Here is the test for the PC: Here are the results while running it from my PC (java 7, 8GB memory, CPU intel i5): Naive algorithm – 14 ms System.arraycopy(); – 6 ms. Arraycopy does the task in less than half of the time. Now to use it on Android – here is the code: * Notice I have reduced the size of the Array from 10 million to 1 million, this is due to restrictions on memory for applications in Android. The results from running it on my device (nexus 1): Naive algorithm – 182 ms System.arraycopy(); – 12 ms. This means that the fact that System.arraycopy() is better than the regular copy is even more true for Android. In short than, always use System.arraycopy() especially on Android. Test for Continue reading Android quick tip: use System.arraycopy()