JUnit 4 Tutorial – Basic Usage

This tutorial introduces the basic annotation supported in Junit 4.


import org.junit.*;
import static org.junit.Assert.*;
import java.util.*;

 * @author mkyong
public class JunitTest1 {

    private Collection collection;

    public static void oneTimeSetUp() {
        // one-time initialization code
    	System.out.println("@BeforeClass - oneTimeSetUp");

    public static void oneTimeTearDown() {
        // one-time cleanup code
    	System.out.println("@AfterClass - oneTimeTearDown");

    public void setUp() {
        collection = new ArrayList();
        System.out.println("@Before - setUp");

    public void tearDown() {
        System.out.println("@After - tearDown");

    public void testEmptyCollection() {
        System.out.println("@Test - testEmptyCollection");

    public void testOneItemCollection() {
        assertEquals(1, collection.size());
        System.out.println("@Test - testOneItemCollection");


@BeforeClass - oneTimeSetUp
@Before - setUp
@Test - testEmptyCollection
@After - tearDown
@Before - setUp
@Test - testOneItemCollection
@After - tearDown
@AfterClass - oneTimeTearDown

In JUnit 4, you have to declare “@BeforeClass” and “@AfterClass” method as static method.


Scala vs Java – Differences and Similarities

Scala is new generation JVM language, which is generating popularity as alternative of arguable one of the most popular language Java. It’s not yet as popular as Java, but slowly getting momentum. As more and more Java developers are learning Scala and inspired by Twitter, more and more companies are using Scala, it’s future looks very bright. To start with, Scala has several good feature, which differentiate it from Java, but same time it has lot of similarities as well e.g. both Scala and Java are JVM based language, You can code Scala in Java way and Scala can use any Java library, which in my opinion a great decision made by designers of Scala. Since tremendous works has already been done in form of open source framework and library in Java, it’s best to reuse them, rather than creating a separate set for Scala. Out of several differences, one of the main difference between Scala and Java is it’s ability to take advantage of Functional programming paradigm and multi-core architecture of current  CPU. Since current CPU development trend is towards adding more cores, rather than increasing CPU cycles, it also favors functional programming paradigm. Though this differences may not be significant, once Java 8 will introduce lambdas, but it might be too early to comment. Apart from functional programming aspect, there are many other differences as well. One of the obvious one is improved readability and succinct code. Java is always on firing line for being too verbose, I thing Scala does take care of that and code which took 5 to 6 lines in Java, can be written in just 2 to 3 lines in Scala. Well Grounded Java Developer has some nice introduction on JVM languages like Scala, Groovy and Closure, which is worth reading.  In this article, we will see such kind of similarities and differences between Scala and Java.

Similarities between Scala and Java

Following are some of the major similarities between Scala and Java programming language :

1) Both are JVM based language, Scala produce same byte code as Java and runs on Java Virtual Machine. Similar to Java compiler javac, Scala has a compiler scalac, which compiles Scala code into byte code. At this level, all JVM language like Groovy, JRuby, Scala becomes equals to Java, because they use same memory space, type system and run inside same JVM.

2) You can call Scala from Java and Java from Scala, it offers seems less integration. Moreover, you can reuse existing application code and open source Java libraries in Scala.

3) Major Java programming IDE like Eclipse, Netbeans and InetelliJ supports Scala.

4) One more similarity between Scala and Java is that both are Object Oriented, Scala goes one steps further and also supports functional programming paradigm, which is one of it’s core strength.

Differences between Scala and Java

1) First and Major difference you will notice between Scala and Java is succinct and concise code. Scala drastically reduce number of lines from a Java application by making clever use of type inference, treating everything as object, function passing and several other features.

2) Scala is designed to express common programming patterns in elegant, concise and type-safe way. Language itself encourage you to write code in immutable style, which makes applying concurrency and parallelism easily.

3) One difference, which some might not notice is learning curve. Scala has steep learning curve as compared to Java, my opinion may be slightly biased because I am from Java background, but with so much happening with little code, Scala can be really tricky to predict. Syntax of Scala looks confusing and repulsive as compared to Java, but I am sure that is just the starting hurdle. One way to overcome this hurdle is following a good Scala book like  Programming in Scala or Scala in Action, both are excellent books for a Java developer, who wants to learn Scala

4) One of Scala’s cool feature is built-in lazy evaluation, which allows to defer time consuming computation, until absolutely needed and you can do this by using a keyword called “lazy” as shown in below code :

// loading of image is really slow, so only do it if need to show image
lazy val images = getImages()  //lazy keyword is used for lazy computation

    // Do something without loading images.

If you love to learn by following examples, then I guess Scala CookBook is a another good buy, contains tons of examples on different features of Scala.

5) Some one can argue that Java is more readable than Scala, because of really nested code in Scala. Since you can define functions inside function, inside another functions, inside of an object inside of a class. Code can be very nested. Though some time it may improve clarity, but if written poorly it can be really tricky to understand.

6) One more difference between Scala and Java is that Scala supports Operator overloading. You can overload nay operator in Java and you can also create new operators for any type, but as you already know, Java doesn’t support Operator Overloading.

7) Another major difference between Java and Scala is that functions are objects in Java. Scala treats any method or function as they are variables. When means, you can pass them around like Object. You might have seen code, where one Scala function is accepting another function. In fact this gives the language enormous power.

8) Let’s compared some code written in Scala and Java to see How much different it look:


List<Integer> iList = Arrays.asList(2, 7, 9, 8, 10);
List<Integer> iDoubled = new ArrayList<Integer>();
for(Integer number: iList){
    if(number % 2 == 0){
        iDoubled.add(number  2);


val iList = List(2, 7, 9, 8, 10);
val iDoubled = iList.filter(_ % 2 == 0).map(_  2)

You can see that Scala version is lot succinct and concise than Java version. You will see more of such samples, once you start learning functional programming concepts and patterns. I am eagerly waiting for Scala Design Patterns: Patterns for Practical Reuse and Design by John Hunt, which is not yet released and only available for pre order. This book is going to release this month.

That’s all on this article about similarities and differences between Scala and Java.  Though they are two separate programming language, they have lot in common, which is not a bad thing at all and in my opinion that’s the only thing, which will place Scala as Java alternative, if at all it happens in future. As I had mentioned in my post 10 reason to learn Java programming, that Java tools, libraries, and community is it’s biggest strength and if Scala can somehow reuse that, it will be well ahead, forget about competing though, it will take years to build such community and code. For a Java programmer, I would say nothing harm in learning Scala, most likely you will learn few good practices, which you can even apply in Java, as corporate sector is still on Java, and Scala in it’s early days, you can be well ahead, if you learn Scala now. On closing note, at high  level Scala looks very promising, all design decision made are really good and they came after several years of experience with Java.

Recommended Books on Scala for Java Programmers
Books are best way to learn a new programming language, first of all they contains complete information but also in much more readable and authentic form. I strongly recommend to follow at-least one book, before jumping on blogs and online articles. One reading any Scala Programming book is must to build fundamental, which is indeed necessary, given rather steep learning curve of Scala. Following are my list of some books from which you can choose one.

Programming in Scala: A Comprehensive Step-by-Step Guide, 2nd Edition by Martin Odersky, Lex Spoon and Bill Venners
Scala for the Impatient by Cay S. Horstmann
Scala in Depth by Joshua D. Suereth and Martin Odersky

Thanks folks, Enjoy learning Scala.


Quickstart to testing your website with Behat, Mink, and Selenium
YouTube Preview Image
best way to add payment to your website

s1s2s4 s3https://stripe.com/us/pricing

<form action="/charge" method="POST">
    data-name="Demo Site"
    data-description="2 widgets ($20.00)"

ُExample no need to pay

Vagrant Beginner
YouTube Preview Image

This is the best way you could build your server with.


Benchmarks: Node.js vs Go vs PHP

With talk lately about Go, the Google sponsored programming language), and what performance benefits it holds, I thought I’d go and do a quick benchmark of Go, Node.js, and PHP.

Update: Node.js vs. Go 1.1

Disclaimer: Make the smartest decision possible when choosing a language. Benchmarks give you a rough idea of language speed, but do not provide insights into real world usability, productivity, or what is best for you or your company. In short, take these numbers wisely.

The test

Here’s the first test. A rusty old Bubble sort. I use this because it gives a good idea of how long computations and comparison operations take for the specific language to perform. Here’s the code I used:


$starttime = microtime(true);

$array = array(3,4,1,3,5,1,92,2,4124,424,52,12);

for ($c=0;$c<100000;$c++) {

for ($i=0;$i<count($array);$i++) {
    for ($y=0;$y<count($array)-1;$y++) {
        if ($array[$y+1] < $array[$y]) {
            $t = $array[$y];
            $array[$y] = $array[$y+1];
            $array[$y+1] = $t;

echo microtime(true) - $starttime;


var starttime = new Date().getTime();

var array = [3,4,1,3,5,1,92,2,4124,424,52,12];

for (var c = 0; c < 100000; c++) {
    for (var i = 0; i < array.length; i++) {
        for (var y = 0; y < array.length - 1; y++) {
            if (array[y+1] < array[y]) {
                var t = array[y];
                array[y] = array[y + 1];
                array[y + 1] = t;
console.log(new Date().getTime() - starttime);


package main

import "fmt"
import "time"

func main() {

timestart := time.Now();

array := [...]int16{3,4,1,3,5,1,92,2,4124,424,52,12}

for c := 0; c < 100000; c++ {

for i := 0; i < len(array); i++ {
    for y := 0; y < len(array) - 1; y++ {
        if array[y+1] < array[y] {
            t := array[y]
            array[y] = array[y+1]
            array[y+1] = t



timeend := time.Now();



Without further ado, here are the results:

Holy slow is slow, PHP. That’s a full three seconds, verses the less than 100ms boasted by Node.js and Go. Let’s remove the outlier:

PHP completed the operations in 3.835 seconds. Node.js completed them in 71 milliseconds, whereas Go completed them in 38ms. Not bad, those latter two.


As a language, Go does seem faster than Node.js by a significant margin. This being said, the two are both eons ahead of PHP in speed, which we all already knew. The performance gains from both of them, compared to PHP, shows they are both relatively fast when compared to a very popular language for web development.

Test 2: HTTP

Now, since we’re talking in the context of the web, I thought I’d compare Node.js and Go’s HTTP capabilities.


package main

import (

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "You requested %s", r.URL.Path)

func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)


var http = require("http");

http.createServer(function(request,response) {

    response.write("You requested " + request.url);


Without further ado, the ApacheBench results:

Again, lower is better. In this case, Node barely outperformed Go in handling static HTTP requests, but not by much of a margin (~1ms).

Now, if we throw the bubble sort code into the request handler function, we get obviously this:

Here, the computation efficiency of Go wins over Node.js. But computing 100,000 bubble sort operations is probably not on the scale of data processing is required per request to your users, so we’ll drop the loop and do one bubble sort per request:

Now that’s interesting. Here, it appears that the HTTP transport of Node.js is more efficient than Go’s, despite the lower computation speed. If we increase the concurrency, the gap between the two grows:


My only strong conclusion from this is, if your goal is to optimize past the speeds of PHP or other similar languages, Go and Node.js are good alternatives. Which should you use? This information can’t tell you that. It would appear, and make sense, that Go handles data processing more efficiently than Node. But at the same time, it does appear that Node may scale more efficiently, at least in the almost pure HTTP side of things. In a real world scenario, the type of operations your application does will be critical in determining this. One thing I didn’t benchmark, and I wish I had time to, is database driver speeds, but that’s another topic for another time. In the end, though, I’d say language choice is truly up to preference and suitability for your project. Go may be somewhat faster in a few cases, and Node in others, but both Node.js and Go are eons faster than PHP. It truly depends on your team’s experience and what type of operations are at hand.

Any questions, suggestions, or better points are welcomed (and encouraged)

Update: Node.js vs. Go 1.1


من يدير جوجل؟

من يدير جوجل؟

مقال رائع جدا للاخ محمد حجاج

Genetics, Nanotechnology and Robotics


روشتة لنمط حياة صحي لكبار السن في مصر لتجنب العديد من الأمراض

قدم الدكتور سامح علي ، رئيس مركز دراسات أمراض الشيخوخة بمعهد حلمي للدراسات الطبية ب #مدينة_زويل لموقع ” #الوطن #علوم و #صحة ” روشتة لنمط حياة صحي لكبار السن في مصر لتجنب العديد من الأمراض.

قال الدكتور سامح أن أمراض الشيخوخة تكبد دول العالم الكثير من الأموال لرعاية الأفراد صحياً في حال إصابتهم بالأمراض بخاصة بعد التقاعد يقدر في معظمها بمليارات الجنيهات. في ظل إرتفاع معدل عمر المصريين منذ الأربعينات من 50 إلي 70 عام.

“تأخر متوسط العمر الصحي لكبار السن في مصر بعشرة سنوات مقارنة بباقي دول العالم” ، أضاف سامح في إشارة لمعاناة المسنين في مصر من تدهور الحالة الصحية والإصابة بأمراض متوطنة مثل السكر و القلب ؛ ما يزيد من معاناة موازنة الدولة في تقديم الرعاية الصحية.

يرتبط التدهور الصحي لكبار السن ،كما أضاف سامح بوجود أخطاء في نمط الحياه و الإبتعاد عن النمط الصحي في الغذاء أو حركة الجسم أو الحالة النفسية ؛ مايجعلنا نقدم روشتة نحو شيخوخة أكثر صحية.

نوعية الغذاء الصحي لكبار السن

علي مستوي التغذية ، يفند مدير مركز أمراض الشيخوخة ما أسماه بأسطورة “أن الغذاء الصحي مكلف” ،موضحاً بأن الوجبة الغذائية الصحية يمكن أن تكون أقل تكلفة .و يعتمد البرنامج الغذائي الصحي علي تناول الخضروات و الفاكهة و التقليل من النشويات و التركيز علي اللحوم البيضاء علي حساب اللحوم الحمراء لزيادة المواد الدهنية في الأخيرة التي تضر بالقلب بجانب التركيز علي زيت الزيتون في طهي الأطعمة.

أشار سامح لضرورة تناول المكسرات ، التي تعد مصدراً للدهون غير المشبعة التي تحتاجها خلايا جسم الإنسان للقيام بوظائفها ؛ بخاصة الفول السوداني و عين الجمل . و الإبتعاد عن المشروبات الغازية التي تعجل بالإصابة بأمراض البدانة في حال الإفراط في تناولها ،و تجنب العصائر المحفوظة و إستبدالها بالطازجة.

شددت روشتة رئيس مركز أمراض الشيخوخة علي تناول المياه بما لا يقل عن 2 لتر يومياً ،وهي الكمية التي يحتاجها جسم الإنسان بخاصة كبار السن.

ممارسة الرياضة و التنشيط الذهني

نبه الدكتور سامح لضرورة ممارسة الرياضة سواء في الصالات الرياضية أو بممارسة رياضة المشي لمدة ساعة يومياً أو رفع بعض المواد الثقيلة التي تساعد علي تنشيط معدل التمثيل الغذائي لفترات طويلة ،بجانب التنزه بالأماكن المفتوحة و إستنشاق الهواء النقي.

فيما يتعلق بالنشاط الذهني اثبتت الدراسات ، كما ذكر الدكتور سامح أن تنشيط الذهن بحل الألغاز أو القراءة يساعد في إطالة العمر ،و الإبتعاد عن مصادر التوتر منها متابعة الأخبار السيئة للحفاظ علي الثبات النفسي لكبار السن.

إضطراب النوم والأمراض النفسية

نعت رئيس مركز أمراض الشيخوخة إضطراب النوم “بالأهم” للحفاظ علي التوازن الهرموني داخل جسم الإنسان ،بعد تغيير نظام النوم الطبيعي بالإستيقاظ حتي وقت متأخر من ساعات الليل و الخلود للنوم خلال فترات النهار ؛ ما يخل بوظائف جسم الإنسان التي تعمل وفقاً لساعة بيولوجية تتأقلم مع الضوء في حال شروق أو غروب الشمس.

و يتسبب الخلل بالساعة البيولوجية ،كما أضاف سامح في فقدان التركيز و قدرات التعلم و الإصابة بعدد من الأمراض النفسية علي رأسها الإكتئاب والإصابة بأمراض البدانة لتأخر معدل تكسير الطعام خلال فترات الليل.” lموقع الوطن – مقال “رئيس مركز أمراض الشيخوخة يقدم روشتة لنمط حياة صحي لكبار السن

Embedded Systems Projects Ideas for Engineering Students

List of Embedded Systems Projects Ideas:

Project Title
Auto Power Supply Control from 4 Different Sources: Solar, Mains, Generator & Inverter to Ensure No Break Power
Automated Car Dash Board
Automated Town Water Management System Using PIC
Automatic Door Bell with Object Detection
Automatic bidirectional visitor counter using 8051 microcontroller (AT89C51)
Automatic plant Irrigation (AT89C2051)
Automatic College Bell (AT89S8252 & DS1307)
Automatic Dialing to Any Telephone Using I2C Protocol on Detecting Burglary
Automatic Door Opening System with Movement Sense
Automatic irrigation System on Sensing Soil Moisture Content
Automatic Room light Controller with Visitor Counter (AT89S52)
Automatic Surveillance Camera Panning System from PC
Cell Phone Based DTMF Controlled Garage Door Opening System
Cell Phone Controlled Robotic Vehicle
Celsius and Fahrenheit scale digital thermometer using 8051 microcontroller (AT89C51)
Celsius scale digital thermometer using 8051 microcontroller (AT89C51)
Clap counter using 8051 microcontroller (AT89C51)
Remote Jamming Device
3 LED Bike Light using PIC10F200
3-Switch Mini IR Remote Control Continue Reading →
PHP Template Engine Comparison

Summary (assign)

Test tot. time tot. memory package size
php 5.4.4-14+deb7u5 2001 μs 12.16 KB 4 KB
raintpl 2.7.0 5113 μs 321.86 KB 37 KB
twig 1.5.1 17671 μs 844.86 KB 647 KB
smarty 3.1.11 20411 μs 1.52 MB 1100 KB


Next Page