KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > samples > Foo


1 package samples;
2
3
4 public class Foo {
5     public static String JavaDoc secretField;
6     public static int iValue = 1;
7
8     public static void main(String JavaDoc[] args) throws Throwable JavaDoc {
9         System.out.println("Foo.main(...)");
10         System.out.println(foo1());
11
12         System.out.println(foo2(123l));
13         foo3("ddd");
14
15         Bar.static_bar();
16         Bar b = new Bar();
17         b.bar1();
18         System.out.println(b.bar2());
19         System.out.println(b.bar_field);
20
21         long l1 = System.currentTimeMillis();
22         foo4();
23         foo4();
24         foo4();
25         long l2 = System.currentTimeMillis();
26         System.out.println("foo4s executed in total of " + (l2-l1) + " ms");
27     }
28
29     public static double foo1() {
30         secretField = "secretFieldSetByFoo" + iValue;
31         return 0.1d;
32     }
33     public static long foo2(long l1) {
34         System.out.println("foo2: " + secretField + ", " + l1);
35         return -1;
36     }
37     public static void foo3(String JavaDoc s) throws Throwable JavaDoc {
38         System.out.println(s);
39     }
40
41     public static void foo4() {
42 // int l1 = (int)System.currentTimeMillis();
43
for (int i = 0; i < 1000000; i++) {
44          //Object o = secretField;
45
}
46
47      int l2 = (int)System.currentTimeMillis();
48 // System.out.println("Foo4(...) executed in " + (l2-l1) + " ms");
49
//return l2-l1;
50

51 // int i = (int)(l2-l1);
52
return ;
53     }
54
55 // public static void foo5(Bar b) {
56
// int l1 = (int)System.currentTimeMillis();
57
// for (int i = 0; i < 1000000; i++) {
58
// Object o = b.bar_field;
59
// }
60

61 // int l2 = (int)System.currentTimeMillis();
62
// System.out.println("Foo5(...) executed in " + (l2-l1) + " ms");
63
// //return l2-l1;
64

65 // int i = (int)(l2-l1);
66
// return ;
67
// }
68
}
69
Popular Tags