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.

Saturday, April 16, 2016

Java Threading - Three ways to create java threads

In programming, threading is a way of distributing our work. We can delegate a huge load of work in to several threads (i.e several processes). A thread will run as a separate operating system process which can run concurrently with other threads.

There are three ways of creating threads in java

1. Extend the thread class

Thread class has a run method and need override method with the code to run in a its own thread.
To execute code in a separate thread,
  • Instantiate an object of class which is extended by Thread class (Runner)
  • Invoke the start() method of Thread class.
    • start() method will go to Thread class and look for the run method and invoke that in a separate thread.

2. Implement Runnable interface

  • Implement Runnable interface in a class
  • Pass object of that class to a constructor of Thread class.
  • Invoke the start() method 




3. Instantiate a Thread object with a Runnable instance

Java Socket Programming - Simple Server And Client

In Java socket programming(Network programming) we basically study about how to implement programs that communicate over a network. When we use java to implement those kind of applications java.net package will be used because it contains collection of classes and interfaces that provide low level communication details. It provides support for TCP and UDP which are two major network protocols.


Process between client and a server


  • First client program creates a socket and try to connect to a socket in a server. That server socket should be already created and ready for client requests. 
  • After a connection is made server and client communicate by writing and reading from the socket.

Wednesday, February 24, 2016

Sorting Algorithms - Part I

Selection Sorting

Algorithm

for i = 1:n,
    k = i
    for j = i+1:n, if a[j] < a[k], k = j
    → invariant: a[k] smallest of a[i..n]
    swap a[i,k]
    → invariant: a[1..i] in final position
end

Implementation in Java

public static void selectionSorting(int[] arr){  
  for(int i=0;i<arr.length;i++){
   int k =i;
   for(int j=i+1;j<arr.length;j++){
    if(arr[j]<arr[k]){
     k=j;
    }
   }
   int temp=arr[k];
   arr[k]=arr[i];
   arr[i]=temp;
  }  
 }

Properties

  • O(1) extra space
  • O(n2) comparisons
  • O(n) swaps

Usage

This algorithms has O(n2) comparisons property so run time is always quadratic. So selection sort is not an algorithm that we don't want to use.
Interesting property is it minimizes the number of swaps. There for it can be used in sorting where swapping costs  high.

Saturday, February 13, 2016

What is a Java Bean (JB)

There are lot of confusions among people new to Java programming what is a Java Bean. What does that really mean. Is it a different type of class in Java as Enum . I also had all those questions at the beginning. So here i'm writing about what i learn on the way of finding what java bean is.
  • What is a Java Bean
Simple answer for that is Java Bean is also a normal java class. But all java classes are not java beans.
To be a Java Bean classes should have following,
  1. All properties of the class should be private. Getters and setters can be used to get and set the elements.
  2. Class should has a public but no-argument constructor.
  3. Java Serializable interface should be implemented.
So if those things have in a java class we can call it as a Java Bean. So it is a standard 
People use Word java bean to recognize java classes which are built in a predefined way.

  • Could you give me an example
Here is an example java bean

public class Employee implements java.io.Serializable{  

private int id;  
private String name; 
private String address;
private int age;
  
public Employee(){}  
  
public void setId(int id){this.id=id;}  
  
public int getId(){return id;}  
  
public void setName(String name){this.name=name;}  
  
public String getName(){return name;}  

public void setAge(int age){this.age=age;}

public int getAge(){return age;}
  
}  

Look whether this has all the features mentioned above. YES. so this is a java bean

Note: Remember,  we talked about normal java beans. there is whole different thing named EJB (enterprise java bean). names are similar. but don't be mixed with plain java beans and Enterprise java beans.

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...