<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5553707859049859464</id><updated>2026-03-07T05:45:50.068-08:00</updated><category term="Basic Java Programs"/><category term="Java File Example"/><category term="String Example"/><category term="Excel Example"/><category term="Java Class Examples"/><category term="Zip File"/><category term="ArrayList Examples"/><category term="Array Example"/><category term="JDBC"/><category term="Java AWT Example"/><category term="Java Network Example"/><category term="Java Swing Example"/><category term="Email Example"/><category term="MIDI Sound"/><category term="Java MultiThreading Example"/><category term="Random Function"/><category term="Sorting Example"/><category term="XML Parsing"/><category term="CSV Example"/><category term="Data Structure"/><category term="Java Exception Example"/><category term="Java Map Example"/><category term="Operator Example"/><category term="Java Command Example"/><category term="Java Mail Examples"/><category term="Java Vector Example"/><category term="PDF Generation Example"/><category term="Robot Class"/><category term="Stack Example"/><category term="Algorithm"/><category term="Encryption Example"/><category term="JFrame Example"/><category term="Java Database Example"/><category term="Java Date and Time Example"/><category term="Java DateFormat Example"/><category term="Java IO Example"/><category term="Java Image Examle"/><category term="Java Inheritance Example"/><category term="Java JSON Example"/><category term="Java XML Example"/><category term="MD5 Hashing Example"/><category term="PDF File Example"/><category term="Prime Number"/><category term="Searching Example"/><category term="Switch Case"/><category term="iText Example"/><category term="Bing API Example"/><category term="Break Statement"/><category term="BufferedReader Example"/><category term="Date Example"/><category term="FTP Example"/><category term="If Condition"/><category term="JSP Example"/><category term="Java Examples"/><category term="Java MapReduce Example"/><category term="Java Robot Class Examples"/><category term="Java Zip Class Examples"/><category term="LinkedList Example"/><category term="Module Operator Example"/><category term="Pre and Post Operator"/><category term="Property List Example"/><category term="Recursion Example"/><category term="Regex Example"/><category term="Remote Host Example"/><category term="StreamTokenizer Example"/><category term="Thumbnail Example"/><category term="TimerTask Example"/><category term="Validation Example"/><category term="jUnit Example"/><category term="Agile Methodology"/><category term="AntiSamy"/><category term="Arithmetic Operation"/><category term="Average an Array of Values"/><category term="Barcode Example"/><category term="BitSet Example"/><category term="Boolean Example"/><category term="Bouncy Castle API"/><category term="CRC Example"/><category term="Calendar Example"/><category term="Chart Generation Example"/><category term="Command Line Argument"/><category term="Comparator Example"/><category term="Concatenation of String"/><category term="Continue Statement"/><category term="Control Structure"/><category term="Copy File Example"/><category term="Directory Example"/><category term="Do - While Loop Example"/><category term="Domino Database"/><category term="Factorial Example"/><category term="File Upload Example"/><category term="Find Roots of Quadratic Equation"/><category term="GSON Library"/><category term="Graph Examples"/><category term="Greater between Two Numbers"/><category term="HashMap Example"/><category term="HashSet Example"/><category term="Hello World Program"/><category term="Inner Class Example"/><category term="JAR File"/><category term="JAVA Applet"/><category term="JDK Version Comparison"/><category term="JOptionPane Dialog Example"/><category term="JPanel Example"/><category term="JSTL Example"/><category term="Java Applications"/><category term="Java Certification"/><category term="Java Collection Example"/><category term="Java Constructor Examples"/><category term="Java Currency Example"/><category term="Java GUI Example"/><category term="Java Input Output Example"/><category term="Java Jar Example"/><category term="Java Package"/><category term="Java Programs"/><category term="Java RMI"/><category term="Java Runtime Example"/><category term="Java Util Example"/><category term="Java Voice Example"/><category term="Java Webservice Example"/><category term="List Example"/><category term="Long Variable"/><category term="Lottery Nubmer"/><category term="Memory Management Example"/><category term="Method Override"/><category term="Multiplication Table"/><category term="Observer Interface Example"/><category term="Pagination"/><category term="Palindrome Number"/><category term="Pass By Reference Example"/><category term="Pass By Value Example"/><category term="Progress Bar Example"/><category term="Slideshow"/><category term="SpringLayout Example"/><category term="Static Variable"/><category term="Struts2 Example"/><category term="Sum of Digits"/><category term="Swap Two Numbers"/><category term="Tapestry Components"/><category term="To Calculate Volume"/><category term="To Check Armstrong Number"/><category term="Tree Example"/><category term="TreeMap Example"/><category term="TreeSet Example"/><category term="Two Dimensional Array Example"/><category term="UUID"/><category term="Variable Casting"/><category term="While Loop"/><category term="XSS Attacks"/><title type='text'>Java Programs and Examples with Output</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>683</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-8417777860157349845</id><published>2014-08-13T15:27:00.000-07:00</published><updated>2014-08-13T15:27:27.774-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Searching Example"/><title type='text'>Java program to create a Binary Heap and Perform various operation</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
A binary heap (min-heap) is a complete binary tree with elements from a
partially ordered set, such that the element at every node is less than (or
equal to) the the element at it&#39;s left and right child.&lt;br /&gt;
&lt;br /&gt;
This Binary Heap is a min-heap implemented with one-based array (root is
element 1; children of element n are elements 2n and 2n+1) for simplicity.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Complexity&lt;/i&gt;&lt;/b&gt;: Space O(n), findMin O(1), insert O(logn), deleteMin O(logn),
buildHeap O(n);
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;class BinaryHeap {

 private int nodes[];
 private int size;
 private int capacity;
 

 public BinaryHeap(int capacity) {
  this.size = 0;
  this.capacity = capacity;
  this.nodes = new int[capacity + 1];
 }

 public int size() {
  return size;
 }

 public int findMin() {
  if (size &amp;lt;= 0) {
   throw new RuntimeException(&quot;Empty Heap is empty.&quot;);
  }
  return nodes[1];
 }

 public void insert(int e) {
  if (size &amp;gt;= capacity) {
   throw new RuntimeException(&quot;Heap overflow.&quot;);
  }

  size++;
  nodes[size] = e;
  percolateUp();
 }

 public int deleteMin() {
  if (size &amp;lt;= 0) {
   throw new RuntimeException(&quot;Empty Heap is empty.&quot;);
  }
  int min = findMin();
  nodes[1] = nodes[size];
  size--;
  percolateDown();
  return min;
 }

 private void percolateDown() {
  int index = 1;
  while (true) {
   int child = index * 2;
   if (child &amp;gt; size)
    break;
   if (child + 1 &amp;lt;= size) {
    // if there are two children -&amp;gt; take the smallest or
    // if they are equal take the left one
    child = findMin(child, child + 1);
   }
   if (nodes[index] &amp;lt;= nodes[child])
    break;
   swap(index, child);
   index = child;
  }
 }

 private void percolateUp() {
  int index = size();
  while (index &amp;gt; 1) {
   int parent = index / 2;
   if (nodes[index] &amp;gt;= nodes[parent])
    break;
   swap(index, parent);
   index = parent;
  }
 }

 private void swap(int i, int j) {
  int temp = nodes[i];
  nodes[i] = nodes[j];
  nodes[j] = temp;
 }

 private int findMin(int leftChild, int rightChild) {
  if (nodes[leftChild] &amp;lt;= nodes[rightChild]) {
   return leftChild;
  } else {
   return rightChild;
  }
 }
 
 public static void main(String[] args) {
  BinaryHeap bh = new BinaryHeap(10);
  bh.insert(7);
  bh.insert(5);
  bh.insert(9);
  bh.insert(6);
  bh.insert(4);
  bh.insert(8);
  bh.insert(10);
  bh.insert(1);
  bh.insert(3);
  bh.insert(2);
  
  System.out.println(&quot;Size of Binary Heap is : &quot; + bh.size());

  System.out.println(&quot;Delete min from Binary Heap : &quot; + bh.deleteMin());
  System.out.println(&quot;Size of Binary Heap is : &quot; + bh.size());

  System.out.println(&quot;Delete min from Binary Heap : &quot; + bh.deleteMin());
  System.out.println(&quot;Size of Binary Heap is : &quot; + bh.size());
 }
 
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Output of this Program&lt;/b&gt;

&lt;br /&gt;
&lt;pre class=&quot;&quot; style=&quot;background-color: white !important; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 0px; color: #333333; font-family: Monaco, Menlo, Consolas, &#39;Courier New&#39;, monospace; font-size: 13px; line-height: 20px; padding: 0px !important; tab-size: 4; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;&quot;&gt;Size of Binary Heap is : 10
Delete min from Binary Heap : 1
Size of Binary Heap is : 9
Delete min from Binary Heap : 2
Size of Binary Heap is : 8
&lt;/pre&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;Try this by Yourself :&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://ideone.com/FnSiPv&quot;&gt;http://ideone.com/FnSiPv&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/8417777860157349845/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2014/08/java-program-to-create-binary-heap-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/8417777860157349845'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/8417777860157349845'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2014/08/java-program-to-create-binary-heap-and.html' title='Java program to create a Binary Heap and Perform various operation'/><author><name>Happy Coder</name><uri>http://www.blogger.com/profile/10351448605389567935</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-8043801907837261450</id><published>2014-08-13T15:07:00.001-07:00</published><updated>2014-08-13T15:07:58.674-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Data Structure"/><category scheme="http://www.blogger.com/atom/ns#" term="Graph Examples"/><category scheme="http://www.blogger.com/atom/ns#" term="Searching Example"/><title type='text'>Create an Adjacency matrix Graph and perform Add and Remove operation</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;import java.util.ArrayList;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Stack;

/**
 * Implementation of a directed unweighted Graph using Adjacency Matrix
 * 
 * Complexity: addEdge, removeEdge, hasEdge O(1) / outEdges, inEdges O(n) /
 * Space O(n^2)
 */
public class AdjMatrixGraph {
 int size;
 private boolean[][] matrix;
 public static final byte WHITE = 1;
 public static final byte GREY = 2;

 public AdjMatrixGraph(int size) {
  this.size = size;
  this.matrix = new boolean[size][size];
 }

 public void addEdge(int nodeA, int nodeB) {
  matrix[nodeA][nodeB] = true;
 }

 public void removeEdge(int nodeA, int nodeB) {
  matrix[nodeA][nodeB] = false;
 }

 public boolean hasEdge(int nodeA, int nodeB) {
  return matrix[nodeA][nodeB];
 }

 public List&amp;lt;Integer&amp;gt; outEdges(int i) {
  List&amp;lt;Integer&amp;gt; edges = new ArrayList&amp;lt;Integer&amp;gt;();
  for (int j = 0; j &amp;lt; size; j++) {
   if (matrix[i][j]) {
    edges.add(j);
   }
  }
  return edges;
 }

 public List&amp;lt;Integer&amp;gt; inEdges(int i) {
  List&amp;lt;Integer&amp;gt; edges = new ArrayList&amp;lt;Integer&amp;gt;();
  for (int j = 0; j &amp;lt; size; j++) {
   if (matrix[j][i]) {
    edges.add(j);
   }
  }
  return edges;
 }

 public int nVertices() {
  return size;
 }

 public void breadthFirstSearch(int root) {
  boolean[] seen = new boolean[nVertices()];
  Queue&amp;lt;Integer&amp;gt; q = new LinkedList&amp;lt;Integer&amp;gt;();
  q.add(root);
  seen[root] = true;
  while (!q.isEmpty()) {
   int i = q.remove();
   for (Integer j : outEdges(i)) {
    if (!seen[j]) {
     q.add(j);
     seen[j] = true;
    }
   }
  }
 }

 public void depthFirstSearch(int r) {
  byte[] c = new byte[nVertices()];
  Stack&amp;lt;Integer&amp;gt; s = new Stack&amp;lt;Integer&amp;gt;();
  s.push(r);
  while (!s.isEmpty()) {
   int i = s.pop();
   if (c[i] == WHITE) {
    c[i] = GREY;
    for (int j : outEdges(i))
     s.push(j);
   }
  }
 }

 public static void main(String[] args) {
  AdjMatrixGraph graph = new AdjMatrixGraph(10);

  graph.addEdge(1, 3);
  graph.addEdge(2, 4);
  graph.addEdge(6, 8);
  graph.addEdge(3, 2);

  System.out.println(&quot;Edge from 6 to 8 is : &quot; + graph.hasEdge(6, 8));
  System.out.println(&quot;Edge from 2 to 4 is : &quot; + graph.hasEdge(2, 4));
  System.out.println(&quot;Edge from 3 to 2 is : &quot; + graph.hasEdge(3, 2));
  System.out.println(&quot;Edge from 1 to 3 is : &quot; + graph.hasEdge(1, 3));

  graph.removeEdge(6, 8);
  System.out.println(&quot;Edge from 6 to 8 is : &quot; + graph.hasEdge(6, 8));

 }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Output of this Program:&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;&quot; style=&quot;background-color: white !important; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 0px; color: #333333; font-family: Monaco, Menlo, Consolas, &#39;Courier New&#39;, monospace; font-size: 13px; line-height: 20px; padding: 0px !important; tab-size: 4; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;&quot;&gt;Edge from 6 to 8 is : true
Edge from 2 to 4 is : true
Edge from 3 to 2 is : true
Edge from 1 to 3 is : true
Edge from 6 to 8 is : false
&lt;/pre&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;Try this by Yourself :&lt;/span&gt;&amp;nbsp;&lt;a href=&quot;http://ideone.com/ZZm7rW&quot;&gt;http://ideone.com/ZZm7rW&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/8043801907837261450/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2014/08/create-adjacency-matrix-graph-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/8043801907837261450'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/8043801907837261450'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2014/08/create-adjacency-matrix-graph-and.html' title='Create an Adjacency matrix Graph and perform Add and Remove operation'/><author><name>Happy Coder</name><uri>http://www.blogger.com/profile/10351448605389567935</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-3652304523130544083</id><published>2014-08-11T16:37:00.001-07:00</published><updated>2014-08-11T16:37:58.086-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Algorithm"/><category scheme="http://www.blogger.com/atom/ns#" term="Sorting Example"/><title type='text'>To Sort an Interger Array using Shell Sort</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
To Sort an Interger Array using Shell Sort&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;class ShellSort {

    public static int[] shellSort(int[] array) {
  int N = array.length;
  
  // determine the initial h value
  int h = 1;
     while (h &amp;lt; N / 3) 
      h = 3 * h + 1; // 1, 4, 13, 40, 121, 364, 1093, ...
     
     while (h &amp;gt;= 1) {
      // h-sort the array
      for (int i = h; i &amp;lt; array.length; i++) {
       // do insertion sort for h-sized array
       for (int j = i; j &amp;gt;= h &amp;amp;&amp;amp; array[j] &amp;lt; array[j - h]; j -= h)
        swap(array, j, j - h);
      }
      
      h = h / 3; // reverse the h-size
     }
     
     return array;
 }
 
 /*
  * swaps data elements between 2 indexes of an array
  */
 private static void swap(int[] array, int i, int j) {
  int temp = array[i];
  array[i] = array[j];
  array[j] = temp;
 } 
    
    public static void  main(String args[]){
     ShellSort sSort = new ShellSort();
     int[] array = { 77, 99, 44, 55, 22, 88, 11, 0, 66, 33 };
     int[] sortedArray = sSort.shellSort(array);
     for (int i = 0; i &amp;lt; array.length; i++)
         System.out.println(sortedArray[i]);
     
    }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Output of the Program :&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;&quot; style=&quot;background-color: white !important; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 0px; color: #333333; font-family: Monaco, Menlo, Consolas, &#39;Courier New&#39;, monospace; font-size: 13px; line-height: 20px; padding: 0px !important; tab-size: 4; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;&quot;&gt;0
11
22
33
44
55
66
77
88
99&lt;/pre&gt;
&lt;br /&gt;
Try it by yourself here :&lt;a href=&quot;http://ideone.com/veRv5P&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;&amp;nbsp;http://ideone.com/veRv5P&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/3652304523130544083/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2014/08/to-sort-interger-array-using-shell-sort.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/3652304523130544083'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/3652304523130544083'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2014/08/to-sort-interger-array-using-shell-sort.html' title='To Sort an Interger Array using Shell Sort'/><author><name>Happy Coder</name><uri>http://www.blogger.com/profile/10351448605389567935</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-3884102298341015351</id><published>2014-08-11T16:29:00.000-07:00</published><updated>2014-08-11T16:29:49.803-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Algorithm"/><category scheme="http://www.blogger.com/atom/ns#" term="Sorting Example"/><title type='text'>Sort an Integer array with Bucket Sort</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Here is a java program to Sort an Integer array with Bucket Sort&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;class BucketSort {

    public int[] bucketSort(int[] array) {
        // create an array the size of the largest value + 1
        int[] bucket = new int[100];   

        // for every value in array, increment its corresponding bucket
        for (int i = 0; i &amp;lt; array.length; i++)
            bucket[array[i]]++;

        int outPos = 0;
        for (int i = 0; i &amp;lt; bucket.length; i++) { 
         if (bucket[i] &amp;gt; 0)
             array[outPos++] = i;
        }
        
        return array;
    }
    
    public static void  main(String args[]){
     BucketSort bSort = new BucketSort();
     int[] array = { 77, 99, 44, 55, 22, 88, 11, 0, 66, 33 };
     int[] sortedArray = bSort.bucketSort(array);
     for (int i = 0; i &amp;lt; array.length; i++)
         System.out.println(sortedArray[i]);
     
    }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Output of the Program :&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;&quot; style=&quot;background-color: white !important; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 0px; color: #333333; font-family: Monaco, Menlo, Consolas, &#39;Courier New&#39;, monospace; font-size: 13px; line-height: 20px; padding: 0px !important; tab-size: 4; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;&quot;&gt;0
11
22
33
44
55
66&lt;/pre&gt;
&lt;br /&gt;
Try By Yourself Here :&lt;a href=&quot;http://ideone.com/OpHXmH&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;&amp;nbsp;http://ideone.com/OpHXmH&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/3884102298341015351/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2014/08/sort-integer-array-with-bucket-sort.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/3884102298341015351'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/3884102298341015351'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2014/08/sort-integer-array-with-bucket-sort.html' title='Sort an Integer array with Bucket Sort'/><author><name>Happy Coder</name><uri>http://www.blogger.com/profile/10351448605389567935</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-1067566317298901472</id><published>2013-08-15T10:10:00.000-07:00</published><updated>2013-08-15T10:10:25.951-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Algorithm"/><category scheme="http://www.blogger.com/atom/ns#" term="Sorting Example"/><title type='text'>Merge-Sort Algorithm implementation in JAVA</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Merge-Sort Function&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;void MergeSort(int low, int high)
   // a[low : high] is a global array to be sorted.
   // Small(P) is true if there is only one element to
   // sort. In this case the list is already sorted.
   {
       if (low &amp;lt; high) { // If there are more than one element
              // Divide P into subproblems.
              // Find where to split the set.
              int mid = (low + high)/2;
              // Solve the subproblems.
              MergeSort(low, mid);
              MergeSort(mid + 1, high);
              // Combine the solutions.
              Merge(low, mid, high);
       }
   }

   void Merge(int low, int mid, int high)
   // a[low:high] is a global array containing two sorted
   // subsets in a[low:mid] and in a[mid+1:high]. The goal
   // is to merge these two sets into a single set residing
   // in a[low:high]. b[] is an auxiliary global array.
   {
       int h = low, i = low, j = mid+1, k;
       while ((h &amp;lt;= mid) &amp;amp;&amp;amp; (j &amp;lt;= high)) {
          if (a[h] &amp;lt;= a[j]) { b[i] = a[h]; h++; }
          else { b[i] = a[j]; j++; } i++;
       }
       if (h &amp;gt; mid) for (k=j; k&amp;lt;=high; k++) {
                       b[i] = a[k]; i++;
                    }
       else for (k=h; k&amp;lt;=mid; k++) {
               b[i] = a[k]; i++;
            }
       for (k=low; k&amp;lt;=high; k++) a[k] = b[k];
   }

&lt;/pre&gt;
&lt;br/&gt;
Merge Sort Java Code :

&lt;br/&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;
import java.util.*;

public class MergeSort {
 public int a[] = new int[50];

 public void merge_sort(int low, int high) {
  int mid;
  if (low &lt; high) {
   mid = (low + high) / 2;
   merge_sort(low, mid);
   merge_sort(mid + 1, high);
   merge(low, mid, high);
  }
 }

 public void merge(int low, int mid, int high) {
  int h, i, j, k;
  int b[] = new int[50];
  h = low;
  i = low;
  j = mid + 1;

  while ((h &lt;= mid) &amp;&amp; (j &lt;= high)) {
   if (a[h] &lt;= a[j]) {
    b[i] = a[h];
    h++;
   } else {
    b[i] = a[j];
    j++;
   }
   i++;
  }
  if (h &gt; mid) {
   for (k = j; k &lt;= high; k++) {
    b[i] = a[k];
    i++;
   }
  } else {
   for (k = h; k &lt;= mid; k++) {
    b[i] = a[k];
    i++;
   }
  }
  for (k = low; k &lt;= high; k++)
   a[k] = b[k];
 }

 public MergeSort() {
  int num, i;

  System.out.println(&quot;             MERGE SORT PROGRAM            &quot;);

  System.out.println();
  System.out.println();
  System.out
    .println(&quot;Please Enter THE No. OF ELEMENTS you want to sort[THEN PRESS ENTER]:&quot;);
  num = new Scanner(System.in).nextInt();
  System.out.println();
  System.out.println(&quot;Now, Please Enter the (&quot; + num
    + &quot;) nos. [THEN PRESS ENTER]:&quot;);
  for (i = 1; i &lt;= num; i++) {
   a[i] = new Scanner(System.in).nextInt();
  }
  merge_sort(1, num);
  System.out.println();
  System.out.println(&quot;So, the sorted list (using MERGE SORT) will be :&quot;);
  System.out.println();
  System.out.println();

  for (i = 1; i &lt;= num; i++)
   System.out.print(a[i] + &quot;    &quot;);

 }

 public static void main(String[] args) {
  new MergeSort();
 }
}
&lt;/pre&gt;

&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/1067566317298901472/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2013/08/merge-sort-algorithm-implementation-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/1067566317298901472'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/1067566317298901472'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2013/08/merge-sort-algorithm-implementation-in.html' title='Merge-Sort Algorithm implementation in JAVA'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-7369302048871023208</id><published>2013-04-22T12:39:00.000-07:00</published><updated>2013-04-22T12:40:20.332-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Data Structure"/><category scheme="http://www.blogger.com/atom/ns#" term="Tree Example"/><title type='text'>Implementation of a basic generic tree, with labels of type T - Data Structure</title><content type='html'>&lt;p&gt;&lt;/p&gt;
&lt;br/&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;
// This implements a basic generic tree, with labels of type T,
// pointer to the parent node, and a singly linked list of children nodes.

class Tree&amp;lt;T&amp;gt;  {
    private T label;
    private Tree&amp;lt;T&amp;gt; parent;
    private Tree&amp;lt;T&amp;gt; nextSibling; // next node on the list of parents&amp;#039;s 
                                 //  children
    private Tree&amp;lt;T&amp;gt; firstChild;  // first in the linked list of children

                                 
//  Getters and setters
    public T getLabel() { return label; }  
    public void setLabel(T v) { label = v; }
    public Tree&amp;lt;T&amp;gt; getParent() { return parent;}
    public Tree&amp;lt;T&amp;gt; getNextSibling() { return nextSibling;}
    public Tree&amp;lt;T&amp;gt; getFirstChild() { return firstChild;}

// Add C to the front of the children of this
    public void addChild(Tree&amp;lt;T&amp;gt; c) {
         c.parent = this;
         if (firstChild == null) 
           firstChild = c;
         else {
             c.nextSibling = firstChild;
             firstChild = c;
            }
    }

// Check if the node is a leaf
    public boolean Leaf() { return firstChild==null; }

// `Convert the tree into a string. The structure is indicated by
// square brackets. Uses a preorder listing.
    public String toString() {
       String S = &amp;quot;[ &amp;quot; + label.toString();
       Tree&amp;lt;T&amp;gt; N = firstChild;
       while (N != null) {
          S = S + &amp;quot; &amp;quot; + N.toString();
          N = N.nextSibling;
        }
       return S+&amp;quot; ]&amp;quot;;
     }

     public void displayPreorder() {
         displayPreorder1(0); }

     public void displayPreorder1(int Indent) {
         for (int I = 0; I &amp;lt; Indent; I++) System.out.print(&amp;quot; &amp;quot;);
         System.out.println(label.toString());
         Tree&amp;lt;T&amp;gt; N = firstChild;
         while (N != null) { 
            N.displayPreorder1(Indent+3);
            N = N.nextSibling;
           }
         }

     public void displayPostorder() {
         displayPostorder1(0); }

     public void displayPostorder1(int Indent) {
         Tree&amp;lt;T&amp;gt; N = firstChild;
         while (N != null) { 
            N.displayPostorder1(Indent+3);
            N = N.nextSibling;
           }
         for (int I = 0; I &amp;lt; Indent; I++) System.out.print(&amp;quot; &amp;quot;);
         System.out.println(label.toString());
         }
}
&lt;/pre&gt;
&lt;br/&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/7369302048871023208/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2013/04/implements-basic-generic-tree-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/7369302048871023208'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/7369302048871023208'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2013/04/implements-basic-generic-tree-with.html' title='Implementation of a basic generic tree, with labels of type T - Data Structure'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-6634786017111276292</id><published>2013-04-22T12:36:00.001-07:00</published><updated>2013-04-22T12:36:52.566-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Array Example"/><category scheme="http://www.blogger.com/atom/ns#" term="Data Structure"/><category scheme="http://www.blogger.com/atom/ns#" term="Stack Example"/><title type='text'>Stack implemented as array - Data Structure</title><content type='html'>&lt;p&gt;&lt;/p&gt;
&lt;br/&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;
// Stack implemented as array
public class ArrayStack&amp;lt;T&amp;gt; {
     private T[] stack;
     private int numElements = 0; // points to slot after top element

     public ArrayStack(T[] s) { stack = s; }  

     public boolean emptyStack() { 
         return numElements == 0; }
   
     public T  top() {
         return stack[numElements-1];
       }

     public void push(T x) {
         stack[numElements] = x;
         numElements++;
       }
  
     public T pop() {
         numElements--;
         return stack[numElements];
      }

    public static void main(String[] args) {
       ArrayStack&amp;lt;Integer&amp;gt; s = new ArrayStack&amp;lt;Integer&amp;gt;(new Integer[100]);
       s.push(2);
       s.push(3);
       s.push(5);
       System.out.println(s.top());
       System.out.println(s.pop());
       System.out.println(s.pop());
       s.push(15);
       s.push(22);
       System.out.println(s.pop());
   }
}
&lt;/pre&gt;
&lt;br/&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/6634786017111276292/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2013/04/stack-implemented-as-array-data.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/6634786017111276292'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/6634786017111276292'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2013/04/stack-implemented-as-array-data.html' title='Stack implemented as array - Data Structure'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-4162345232218662305</id><published>2013-04-22T12:34:00.000-07:00</published><updated>2013-04-22T12:34:51.812-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Data Structure"/><category scheme="http://www.blogger.com/atom/ns#" term="List Example"/><title type='text'>Singly linked list with header - Data Structure</title><content type='html'>&lt;p&gt;&lt;/p&gt;
&lt;br/&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;


class OrderedList  {
   private int value;
   private OrderedList next;

// Note: No setValue() method or setNext() methods are provided, 
// since those could require reordering the list.
  
   public int getValue() {
       return value; }

   public OrderedList getNext() {
       return next; }

// If X is in the list, returns the previous node.
// If X is not in the list, returns the node for the greatest element less 
// than  X.

   public OrderedList searchBefore(int x) { // Locate node containing X
       OrderedList n = this;
       while (true) {
          if (n.next==null) return n;
          if (n.next.value &gt;= x) return n;
          n = n.next;
         } 
      }

// Is element x in the list. Note the use of the left to right evaluation of 
// &amp;&amp; (if the condition n.net != null is false, then the conjunction returns
// false without evaluating n.next.value=x.

   public boolean inList(int x) {
       OrderedList n = searchBefore(x);
       return n.next != null &amp;&amp; n.next.value == x; }

// Adds x to the ordered list, if it is not already there.
   public void add(int x) {
       OrderedList n = searchBefore(x);
       if (n.next == null || n.next.value != x) {
           OrderedList newNode = new OrderedList();
           newNode.value = x;
           newNode.next = n.next;
           n.next = newNode;
         }
     }
       
// Deletes X from the ordered list, if it is there.

   public void delete(int x) {
       OrderedList n = searchBefore(x);
       if (n.next != null &amp;&amp; n.next.value == x)
          n.next = n.next.next;
      }



   public String toString() {
          OrderedList a = next;
          String s = &quot;[&quot;;
          while (a != null) {
             s = s + a.value + &quot; &quot;;
             a = a.next;
           }
         return s+ &quot;]&quot;;
         }

   public static void main(String[] args) {
      OrderedList l = new OrderedList();
      l.add(31);
      l.add(41);
      l.add(59);
      l.add(26);
      l.add(53);
      l.add(58);
      l.add(37);
      l.delete(53);
      System.out.println(l.toString());
}
}


&lt;/pre&gt;
&lt;br/&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/4162345232218662305/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2013/04/singly-linked-list-with-header-data.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/4162345232218662305'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/4162345232218662305'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2013/04/singly-linked-list-with-header-data.html' title='Singly linked list with header - Data Structure'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-454769912516998922</id><published>2013-04-22T12:32:00.001-07:00</published><updated>2013-04-22T12:32:40.879-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Array Example"/><category scheme="http://www.blogger.com/atom/ns#" term="Data Structure"/><title type='text'>Ordered array of ints with no repetition - Data Structure</title><content type='html'>&lt;p&gt;&lt;/p&gt;
&lt;br/&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;

public class OrderedArray {

   private int numElements = 0;
   private int[] elements;

// Constructor..Note: the caller has to provide the array of elements.
// This is because Java generics do not allow a call &quot;elements = new T[100]&quot;.
//
   public OrderedArray(int[] elts) {
        elements = elts; }

   public int getNumElements() { return numElements; } 

   public int nth(int n) { // return the Nth element
       if (n &lt; numElements) return elements[n]; else return -1; }
  
   public int first() { return nth(0); } 
   public int  last() { return nth(numElements-1); } 

//  search(X) returns the index where X is, if X is in the list.
//  Otherwise, it returns the index of the smallest number greater than X
   public int search(int x) {
       if (numElements==0) return 0;
       if (x &lt;= first()) return 0;
       if (x &gt; last()) return numElements;
       if (x == last()) return numElements-1;
       return search1(x,0,numElements-1); 
     }

// X is strictly between L and U.
   public int search1(int x,int l,int u) {
        if (u==l+1) return u;
        else {
           int m = (l+u)/2;
           if (x==elements[m]) return m;
           else if (x &lt; elements[m]) return  search1(x,l,m);
           else return search1(x,m,u);
        }
     }

   public boolean inList(int x) {
       return (elements[search(x)]==x); }

   public void add(int x) {
      int i = search(x);
      if (elements[i] != x)  {
        for (int j = numElements; j&gt;i; j--)
           elements[j]=elements[j-1];
        elements[i]=x;
        numElements++;
       }
     }

   public void delete(int x) {
      int i = search(x);
      if (elements[i] == x) {
        for (int j=i+1; j &lt; numElements; j++)
          elements[j-1] = elements[j];
        numElements--;
      }
    }


   public String toString() {
      String s = &quot;[&quot;;
      for (int i=0; i &lt; numElements; i++)
         s = s + &quot; &quot; + elements[i];
      return s+&quot;]&quot;;
   }

   public static void main(String[] args) {
      OrderedArray l = new OrderedArray(new int[100]);
      l.add(31);
      l.add(41);
      l.add(59);
      l.add(26);
      l.add(53);
      l.add(58);
      l.add(37);
      l.delete(53);
      System.out.println(l.toString());
      System.out.println(l.search(2));
      System.out.println(l.search(26));
      System.out.println(l.search(53));
      System.out.println(l.search(54));
      System.out.println(l.search(195));
}
}

&lt;/pre&gt;
&lt;br/&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/454769912516998922/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2013/04/ordered-array-of-ints-with-no.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/454769912516998922'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/454769912516998922'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2013/04/ordered-array-of-ints-with-no.html' title='Ordered array of ints with no repetition - Data Structure'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-7350640442789508415</id><published>2013-04-19T15:46:00.001-07:00</published><updated>2013-04-19T15:46:59.701-07:00</updated><title type='text'>Stop Watch Program - To measure the amount of time to process each input</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;
public class Stopwatch { 

    private final long start;

    public Stopwatch() {
        start = System.currentTimeMillis();
    } 

    // return time (in seconds) since this object was created
    public double elapsedTime() {
        long now = System.currentTimeMillis();
        return (now - start) / 1000.0;
    } 

}
&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/7350640442789508415/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2013/04/stop-watch-program-to-measure-amount-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/7350640442789508415'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/7350640442789508415'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2013/04/stop-watch-program-to-measure-amount-of.html' title='Stop Watch Program - To measure the amount of time to process each input'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-8916806468243951758</id><published>2012-11-03T00:00:00.000-07:00</published><updated>2012-11-03T00:00:09.982-07:00</updated><title type='text'>Parse XML file using DOM</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
This code snippet
explains about the parsing of the xml file using the DOM parser.  
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;
import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;


public class XMLParser {

    /**
     * @param args
     * @throws IOException 
     * @throws SAXException 
     */
    
    public void GetXMLValue(String FileName){
    
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db         = dbf.newDocumentBuilder();
            File file                  = new File(FileName);
            
            if(file.exists()){
                Document doc = null;
                try {
                    doc = db.parse(file);
                }
                catch (SAXException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                Element docelement1     = doc.getDocumentElement();
                
                System.out.println(&amp;quot;Root element of the document: &amp;quot;
                        + docelement1.getNodeName());                
                //for commercial credit
                NodeList valueList1 = docelement1.getElementsByTagName(&amp;quot;CommercialCredit&amp;quot;);
                
                if (valueList1 != null &amp;amp;&amp;amp; valueList1.getLength() &amp;gt; 0) {
                 
                    for (int i = 0; i &amp;lt; valueList1.getLength(); i++) {
                        
                        Node node = valueList1.item(i);
                        
                        if (node.getNodeType() == Node.ELEMENT_NODE) {
                            
                            Element e = (Element) node;
                            NodeList nodeList = e.getElementsByTagName(&amp;quot;DistSourceId&amp;quot;);
                            System.out.println(&amp;quot;DistSourceId: &amp;quot;
                                    + nodeList.item(0).getChildNodes().item(0)
                                            .getNodeValue());

                            nodeList = e.getElementsByTagName(&amp;quot;MMSReferenceStartTime&amp;quot;);
                            System.out.println(&amp;quot;MMSReferenceStartTime: &amp;quot;
                                    + nodeList.item(0).getChildNodes().item(0)
                                            .getNodeValue());

                            nodeList = e.getElementsByTagName(&amp;quot;MMSReferenceEndTime&amp;quot;);
                            System.out.println(&amp;quot;MMSReferenceEndTime: &amp;quot;
                                    + nodeList.item(0).getChildNodes().item(0)
                                            .getNodeValue());  
                        }                        
                     // for Credit result ---- added only 3 fields to test.....                        
                        
                        NodeList valueList2 = docelement1.getElementsByTagName(&amp;quot;CreditResult&amp;quot;);
                        if (valueList2 != null &amp;amp;&amp;amp; valueList2.getLength() &amp;gt; 0) {
                            
                            for (int j = 0; j &amp;lt; valueList2.getLength(); j++) {
                                
                                Element e2 = (Element) node;
                                NodeList nodeList2 = e2.getElementsByTagName(&amp;quot;MediaAssetId&amp;quot;);
                                System.out.println(&amp;quot;MediaAssetId: &amp;quot;
                                        + nodeList2.item(0).getChildNodes().item(0)
                                                .getNodeValue());
                                
                                nodeList2 = e2.getElementsByTagName(&amp;quot;DetectedTime&amp;quot;);
                                System.out.println(&amp;quot;DetectedTime: &amp;quot;
                                        + nodeList2.item(0).getChildNodes().item(0)
                                                .getNodeValue());
                                
                                nodeList2 = e2.getElementsByTagName(&amp;quot;DetectedSourceId&amp;quot;);
                                System.out.println(&amp;quot;DetectedSourceId: &amp;quot;
                                        + nodeList2.item(0).getChildNodes().item(0)
                                                .getNodeValue());  
                            }
                        }//if ends here
                    }  
                }
                else{
                    System.exit(1);
                }                    
            }
        }
        catch (ParserConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }         
    }    
    
    public static void main (String[] args) throws SAXException, IOException {
        // TODO Auto-generated method stub
        String str = &amp;quot;C:\Test\Mytestfile.xml&amp;quot;;
        new XMLParser().GetXMLValue(str);

    }

}
&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/8916806468243951758/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/11/parse-xml-file-using-dom.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/8916806468243951758'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/8916806468243951758'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/11/parse-xml-file-using-dom.html' title='Parse XML file using DOM'/><author><name>Raju Gupta</name><uri>http://www.blogger.com/profile/13350804494797609989</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-3609689668685957449</id><published>2012-11-02T21:30:00.000-07:00</published><updated>2012-11-02T21:30:02.380-07:00</updated><title type='text'>Listing Files and Directory Using Java </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
Lists Files and
directory present in the system &amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;
File dir = new File(&quot;directoryName&quot;); 
 String[] children = dir.list();
  if (children == null) 
{      
// Either dir does not exist or is not a directory 
 }
 else 
{   
   for (int i=0; i &lt; children.length; i++) 
{
          // Get filename of file or directory       
   String filename = children[i];     
 }
  }
   // It is also possible to filter the list of returned files.
  // This example does not return any files that start with `.&#39;.  
FilenameFilter filter = new FilenameFilter() 
{      
public boolean accept(File dir, String name)
 {
          return !name.startsWith(&quot;.&quot;);    
  }
  };
  children = dir.list(filter);
   // The list of files can also be retrieved as File 
File[] files = dir.listFiles();   
// This filter only returns directories  
FileFilter fileFilter = new FileFilter()
 {

      public boolean accept(File file)
 {
          return file.isDirectory();   
   }
  };  
files = dir.listFiles(fileFilter); 

&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/3609689668685957449/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/11/listing-files-and-directory-using-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/3609689668685957449'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/3609689668685957449'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/11/listing-files-and-directory-using-java.html' title='Listing Files and Directory Using Java '/><author><name>Raju Gupta</name><uri>http://www.blogger.com/profile/13350804494797609989</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-6950633542759108193</id><published>2012-11-02T11:30:00.000-07:00</published><updated>2012-11-02T11:30:03.222-07:00</updated><title type='text'>To Capture screen shots using Java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;
public void captureScreen(String fileName) throws Exception 
{
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();   
Rectangle screenRectangle = new Rectangle(screenSize);  
 Robot robot = new Robot();  
 BufferedImage image = robot.createScreenCapture(screenRectangle);  
 ImageIO.write(image, &quot;png&quot;, new File(fileName)); 
}

&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/6950633542759108193/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/11/to-capture-screen-shots-using-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/6950633542759108193'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/6950633542759108193'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/11/to-capture-screen-shots-using-java.html' title='To Capture screen shots using Java'/><author><name>Raju Gupta</name><uri>http://www.blogger.com/profile/13350804494797609989</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-8976893402227918275</id><published>2012-11-02T03:48:00.000-07:00</published><updated>2012-11-02T03:48:00.129-07:00</updated><title type='text'>Extract a zip file in Java </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
The sole purpose
of this program is how to extarct the content of a zip file in java.We
start by opening an input stream to the compressed file and an output
stream to the file where we want the content to be extracted. 
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
After that we get
the next entry of the zip file (and the only entry in this case) -
test so it&#39;s not null, and then start reading the contents from the
input stream and writing each chunk read to the output stream. 
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
As usual we should
clean up properly afterwards so we close the input and output
streams. 
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class ExtractingZipFile{

    /**
     * Extracts a zip file
     */
    public void extractZipFile() {
        
        try {
            String zipFileName = &quot;file.zip&quot;;
            String extractedFileName = &quot;extractedfile.txt&quot;;
            
            //Create input and output streams
            ZipInputStream inStream = new ZipInputStream(new FileInputStream(zipFileName));
            OutputStream outStream = new FileOutputStream(extractedFileName);
            
            ZipEntry entry;
            byte[] buffer = new byte[1024];
            int nrBytesRead;
            
            //Get next zip entry and start reading data
            if ((entry = inStream.getNextEntry()) != null) {
                while ((nrBytesRead = inStream.read(buffer)) &gt; 0) {
                    outStream.write(buffer, 0, nrBytesRead);
                }
            }
                    
            //Finish off by closing the streams
            outStream.close();
            inStream.close();
            
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new ExtractingZipFile().extractZipFile();
    }
    
}

&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/8976893402227918275/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/11/extract-zip-file-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/8976893402227918275'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/8976893402227918275'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/11/extract-zip-file-in-java.html' title='Extract a zip file in Java '/><author><name>Raju Gupta</name><uri>http://www.blogger.com/profile/13350804494797609989</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-598476546780152010</id><published>2012-11-02T00:00:00.000-07:00</published><updated>2012-11-02T00:00:11.184-07:00</updated><title type='text'>Albers Square using JAVA</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
Albers Square
using JAVA&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;
public class AlbersSquares {

    public static void main(String[] args) {

        StdDraw.setCanvasSize(800, 800);

        // first color
        int r1 = Integer.parseInt(args[0]);
        int g1 = Integer.parseInt(args[1]);
        int b1 = Integer.parseInt(args[2]);
        Color c1 = new Color(r1, g1, b1);

        // second color
        int r2 = Integer.parseInt(args[3]);
        int g2 = Integer.parseInt(args[4]);
        int b2 = Integer.parseInt(args[5]);
        Color c2 = new Color(r2, g2, b2);

        // first Albers square
        StdDraw.setPenColor(c1);
        StdDraw.filledSquare(.25, .5, .2);
        StdDraw.setPenColor(c2);
        StdDraw.filledSquare(.25, .5, .1);

        // second Albers square
        StdDraw.setPenColor(c2);
        StdDraw.filledSquare(.75, .5, .2);
        StdDraw.setPenColor(c1);
        StdDraw.filledSquare(.75, .5, .1);
    } 
} 

&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/598476546780152010/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/11/albers-square-using-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/598476546780152010'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/598476546780152010'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/11/albers-square-using-java.html' title='Albers Square using JAVA'/><author><name>Raju Gupta</name><uri>http://www.blogger.com/profile/13350804494797609989</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-7569308161160945446</id><published>2012-11-01T15:30:00.000-07:00</published><updated>2012-11-01T15:30:00.819-07:00</updated><title type='text'>Doubling Stack of Strings using Java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
Doubling Stack of
Strings using Java &amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;
import java.util.Iterator;
import java.util.NoSuchElementException;

public class DoublingStackOfStrings implements Iterable&amp;lt;String&amp;gt; {
    private String[] a;
    private int N;

    public DoublingStackOfStrings() {
        a = new String[2];
        N = 0;
    }

    // is the stack empty?
    public boolean isEmpty() {  return (N == 0);  }

    // resize the underlying array holding the elements
    private void resize(int capacity) {
        String[] temp = new String[capacity];
        for (int i = 0; i &amp;lt; N; i++) {
            temp[i] = a[i];
        }
        a = temp;
    }

    // push a new item onto the stack
    public void push(String item) {
        if (N == a.length) resize(2*a.length);
        a[N++] = item;
    }

    // delete and return the item most recently added
    public String pop() {
        if (isEmpty()) { throw new RuntimeException(&amp;quot;Stack underflow error&amp;quot;); }
        String item = a[--N];
        a[N] = null;  // to avoid loitering
        if (N &amp;gt; 0 &amp;amp;&amp;amp; N == a.length/4) resize(a.length/2);
        return item;
    }

    public Iterator&amp;lt;String&amp;gt; iterator()  { return new ReverseArrayIterator();  }

    // an iterator, doesn&amp;#039;t implement remove() since it&amp;#039;s optional
    private class ReverseArrayIterator implements Iterator&amp;lt;String&amp;gt; {
        private int i = N;
        public boolean hasNext()  { return i &amp;gt; 0;                               }
        public void remove()      { throw new UnsupportedOperationException();  }

        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            return a[--i];
        }
    }

    // test client
    public static void main(String[] args) {
        DoublingStackOfStrings s = new DoublingStackOfStrings();
        while (!StdIn.isEmpty()) {
            String item = StdIn.readString();
            if (!item.equals(&amp;quot;-&amp;quot;)) s.push(item);
            else if (s.isEmpty())  StdOut.println(&amp;quot;BAD INPUT&amp;quot;);
            else                   StdOut.print(s.pop());
        }
    }

}
&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/7569308161160945446/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/11/doubling-stack-of-strings-using-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/7569308161160945446'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/7569308161160945446'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/11/doubling-stack-of-strings-using-java.html' title='Doubling Stack of Strings using Java'/><author><name>Raju Gupta</name><uri>http://www.blogger.com/profile/13350804494797609989</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-826907227308243192</id><published>2012-11-01T10:30:00.000-07:00</published><updated>2012-11-01T10:30:00.988-07:00</updated><title type='text'>Excel Comparator xls or xlsx in java </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
we can compare any
two excels of extension either xls or xlsx &amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class Excelcomparison {
 ArrayList&amp;lt;String&amp;gt; listOfTerms =null;
 ArrayList&amp;lt;String&amp;gt; al =new ArrayList&amp;lt;String&amp;gt;();
 ArrayList&amp;lt;String&amp;gt; finallist = new ArrayList&amp;lt;String&amp;gt;();
 public  Workbook checkFileFormat(String fileName){
  Workbook hwb=null;
  
  FileInputStream checkFis=null;
  try{
    checkFis=new FileInputStream(fileName);
    //Instantiate the Workbook using HSSFWorkbook
    hwb=(Workbook)new HSSFWorkbook(checkFis);
    Sheet sheet=hwb.getSheetAt(0);
    Iterator&amp;lt;Row&amp;gt; rows=sheet.rowIterator();
   
    Iterator&amp;lt;Cell&amp;gt; cells=null;
    Row row=null;
    Cell cell=null;
    int check=0;
    //Read the file as HSSFWorkbook
    while(rows.hasNext()){
    check++;
    row=(HSSFRow)rows.next();
    cells=row.cellIterator();
    while(cells.hasNext()){
     cell=(HSSFCell)cells.next();
    }
    if(check==2)
     break;
   }
   //Return HSSFWorkbook type object if there is no exception in reading the file using HSSFWorkbook
   return hwb;
  }catch(ClassCastException ce){  //Instantiate the Workbook using XSSFWorkbook in case of class cast exception
   Workbook xwb=null;
   try{
   xwb=new XSSFWorkbook(checkFis);  
   checkFis.close();
   }catch(IOException e){    
   e.printStackTrace();
     }
  return xwb; }
  catch(Exception e){ //Instantiate the Workbook using XSSFWorkbook in case of Exception while reading file through HSSFWorkbook
  Workbook xwb=null;
  try{
   if(checkFis!=null)
  checkFis.close();
  checkFis=null;
  checkFis=new FileInputStream(fileName);
  xwb=new XSSFWorkbook(checkFis); 
  checkFis.close();
  }catch(Exception ie){
   
 return null;
  }
  
 return xwb;
 }
 }
 public void readExcel()
 {
  try
  {
   Workbook workbook = checkFileFormat(&amp;quot;EXCEL1.xlsx&amp;quot;);
  listOfTerms =new ArrayList&amp;lt;String&amp;gt;();
  Sheet sheet = workbook.getSheetAt(0);
  int rows  = sheet.getPhysicalNumberOfRows();
  System.out.println(&amp;quot;here &amp;quot;+rows+&amp;quot;   &amp;quot;+sheet.getSheetName());
  for (int r = 0; r &amp;lt; rows; r++)
  {
       Row row   = sheet.getRow(r);
       Cell cell =row.getCell((short)0);
       String cellValue = cell.getStringCellValue().trim();
       listOfTerms.add(cellValue);
    }
      System.out.println(listOfTerms);
      Workbook workbook1 = checkFileFormat(&amp;quot;EXCEL2.xls&amp;quot;);
      Sheet sheet1 = workbook1.getSheetAt(0);
      int rows1  = sheet1.getPhysicalNumberOfRows();
      System.out.println(&amp;quot;here &amp;quot;+rows1+&amp;quot;   &amp;quot;+sheet.getSheetName());
      for (int k = 0; k &amp;lt; rows1; k++)
      {
         Row row1   = sheet.getRow(k);
        Cell cell =row1.getCell((short)0);
         String cellValue2 = cell.getStringCellValue();
         al.add(cellValue2);
       
      }
        System.out.println(al);
        for(int i=0; i&amp;lt;al.size(); i++)
        {
        
          if(!listOfTerms.contains(al.get(i))) 
           {
             finallist.add(al.get(i));
           }
        }
        for(int i=0; i&amp;lt;listOfTerms.size(); i++)
        {
          if(!al.contains(listOfTerms.get(i))) 
          {
            finallist.add(listOfTerms.get(i));
          }
        }
        System.out.println(&amp;quot;Elements which are different: &amp;quot; +finallist);
        System.out.println(&amp;quot;&amp;quot;); 
 createSheet();
  }catch(Exception e)
  {
   e.getStackTrace();
   System.out.println(e.getMessage());
  }
 }
 private void createSheet() {
  XSSFWorkbook bookout = new XSSFWorkbook();
  try
  {
   int j=0;
   XSSFSheet sheet1= bookout.createSheet();
   bookout.setSheetName(0,&amp;quot;Document Handles&amp;quot;);
    for(int m=0;m&amp;lt;finallist.size();m++)
    {
     XSSFRow row=sheet1.createRow(j++);
     row.createCell((short) 0).setCellValue(finallist.get(m));
     
    } 
    FileOutputStream fout = new FileOutputStream(&amp;quot;OutputExcel.xlsx&amp;quot;);
    bookout.write(fout);
    fout.close();
  System.out.println(&amp;quot;file completed&amp;quot;); 
  }
  catch(Exception e)
  {
   System.out.println(e.getMessage());
  }
 }
  public static void main(String args[]){
  Excelcomparison e = new Excelcomparison();
  e.readExcel();
 }
}
&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/826907227308243192/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/11/excel-comparator-xls-or-xlsx-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/826907227308243192'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/826907227308243192'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/11/excel-comparator-xls-or-xlsx-in-java.html' title='Excel Comparator xls or xlsx in java '/><author><name>Raju Gupta</name><uri>http://www.blogger.com/profile/13350804494797609989</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-8555006757834366748</id><published>2012-11-01T03:35:00.000-07:00</published><updated>2012-11-01T03:35:00.099-07:00</updated><title type='text'>Code to Remove Certain Characters from a Java Input </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
Sometimes we can&#39;t
rename a file automatically when the Filename has &quot;/&quot;
inside them because of Windows limitations. This code might prove
handy in these situations.  
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;
//Code to Remove Certain Characters from a Java Input//

try {
    String Y = X;
    String regx = &quot;/&quot;;
    char[] ca = regx.toCharArray();
    for (char c : ca) {
     Y = Y.replace(&quot;&quot; + c, &quot;&quot;);
}
&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/8555006757834366748/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/11/code-to-remove-certain-characters-from.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/8555006757834366748'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/8555006757834366748'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/11/code-to-remove-certain-characters-from.html' title='Code to Remove Certain Characters from a Java Input '/><author><name>Raju Gupta</name><uri>http://www.blogger.com/profile/13350804494797609989</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-6182809466564231881</id><published>2012-11-01T00:00:00.000-07:00</published><updated>2012-11-01T00:00:05.427-07:00</updated><title type='text'>Code to Populate Dropdown from a DB</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
Using this Java
snippet the users can Populate Dropdown from a DB &amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;
//Code to Populate Dropdown from a DB//
//In JSP//
&amp;lt;div id=&amp;quot;bodydiv&amp;quot; align=&amp;quot;center&amp;quot; &amp;gt;
    &amp;lt;select name=&amp;quot; Name&amp;quot; onchange=&amp;quot;this.form.submit();&amp;quot;&amp;gt;
     &amp;lt;option name=&amp;quot;Router Name&amp;quot; value=&amp;quot;0&amp;quot;&amp;gt;--------select--------&amp;lt;/option&amp;gt;
     &amp;lt;%
     GetXRouter dao = new GetXRouter();
     ArrayList ReList = dao.retreiveRname();
     for (int i = 0; i &amp;lt; ReList.size(); i++) {
    %&amp;gt;
     &amp;lt;option name=&amp;quot;RName&amp;quot; value=&amp;quot;&amp;lt;%=ReList.get(i)%&amp;gt;&amp;quot;&amp;gt;&amp;lt;%=ReList.get(i)%&amp;gt;&amp;lt;/option&amp;gt;
     &amp;lt;%
     }
    %&amp;gt;
    &amp;lt;/select&amp;gt;

//IN Java Class File//
public class GetList {
 static Connection conn = null;
 static Statement st = null;
 static ResultSet rs = null;
 static DBConnection db;

 
 @SuppressWarnings({ &amp;quot;rawtypes&amp;quot;, &amp;quot;unchecked&amp;quot; })
 public ArrayList retreiveIname(String Rname) throws SQLException {
  Connection conn;
  DBConnection db = new DBConnection();
  conn = db.getConnection();
  Statement st;
  st = conn.createStatement();
  ResultSet rs = st.executeQuery(&amp;quot;select tt.Y_nm from Z.Z_X_Y_cfg tt where tt.active = &amp;#039;A&amp;#039; and tt.X_nm = &amp;#039;&amp;quot;+Rname+&amp;quot;&amp;#039; &amp;quot;);
  ArrayList IList = new ArrayList();
  while (rs.next()) {
   IList.add(rs.getString(1));
  }
  for (int i = 0; i &amp;lt; IList.size(); i++) {
   System.out.println(IList.get(i));
  }
  return IList;

 }

}
&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/6182809466564231881/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/11/code-to-populate-dropdown-from-db.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/6182809466564231881'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/6182809466564231881'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/11/code-to-populate-dropdown-from-db.html' title='Code to Populate Dropdown from a DB'/><author><name>Raju Gupta</name><uri>http://www.blogger.com/profile/13350804494797609989</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-8122483877321468458</id><published>2012-10-31T18:00:00.000-07:00</published><updated>2012-10-31T18:00:02.354-07:00</updated><title type='text'>To Convert the Given String to Propercase </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
If string is not
in proper case i.e. if a particular name&#39;s all letters are in upper
case or lower case, so this code will convert it to proper case.  
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;
public class ConvertToProperCase {
 
 public static String convertToProper(String strToConvert) throws java.io.IOException{
   
  //get lower case string
  java.io.StringReader str = new java.io.StringReader(strToConvert.toLowerCase());
   boolean precededBySpace = true;
   StringBuffer properCase = new StringBuffer();    
    while(true) {     
     //read string character by character
   int i = str.read();
     if (i == -1)  break;      
    char c = (char)i;
    if (c == &amp;#039; &amp;#039; || c == &amp;#039;&amp;quot;&amp;#039; || c == &amp;#039;(&amp;#039; || c == &amp;#039;.&amp;#039; || c == &amp;#039;/&amp;#039; || c == &amp;#039;\&amp;#039; || c == &amp;#039;,&amp;#039;) {
      properCase.append(c);
      precededBySpace = true;
      } else {
      if (precededBySpace) {
       //convert first character to proper
     properCase.append(Character.toUpperCase(c));
      } else { 
         // append rest character
      properCase.append(c); 
      }
      precededBySpace = false;
   }
   }
   
  return properCase.toString();    
   
 }
 //main code
 public static void main(String[] args) {
  
  try {
   //call convertToProper method
   System.out.println(convertToProper(&amp;quot;1jf94osl TEST TEST test test., MIKE, BRADD, blair&amp;quot;));
  } catch (java.io.IOException e) {
   System.out.println(&amp;quot;Exception:&amp;quot; + e);
  }
 }
 
 
}
&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/8122483877321468458/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/10/to-convert-given-string-to-propercase.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/8122483877321468458'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/8122483877321468458'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/10/to-convert-given-string-to-propercase.html' title='To Convert the Given String to Propercase '/><author><name>Raju Gupta</name><uri>http://www.blogger.com/profile/13350804494797609989</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-613625748767808272</id><published>2012-10-31T13:30:00.000-07:00</published><updated>2012-10-31T13:30:00.544-07:00</updated><title type='text'>Excel report generator based on the Input provided through an xml file</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
This tool can
generate one or more xls report based on the input provided inside a
xml file.  
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.hssf.util.Region;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
* This java class will read the xml file and generate the excel sheet based on the input parameter 
* provided to it.  
* 
* 
*/
public class ReadXmlFile {

 public static void main(String argv[]) {
  Connection con = null;
  try {
   String __runId = argv[0];
   String __runIdArr[] = __runId.split(&amp;quot;,&amp;quot;);
   if (__runIdArr.length &amp;gt; 0) {
    for (int i = 0; i &amp;lt; __runIdArr.length; i++) {
     String __filePath = &amp;quot;C:\excel\test1.xml&amp;quot;;
     File fXmlFile = new File(__filePath);
     DocumentBuilderFactory dbFactory = DocumentBuilderFactory
       .newInstance();
     DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
     Document doc = dBuilder.parse(fXmlFile);
     doc.getDocumentElement().normalize();
     System.out.println(&amp;quot;Root element :&amp;quot;
       + doc.getDocumentElement().getNodeName());
     NodeList nList = doc.getElementsByTagName(&amp;quot;data&amp;quot;);
     System.out.println(&amp;quot;-----------------------&amp;quot;);
     File f = new File(&amp;quot;C:\excel\data_import_&amp;quot;+__runIdArr[i]+&amp;quot;.xls&amp;quot;);
     if (f.createNewFile()) {
      System.out
        .println(&amp;quot;File has been created successfully&amp;quot;);
     }
     FileOutputStream fileOut = new FileOutputStream(f);
     HSSFWorkbook hwb = new HSSFWorkbook();
     for (int temp = 0; temp &amp;lt; nList.getLength(); temp++) {

      Node nNode = nList.item(temp);
      if (nNode.getNodeType() == Node.ELEMENT_NODE) {

       Element eElement = (Element) nNode;
       String __sheetName = getTagValue(&amp;quot;sheetname&amp;quot;,
         eElement);
       String __columns = getTagValue(&amp;quot;column&amp;quot;, eElement);
       String __query = getTagValue(&amp;quot;query&amp;quot;, eElement);
       // String __runId = getTagValue(&amp;quot;runid&amp;quot;, eElement);
       con = DBConnection.getConnection();
       if (createSheet(hwb, __sheetName, con, __query,
         __columns, __runIdArr[i])) {
        System.out
          .println(__sheetName
            + &amp;quot; sheet has been created successfully.&amp;quot;);
       }

      }
     }
     hwb.write(fileOut);
    }
   }
  } catch (Exception e) {
   e.printStackTrace();
  } finally {
   try {
    con.close();
   } catch (Exception e) {
    e.printStackTrace();
   }
  }

  System.out.println(&amp;quot;File has been generated successfully.&amp;quot;);
  System.exit(1);
 }

 /**
  * @depricated.
  * @param sTag String Object.
  * @param eElement Element object
  * @return returns string object.
  */
 private static String getTagValue(String sTag, Element eElement) {
  NodeList nlList = eElement.getElementsByTagName(sTag).item(0)
    .getChildNodes();
  Node nValue = (Node) nlList.item(0);
  return nValue.getNodeValue();
 }

 /**
  * This method will create the excel sheet based on queries has been written inside the xml file.
  * @param hwb Inatance of HSSFWorkbook
  * @param sheetName Instance of 
  * @param con String
  * @return returns boolean values.
  * @throws Exception
  */
 private static boolean createSheet(HSSFWorkbook hwb, String sheetName,
   Connection con, String query, String columns, String runId)
   throws Exception {
  boolean __sheetstatus = false;
  HSSFSheet sheet = hwb.createSheet(sheetName);
  HSSFRow rowhead = sheet.createRow((int) 1);
  int count = 0;
  HSSFFont font = hwb.createFont();
  font.setFontHeightInPoints((short) 10);
  font.setFontName(HSSFFont.FONT_ARIAL);
  HSSFCellStyle headerCell = setHeaderCell(hwb, font);
  String columnsArr[] = columns.split(&amp;quot;;&amp;quot;);
  for (int i = 0; i &amp;lt; columnsArr.length; i++) {
   setHeadColumnValue(sheet, rowhead, headerCell, columnsArr[i],
     count, 75);
   count++;
  }
  PreparedStatement psEventCount = null;
  ResultSet rsEventType = null;
  try {
   psEventCount = con.prepareStatement(query.replaceAll(&amp;quot;#&amp;quot;, runId));
   rsEventType = psEventCount.executeQuery();
   int rowCount = 2;
   HSSFCellStyle setStringCell = setStringCell(hwb);
   while (rsEventType.next()) {
    int __count = 0;
    HSSFRow currentRowhead = sheet.createRow((short) rowCount);
    for (int i = 0; i &amp;lt; columnsArr.length; i++) {
     String __equipmentselNumber = rsEventType
       .getString(columnsArr[i]);
     setHeadColumnValue(sheet, currentRowhead, setStringCell,
       __equipmentselNumber, __count, 75);
     __count++;
    }
    rowCount++;
   }
  } catch (Exception e) {
   e.printStackTrace();
   throw e;
  } finally {
   rsEventType.close();
   psEventCount.close();

  }
  __sheetstatus = true;
  return __sheetstatus;
 }

 /**
  * @This method will organize the xls cell values and style of that.
  * @param wb Instance of HSSFWorkbook
  * @param font Inatance of HSSFFont 
  * @return Instance of String.
  */
 private static HSSFCellStyle setHeaderCell(HSSFWorkbook wb, HSSFFont font) {
  HSSFCellStyle headerCell = wb.createCellStyle();
  font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  // headerCell.setAlignment(HSSFCellStyle.ALIGN_LEFT);
  headerCell.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
  headerCell.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
  headerCell.setFillForegroundColor(HSSFColor.LEMON_CHIFFON.index);
  headerCell.setFont(font);
  headerCell.setBorderBottom(HSSFCellStyle.BORDER_THIN);
  headerCell.setBorderLeft(HSSFCellStyle.BORDER_THIN);
  headerCell.setBorderTop(HSSFCellStyle.BORDER_THIN);
  headerCell.setBorderRight(HSSFCellStyle.BORDER_THIN);
  headerCell.setWrapText(true);
  return headerCell;
 }

 /**
  * @This method will organize the xls cell values and style of that.
  * @param wb Instance of HSSFWorkbook
  * @return returns String instance.
  */
 private static HSSFCellStyle setStringCell(HSSFWorkbook wb) {
  HSSFCellStyle stringCell = wb.createCellStyle();
  stringCell.setAlignment(HSSFCellStyle.ALIGN_LEFT);// &amp;quot;#,##0&amp;quot;
  stringCell.setBorderBottom(HSSFCellStyle.BORDER_THIN);
  stringCell.setBorderLeft(HSSFCellStyle.BORDER_THIN);
  stringCell.setBorderTop(HSSFCellStyle.BORDER_THIN);
  stringCell.setBorderRight(HSSFCellStyle.BORDER_THIN);
  stringCell.setLocked(false);
  stringCell.setWrapText(true);
  return stringCell;
 }

 /**
  * This method will set the head columns values.
  * @param sheet Instance of HSSFSheet 
  * @param row  Instance of HSSFRow 
  * @param style Instance of HSSFCellStyle
  * @param value Instance of String
  * @param colNo Instance of int.
  * @param width Instance of of int.
  */
 public static void setHeadColumnValue(HSSFSheet sheet, HSSFRow row,
   HSSFCellStyle style, String value, int colNo, int width) {
  HSSFCell cellt = row.createCell((short) colNo);
  sheet.addMergedRegion(new Region(0, (short) colNo, 0,
    (short) (colNo + 2)));
  cellt.setCellStyle(style);
  cellt.setCellValue(value);
  sheet.setColumnWidth((short) colNo, (short) (100 * width));
 }

}
import java.sql.*;
public class DBConnection {
public static Connection getConnection(){
 Connection con=null;
 try{
 Class.forName(&amp;quot;oracle.jdbc.driver.OracleDriver&amp;quot;);
 //QA
 //String url = &amp;quot;jdbc:oracle:thin:@etpcamq1.energy.ge.com:1521:etpcamq1&amp;quot;;
 //con = DriverManager.getConnection(url,&amp;quot;TBCAM&amp;quot;,&amp;quot;cam34etpq1&amp;quot;);

 String url =&amp;quot;&amp;quot;
 con = DriverManager.getConnection(url,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;);
 
 }catch(Exception e){
  e.printStackTrace();
 }
 return con;
 }
}
&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/613625748767808272/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/10/excel-report-generator-based-on-input.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/613625748767808272'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/613625748767808272'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/10/excel-report-generator-based-on-input.html' title='Excel report generator based on the Input provided through an xml file'/><author><name>Raju Gupta</name><uri>http://www.blogger.com/profile/13350804494797609989</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-6379127028804009871</id><published>2012-10-31T10:30:00.000-07:00</published><updated>2012-10-31T10:30:00.848-07:00</updated><title type='text'>Recursivey listing files and folders in java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
This code snippet
lists all the files and folders including the files in subdirectories
present in the given path at any level recursively and displays in a
tree structure  
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;
import java.io.File;

public class FileStructure {

  int tabCounter = 0;

  // obtain the list of files and folders in particular location
  public void listFilesAndFolders(String folder) {

    File file = new File(folder);

    if (!file.exists() || !file.isDirectory()) {

      System.out.println(&quot;Parameter is not a directory&quot;);
      System.exit(1);

    }

    File[] fileArray = file.listFiles();

    for (int i = 0; i &lt; fileArray.length; i++) {

      if (fileArray[i].isDirectory()) {

        System.out.println(getTabs() + &quot;- &quot; + fileArray[i].getName());
        tabCounter++;
        listFilesAndFolders(fileArray[i].getAbsolutePath());

      }
      else {

        System.out.println(getTabs() + fileArray[i].getName());
      }
    }
    tabCounter--;

  }
  // provide a tab space to represent tree structure
  private String getTabs() {

    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i &lt; tabCounter; i++)
      buffer.append(&quot;\t&quot;);

    return buffer.toString();
  }

  public static void main(String[] args) {

    FileStructure fileStructure = new FileStructure();
    fileStructure.listFilesAndFolders(&quot;C:\\temp&quot;);
  }
}

&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/6379127028804009871/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/10/recursivey-listing-files-and-folders-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/6379127028804009871'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/6379127028804009871'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/10/recursivey-listing-files-and-folders-in.html' title='Recursivey listing files and folders in java'/><author><name>Raju Gupta</name><uri>http://www.blogger.com/profile/13350804494797609989</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-164637028362540732</id><published>2012-10-31T03:09:00.000-07:00</published><updated>2012-10-31T03:09:00.337-07:00</updated><title type='text'>calculate the free disk space</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
To calculate
available disk space using Java &amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;
import java.io.IOException; 
  
import org.apache.commons.io.FileSystemUtils; 
  
public class DiskSpace { 
    public static void main(String[] args) { 
        try { 
  
            //calculate free disk space 
            double freeDiskSpace = FileSystemUtils.freeSpaceKb(&quot;C:&quot;);  
  
            //convert the number into gigabyte 
            double freeDiskSpaceGB = freeDiskSpace / 1024 / 1024; 
  
            System.out.println(&quot;Free Disk Space (GB):&quot; + freeDiskSpaceGB); 
        } catch (IOException e) { 
            e.printStackTrace(); 
        } 
    } 
}


&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/164637028362540732/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/10/calculate-free-disk-space.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/164637028362540732'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/164637028362540732'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/10/calculate-free-disk-space.html' title='calculate the free disk space'/><author><name>Raju Gupta</name><uri>http://www.blogger.com/profile/13350804494797609989</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-7044702725317218816</id><published>2012-10-30T15:30:00.000-07:00</published><updated>2012-10-30T15:30:01.774-07:00</updated><title type='text'>Dictionary Program to obtain meaning of words using java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;
It is a program to
obtain meaning of words which are redirected to google as parameters.
The results are fetched and printed using json object in java. &amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.nio.charset.Charset;

import javax.swing.JOptionPane;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class Dictonary
{
 public static void main(String args[]) throws Exception
 {
 String str = null;
 System.out.println(&amp;quot;running&amp;quot;);;
 str = JOptionPane.showInputDialog(&amp;quot;Enter the string&amp;quot;); 
 System.setProperty(&amp;quot;http.proxyHost&amp;quot;, &amp;quot;192.168.0.17&amp;quot;);
 System.setProperty(&amp;quot;http.proxyPort&amp;quot;, &amp;quot;8080&amp;quot;);
 JSONObject json = readJsonFromUrl(&amp;quot;http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&amp;amp;q=&amp;quot;+str+&amp;quot;&amp;amp;sl=en&amp;amp;tl=en&amp;amp;restrict=pr%2Cde&amp;amp;client=te&amp;quot;);
 JSONArray json1 = json.getJSONArray(&amp;quot;webDefinitions&amp;quot;);
 JSONArray json2 = ((JSONObject)json1.get(0)).getJSONArray(&amp;quot;entries&amp;quot;);
 System.out.println(&amp;quot;MEANINGS OF  &amp;quot;+str);
 for(int i=0;i&amp;lt;json2.length();i++)
 {
  JSONArray jobarray =((JSONObject)json2.get(i)).getJSONArray(&amp;quot;terms&amp;quot;);
  for(int j=0;j&amp;lt;jobarray.length();j++)
  {
   JSONObject job = jobarray.getJSONObject(j);
      String stri =  (String)job.get(&amp;quot;type&amp;quot;);
      if(stri.equals(&amp;quot;text&amp;quot;))
      {
       System.out.println(job.get(&amp;quot;text&amp;quot;));
      }
  }
  System.out.println(&amp;quot;&amp;quot;);
 }
 

 }
 public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException 
 {
     InputStream is = new URL(url).openStream();
     try {
      
       BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName(&amp;quot;UTF-8&amp;quot;)));
       String jsonText = readAll(rd);
     //  System.out.println(&amp;quot;char 1  &amp;quot;+jsonText.trim());
        jsonText=  jsonText.substring(jsonText.indexOf(&amp;#039;(&amp;#039;)+1,jsonText.lastIndexOf(&amp;#039;)&amp;#039;));
    //   System.out.println(&amp;quot;char 2  &amp;quot;+jsonText.trim());
       JSONObject json = new JSONObject(jsonText.trim());
       return json;
     } finally {
       is.close();
     }

}
 private static String readAll(Reader rd) throws IOException 
 {
     StringBuilder sb = new StringBuilder();
     int cp;
     while ((cp = rd.read()) != -1) {
       sb.append((char) cp);
     }
     return sb.toString();
   }

}
&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/7044702725317218816/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/10/dictionary-program-to-obtain-meaning-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/7044702725317218816'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/7044702725317218816'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/10/dictionary-program-to-obtain-meaning-of.html' title='Dictionary Program to obtain meaning of words using java'/><author><name>Raju Gupta</name><uri>http://www.blogger.com/profile/13350804494797609989</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553707859049859464.post-7164664832712894719</id><published>2012-10-30T14:30:00.000-07:00</published><updated>2012-10-30T14:30:02.034-07:00</updated><title type='text'>Efficient retrieval of Keys using given Values in the Map</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
This asset provides a reusable code which can be used to retrieve the Keys when Values are given in Java maps. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;
BidiMap bidimap = new DualHashBidiMap();

bidimap.putAll(theMap);  
  
String myKey= bidimap.inverseBidiMap().get(&quot;Mumbai&quot;).toString();

System.out.println(&quot;The Key is :&quot;  +  myKey) ;
&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://javaprogramming.language-tutorial.com/feeds/7164664832712894719/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/10/efficient-retrieval-of-keys-using-given.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/7164664832712894719'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553707859049859464/posts/default/7164664832712894719'/><link rel='alternate' type='text/html' href='http://javaprogramming.language-tutorial.com/2012/10/efficient-retrieval-of-keys-using-given.html' title='Efficient retrieval of Keys using given Values in the Map'/><author><name>Raju Gupta</name><uri>http://www.blogger.com/profile/13350804494797609989</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>