想成为大数据工程师的第一天

it2022-05-05  157

JAVA部分:

final 关键字 

1、修饰类 不能被继承;

2、修饰方法,被final修饰的方法不能被重写;

3、修饰成员变量(必须初始值);

直接赋值;在构造方法里赋值;基本类型不能改;引用类型 地址不能改变,引用所指向的对象可以改。

StringTokenizer 是一个用来分隔String的应用类

StringTokenizer(String str, String delim, boolean returnDelims)

待处理字符串,分隔符,是否返回分隔符号

方法介绍

hasMoreElements()、hasMoreTokens()  返回是否有分隔符

nextToken()  nextElement() 返回当前位置到下一个分隔符的字符串(不同在于第二个方法可能返回Object)

countTokens() 可以用来计算分隔符的数量

大数据相关代码:

public class WordCount{     public static class TokenizerMapper     extends Mapper<Object, Text, Text, IntWritable>{ private final static IntWritable one = new IntWritable(1);     private Text word = new Text();     public void map(Obiect key, Text value, Context content) throws IOException, InterruptedException{     StringTokenizer itr = new StringTokenizer(value.toString()); while (itr.hasMoreTokens()) {   word.set(itr.nextToken());   content.write(word,one);           }     }     }     public static class IntSumReducer extends Reducer<Text, IntWriteable, Text, IntWriteable>{ private IntWriteable result = new InterWriteable();     public void reduce(Text key, Iterable<IntWriteable> values, Content content)  throws IOException, InterruptedException{   int sum = 0;   for(Interwriteable val : values){     sum += val.get() } result.set(sum); content.write(key, result);

public static void main (String[] args) throw IOException{     Configuration conf = new Configuration();        //加载Hadoop的配置文件     String[] otherArgs = new GenericOptionParser(conf, args).getRemainingArgs(); if(otherArgs != 2) {     System.err.println("it's error");     System.exit(2); } //配置作业名 Job job = new Job(conf,"word count"); //配置作业各个类     job.setJarByClass(WirdCount.class);     job.setMapperClass(Tokenizer.class);     job.setReducerClass(IntSumWriteable.class);     job.setCombineClass(IntSumWriteable.class);     job.setOutputKeyClass(Text.class);     job.setOutputValueClass(IntWriteable.class);     FileInputFormat.addInputPath(job, new Path(OtherArgs[0]));     FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));     System.exit(job.waitForComplete(true)? 0:1)

这是一个 word count的小代码 原谅我没有运行。。。 环境暂时没搭建好,现在就是写一写熟悉一下,大学学过JAVA基础的基础,后来就忘了。。。尴尬,加油,每天进步一点点。

                                                                                                                            ---生来就是为了赴死,所以,不留遗憾。

                                                                                                                            ---Break


最新回复(0)