import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.RandomAccessFile; import java.util.StringTokenizer; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.mapred.JobConf; // this example is testing for static valiable value // it will show the value of static valiable is related to Class, not object class testb { // object variable public void read() { System.out.println(test.sna); } } public class test { int na; static int sna; static String str; public test() { } public test(String st) { str = st; } public test(int a, int b, String st) { na = a; sna = b; str = st; } public void print(String str) { System.out.println(str); } @SuppressWarnings( { "static-access" }) public void strToken() throws IOException { test a = new test(1, 2, "a"); a.print("a.na = " + a.na); a.print("test.sna = " + test.sna); a.print("a.sna = " + a.sna); // warning about it's not a regular // accessing method test b = new test(3, 4, "a"); b.print("b.na = " + b.na); b.print("test.sna = " + test.sna); b.print("b.sna = " + b.sna); // warning about it's not a regular // accessing method a.print("a.sna = " + a.sna); // a.sna = test.sna -> b.sna String tmp[] = test.str.split(":"); String Column_Family = tmp[0] + ":"; a.print("column family = " + Column_Family); a.print("ori str = " + test.str); // test fileoutputstream FileOutputStream out = new FileOutputStream(new File( "/home/waue/mr-result.txt")); out.write("hello".getBytes()); out.close(); // test randomaccessfile RandomAccessFile raf = new RandomAccessFile("/home/waue/mr-result.txt", "rw"); raf.seek(raf.length()); // move pointer to end raf.write("\n go \t ahead".getBytes()); raf.close(); // test StringTokenizer StringTokenizer st = new StringTokenizer("this is a test"); while (st.hasMoreTokens()) { System.out.println(st.nextToken()); } } String parseFirstLine(String in, String ou) throws IOException { BufferedReader fi = new BufferedReader(new FileReader(new File(in))); BufferedWriter fw = new BufferedWriter(new FileWriter(new File(ou))); String first_line, data; first_line = fi.readLine(); do { data = fi.readLine(); if (data == null) { break; } else { fw.write(data + "\n"); } } while (true); fw.close(); return first_line; } boolean deleteFile(String str) throws IOException { File ttt = new File(str); if (ttt.exists()) { if (!ttt.delete()) { System.err.print("delete file error !"); } } else { System.out.println("file not exit!"); } return true; } void ttt() throws IOException { Path pi; JobConf conf = new JobConf(test.class); FileStatus[] fi = FileSystem.get(conf).listStatus( new Path("/user/waue/input/")); for (int i = 0; i < fi.length; i++) { pi = fi[i].getPath(); System.out.println(pi.getName()); } } public static void main(String[] args) throws IOException { // test a = new test(); // a.strToken(); // System.out.println(a.parseFirstLine("/home/waue/test.txt", // "/home/waue/out.tmp.txt")); // ttt(); animal a = new animal(); bird b = new bird(); dog d = new dog(b); animal aaa = new bird(); // dog ddd = new animal(); -> error animal aa = (animal) b; System.out.println(aa.hand); System.out.println(aa.mind); // bird bb = (bird) a; -> error // d.setbird(aa); -> error // System.out.println(aa.feather); -> error // Fu Fu ak; ak = new Fu(); ak.getFu(); Fu in = ak; // in.setFu("ss"); -> error in.getFu(); } } class Fu { T go; void setFu(T go){ this.go = go; } T getFu(){ return go; } } class animal{ String head = "head"; String feet = "feet"; String body = "body"; String hand = "head"; String mind = "mind"; int id = 1234567; } class bird extends animal{ String feather = "feather"; bird(){ hand = "wing"; id = 1234568; System.out.println(head + hand + body + feet + "id="+id); System.out.println("super = " + super.hand +"this = " + this.hand); } } class dog extends animal{ dog(animal a){ System.out.println(a.head + hand + body + feet + "id="+id); } void setbird(bird b){ System.out.println(b.head + hand + body + feet + "id="+id); } }