The main idea is to relax all the edges exactly n - 1 times (read relaxation above in dijkstra). You can prove this algorithm using induction.
If in the n - th step, we relax an edge, then we have a negative cycle (this is if and only if).

The steps involved are:

The outer loop traverses from 0 to N

Loop over all edges, check if the next node distance > current node distance + edge weight, in this case update the next node distance to "current node distance + edge weight".

This algorithm depends on the relaxation principle where the shortest distance for all vertices is gradually replaced by more accurate values until eventually reaching the optimum solution. In the beginning all vertices have a distance of "Infinity", but only the distance of the source vertex = 0, then update all the connected vertices with the new distances (source vertex distance + edge weights), then apply the same concept for the new vertices with new distances and so on.

Java

/**
* An implementation of the Bellman-Ford algorithm. The algorithm finds
* the shortest path between a starting node and all other nodes in the graph.
* The algorithm also detects negative cycles.
*
* @author William Fiset, william.alexandre.fiset@gmail.com
**/
public class BellmanFordEdgeList {
// A directed edge
public static class Edge {
double cost;
int from, to;
public Edge(int from, int to, double cost) {
this.to = to;
this.from = from;
this.cost = cost;
}
}
/**
* An implementation of the Bellman-Ford algorithm. The algorithm finds
* the shortest path between a starting node and all other nodes in the graph.
* The algorithm also detects negative cycles. If a node is part of a negative
* cycle then the minimum cost for that node is set to Double.NEGATIVE_INFINITY.
*
* @param edges - An edge list containing directed edges forming the graph
* @param V - The number of vertices in the graph.
* @param start - The id of the starting node
**/
public static double[] bellmanFord(Edge[] edges, int V, int start) {
double[] dist = new double[V];
java.util.Arrays.fill(dist, Double.POSITIVE_INFINITY);
dist[start] = 0;
// For each vertex, apply relaxation for all the edges
for (int v = 0; v < V-1; v++)
for (Edge edge : edges)
if (dist[edge.from] + edge.cost < dist[edge.to])
dist[edge.to] = dist[edge.from] + edge.cost;
// Run algorithm a second time to detect which nodes are part
// of a negative cycle. A negative cycle has occurred if we
// can find a better path beyond the optimal solution.
for (int v = 0; v < V-1; v++)
for (Edge edge : edges)
if (dist[edge.from] + edge.cost < dist[edge.to])
dist[edge.to] = Double.NEGATIVE_INFINITY;
// Return the array containing the shortest distance to every node
return dist;
}
public static void main(String[] args) {
int E = 10, V = 9, start = 0;
Edge [] edges = new Edge[E];
edges[0] = new Edge(0,1,1);
edges[1] = new Edge(1,2,1);
edges[2] = new Edge(2,4,1);
edges[3] = new Edge(4,3,-3);
edges[4] = new Edge(3,2,1);
edges[5] = new Edge(1,5,4);
edges[6] = new Edge(1,6,4);
edges[7] = new Edge(5,6,5);
edges[8] = new Edge(6,7,4);
edges[9] = new Edge(5,7,3);
double[] d = bellmanFord(edges, V, start);
for (int i = 0; i < V; i++)
System.out.printf("The cost to get from node %d to %d is %.2f\n", start, i, d[i] );
// Output:
// The cost to get from node 0 to 0 is 0.00
// The cost to get from node 0 to 1 is 1.00
// The cost to get from node 0 to 2 is -Infinity
// The cost to get from node 0 to 3 is -Infinity
// The cost to get from node 0 to 4 is -Infinity
// The cost to get from node 0 to 5 is 5.00
// The cost to get from node 0 to 6 is 5.00
// The cost to get from node 0 to 7 is 8.00
// The cost to get from node 0 to 8 is Infinity
}
}

Applications

The applications of Bellman-Ford Algorithm are:

Bellman-Ford Algorithm works without the full network view/ knowledge and thus, can be used in distance vector algorithms.
Running Dijkstra's algorithm requires full knowledge of all edges and weights in the network. Unlike link state routing algorithms, distance vector algorithms do not construct such a full network map. Thus, Bellman-Ford Algorithm is superior to Dijkstra's Algorithm in this case.

Bellman-Ford Algorithm terminates upon finding a negative cycle and hence, can be used to detect it.