0% found this document useful (0 votes)
5 views1 page

Word Count Program

The document presents a Java program for a Word Count application using Hadoop's MapReduce framework. It defines a Mapper class that processes input text to count word occurrences and a Reducer class that aggregates these counts. The main method sets up the job configuration, specifies input and output formats, and executes the MapReduce job.

Uploaded by

mani
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Word Count Program

The document presents a Java program for a Word Count application using Hadoop's MapReduce framework. It defines a Mapper class that processes input text to count word occurrences and a Reducer class that aggregates these counts. The main method sets up the job configuration, specifies input and output formats, and executes the MapReduce job.

Uploaded by

mani
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Word Count Program:

package [Link];
import [Link];
import [Link].*;
import [Link];
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link];
publicclass WordCount {
publicstaticclass Map extends Mapper<LongWritable, Text, Text,
IntWritable>{ privatefinalstatic IntWritable one =new IntWritable(1);
private Text word =new Text();
publicvoid map(LongWritable key, Text value, Context context)throws IOException,
InterruptedException {
String line =[Link]();
StringTokenizer tokenizer =newStringTokenizer(line);
while([Link]()){ [Link]([Link]());
[Link](word, one);
}
}
}
publicstaticclass Reduce extends Reducer<Text, IntWritable, Text, IntWritable>{
publicvoid reduce(Text key, Iterator<IntWritable> values, Context context) throws
IOException, InterruptedException {
int sum =0; while([Link]()){ sum+= [Link]().get();
}
[Link](key,new IntWritable(sum));
}
}
publicstaticvoid main(String[] args)throws Exception
{
Configuration conf=newConfiguration();
Job job =newJob(conf,"wordcount");
[Link]([Link]); [Link]([Link]);
[Link]([Link]); [Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link](job,new Path(args[0]));
[Link](job,new Path(args[1]));
[Link](true);
}
}

You might also like