Monday, May 30, 2016

Java Threading - Usage of synchronized key word

Go through the following simple code snippet. It increment the value of variable using two threads.

public class App {
 private int number = 0;
 
 public static void main(String args[]){
   App app = new App();
   app.increment();
 } 
 public void increment(){
  Thread t1 = new Thread(new Runnable(){
   @Override
   public void run() {
    for(int i=0;i<10000;i++){
     number=number+1;
    }
   }   
  });  
  Thread t2 = new Thread(new Runnable(){
   @Override
   public void run() {
    for(int i=0;i<10000;i++){
     number=number+1;
    }
   }   
  });  
  t1.start();
  t2.start();

Monday, May 16, 2016

What is continuous integration (CI)

Continuous integration is one of software engineering best practices. this post summarize the my attempt of finding what continuous integration is and it's uses.

First of all lets see what is continuous integration is in a simple sentence.

it is simply a mechanism that rebuilds your project whenever a check in is made into some revision control system.

This can be extended though to include running tests, all the way through to generating a CD image, mounting it within VMs, installing the product and running full tests on it.

This explanation was taken from a stackoverflow post.

It describe the advantages of continuous integration as well in the same post and it says,

Continuous integration has the simple advantage of highlighting when code changes break the system as early as possible. Not only does it detect breaks in the code, it highlights who caused the break. This psychological effect is very effective in encouraging good testing prior to check in!

Lets see important facts about continuous integration in points.
  • Continuous Integration is a software development practice where members of a team integrate their work frequently(usually each person integrates at least daily)
  • It lead to multiple integration s per day. So each integration is verified by an automated build (including test) to detect integration errors as quickly as possible.
  • Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly
Those points are obtained from a nice article about continuous integration written by Martin Fowler.

CI originated from within the extreme programming paradigm but the principles can be applied to any iterative programming model, such as agile programming. Traditional development approaches, such as the waterfall model can benefit from using CI methods for the construction stage.

Sunday, May 15, 2016

Java Threading - Usage of volatile key word.

Threading is important when considering the obligation of work in a program, handle more than one event at a time. But if it is not used in proper way it can lead to some problems as well.

Data being cached is a problem that can encounter in some scenarios. Lets take a look at one.

Consider the following java class

class Processor extends Thread{
 private boolean running =true;
 public void run(){
  while(running){
   System.out.println("hello ");
   try{
    Thread.sleep(100);
   }catch(InterruptedException e){
    e.printStackTrace();
   }
  }
 }
 public void shutDown(){
  running = false;
 }
}

Difference between compiled and interpreted programming languages

When considering about implementation of different programming languages they have used different approaches to achieve their goals. Compiled and interpreted are two different implementations which are used by people who developed programming languages.

I wanted to know what are these interpreted and compiled programming languages, what are the differences, advantages and disadvantages of those approaches. In this post I'm presenting simple and clear answers, I found in my small research of interpreted and compiled programming languages.

[This content is from a answer to a stackoverflow question about programming languages.]

  • In a compiled implementation, the original program is translated into native machine instructions, which are executed directly by the hardware.

Optimize you working enviorenment : Single command to create & move to a directory in linux (C Shell, Bash)

Usually move to a directory just after creating is bit of a anxious task specially if the directory name is too long. mkdir long-name-of...