Mapper

 The job of a Mapper is to split the record, get each word from record, and emit a value of one with a word. The output key and the output value is of type Text and IntWritable, as shown in the following code:

import org.apache.Hadoop.io.IntWritable;
import org.apache.Hadoop.io.LongWritable;
import org.apache.Hadoop.io.Text;
import org.apache.Hadoop.mapreduce.Mapper;

import java.io.IOException;

public class WordcountMapper extends Mapper<LongWritable, Text, Text, IntWritable> {

public static final IntWritable ONE = new IntWritable(1);

@Override
protected void map(LongWritable offset, Text line, Context context)
throws IOException, InterruptedException {
String[] result = line.toString().split(" ");

for (String word : result) {
context.write(new Text(word), ONE);
}
}
}