concept Java in category hadoop

This is an excerpt from Manning's book Hadoop in Practice, Second Edition.
1 To benefit from this book, you should have some practical experience with Hadoop and understand the basic concepts of MapReduce and HDFS (covered in Manning’s Hadoop in Action by Chuck Lam, 2010). Further, you should have an intermediate-level knowledge of Java—Effective Java, 2nd Edition by Joshua Bloch (Addison-Wesley, 2008) is an excellent resource on this topic.
Listing 3.1. Extracting content with Java’s STAX parser
public static class Map extends Mapper<LongWritable, Text, Text, Text> { @Override protected void map(LongWritable key, Text value, Mapper.Context context) throws IOException, InterruptedException { String document = value.toString(); System.out.println("'" + document + "'"); try { XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(document.getBytes())); String propertyName = "; String propertyValue = "; String currentElement = "; while (reader.hasNext()) { int code = reader.next(); switch (code) { case START_ELEMENT: currentElement = reader.getLocalName(); break; case CHARACTERS: if (currentElement.equalsIgnoreCase("name")) { propertyName += reader.getText(); } else if (currentElement.equalsIgnoreCase("value")) { propertyValue += reader.getText(); } break; } } reader.close(); context.write(propertyName.trim(), propertyValue.trim()); } catch (Exception e) { log.error("Error processing '" + document + "'", e); } } }
This chapter starts by highlighting key data-movement properties, so that as you go through the rest of this chapter you can evaluate the fit of the various tools. It goes on to look at low-level and high-level tools that can be used to move your data. We’ll start with some simple techniques, such as using the command line and Java for ingress,[1] but we’ll quickly move on to more advanced techniques like using NFS and DistCp.
The CLI is handy for quickly running commands and for scripting. However, it incurs the overhead of forking a separate process for each command, which is overhead that you’ll probably want to avoid, especially if you’re interfacing with HDFS in a programming language. This technique covers working with HDFS in languages other than Java (which is covered in a subsequent section).

This is an excerpt from Manning's book Hadoop in Action.
Running Hadoop requires Java (version 1.6 or higher). Mac users should get it from Apple. You can download the latest JDK for other operating systems from Sun at http://java.sun.com/javase/downloads/index.jsp. Install it and remember the root of the Java installation, which we’ll need later.
Most Java programmers instinctively default to the int type (or Integer or IntWritable) to represent integer values. In Java the int type can hold any integer between 231-1 and -231, or between 2,147,483,647 and -2,147,483,648. This is adequate for most applications. Rarely do programmers put too much thought into it. When you’re processing Hadoop-scale data, it’s not unusual for some counter variables to need a bigger range. You won’t see this requirement under your development data set, which by design is small. It may not even matter to your current production data, but as your business operation grows, your data set will get bigger. It may get to a point where some variables will outgrow the int range and cause arithmetic errors. Take the canonical word counting example. When processing millions of documents, you won’t have any word count that goes beyond 2 billion,[2] and an int is adequate. But as you grow to process tens of millions or hundreds of millions of documents, counting frequent words like the can cross the limit of an int type. Rather than wait for this kind of bug to creep up on you in production, which is much harder to debug and costlier to fix, now is the time you should go through your code and carefully consider whether your numeric variables should be long or LongWritable to handle future scale.[3]