title: Not getting correct output when running standard "WordCount" program using Hadoop0.20.2
body: <p>I'm new to Hadoop.I have been trying to run the famous "WordCount" program -- which counts the total number of words
  in a list of files using Hadoop-0.20.2.
  I'm using single node cluster.</p>
  
  <p>Following is my program:</p>
  
  <pre><code>import java.io.File;
  import java.io.IOException;
  import java.util.*;
  
  import org.apache.hadoop.fs.Path;
  import org.apache.hadoop.conf.*;
  import org.apache.hadoop.io.*;
  import org.apache.hadoop.mapreduce.*;
  import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
  import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
  
  public class WordCount {
  
      public static class Map extends Mapper&lt;LongWritable, Text, Text, IntWritable&gt; {
          private final static IntWritable one = new IntWritable(1);
          private Text word = new Text();
  
          public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
              String line = value.toString();
              StringTokenizer tokenizer = new StringTokenizer(line);
              while (tokenizer.hasMoreTokens()) {
                  word.set(tokenizer.nextToken());
                  context.write(word, one);
              }
          }
      } 
  
      public static class Reduce extends Reducer&lt;Text, IntWritable, Text, IntWritable&gt; {
  
          public void reduce(Text key, Iterator&lt;IntWritable&gt; values, Context context) 
          throws IOException, InterruptedException {
              int sum = 0;
              while (values.hasNext()) {
                  ++sum ;
              }
              context.write(key, new IntWritable(sum));
          }
      }
  
      public static void main(String[] args) throws Exception {
          Configuration conf = new Configuration();
          Job job = new Job(conf, "wordcount");        
          FileInputFormat.addInputPath(job, new Path(args[0]));
          FileOutputFormat.setOutputPath(job, new Path(args[1]));        
          job.setJarByClass(WordCount.class);
          job.setInputFormatClass(TextInputFormat.class);
          job.setOutputFormatClass(TextOutputFormat.class);
          job.setMapperClass(Map.class);
          job.setMapOutputKeyClass(Text.class);
          job.setMapOutputValueClass(IntWritable.class);       
  
          job.setReducerClass(Reduce.class);          
          job.setOutputKeyClass(Text.class);
          job.setOutputValueClass(IntWritable.class);              
          job.setNumReduceTasks(5);        
          job.waitForCompletion(true);       
  
      }
  
  }
  </code></pre>
  
  <p>Suppose input file is A.txt which has following contents </p>
  
  <p>A B C D A B C D</p>
  
  <p>When I run this program using hadoop-0.20.2 (not showing commands for sake of clarity) ,the output that comes is 
  A 1
  A 1
  B 1
  B !
  C 1
  C 1
  D !
  D 1</p>
  
  <p>which is wrong.The actual output should be :
  A 2
  B 2
  C 2
  D 2</p>
  
  <p>This "WordCount" program is pretty standard program. I'm not sure what is wrong with this code.
  I have written the contents of all configuration files like mapred-site.xml , core-site.xml etc correctly.</p>
  
  <p>How can I fix this problem?</p>