Guest User

Test.java

a guest
Dec 2nd, 2010
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 4.08 KB | None | 0 0
  1.  
  2. public class Test{
  3.  
  4.      private static boolean b_s;
  5.      private static byte bt_s;
  6.      private static short s_s;
  7.      private static int i_s = 555;
  8.      private static long l_s;
  9.      private static float f_s;
  10.      private static double d_s;
  11.      private static char c_s;
  12.      private static Object o_s;
  13.  
  14.      private boolean b;
  15.      private byte bt;
  16.      private short s;
  17.      private int i;
  18.      private long l;
  19.      private float f;
  20.      private double d;
  21.      private char c;
  22.      private Object o;
  23.  
  24.      public void resetVals(){
  25.           b = true;
  26.           bt = 5;
  27.           s = 6;
  28.           i = 7;
  29.           l = 8L;
  30.           f = 9f;
  31.           d = 10d;
  32.           c = 'z';
  33.      }
  34.  
  35.     public void init()
  36.     {
  37.           System.out.println("Starting Test.init()");
  38.           System.out.println("i_s: "+i_s);
  39.           b = true;
  40.           bt = 5;
  41.           s = 6;
  42.           i = 7;
  43.           l = 8L;
  44.           f = 9f;
  45.           d = 10d;
  46.           c = 'z';
  47.           o = new java.util.ArrayList(i);
  48.           System.out.println("b: "+b+", bt: "+bt+", s: "+s+", i: "+i+", l: "+l+", f: "+f+", d: "+d+", c: "+c+", o: "+o);
  49.  
  50.           b_s = true;
  51.           bt_s = 5;
  52.           s_s = 6;
  53.           i_s = 7;
  54.           l_s = 8L;
  55.           f_s = 9f;
  56.           d_s = 10d;
  57.           c_s = 'z';
  58.           o_s = new java.util.ArrayList(i_s);
  59.           System.out.println("b_s: "+b_s+", bt_s: "+bt_s+", s_s: "+s_s+", i_s: "+i_s+", l_s: "+l_s+", f_s: "+f_s+", d_s: "+d_s+", c_s: "+c_s+", o_s: "+o_s);
  60.  
  61.           byte[] bytes = new byte[11];
  62.           bytes[4] = 12;
  63.           System.out.println("bytes[4]: "+bytes[4]);
  64.           System.out.println("bytes.length: "+bytes.length);
  65.  
  66.           String[] fill_data = new String[]{"bob", "tom", "jim", "tim"};
  67.           System.out.println("fill_data: "+fill_data);
  68.           for(String data : fill_data)
  69.                System.out.println("data: "+data);
  70.  
  71.           i = 122;
  72.           bt = (byte)i;
  73.           s = (short)i;
  74.           l = (long)i;
  75.           f = (float)i;
  76.           d = (double)i;
  77.           c = (char)i;
  78.  
  79.           System.out.println("b: "+b+", bt: "+bt+", s: "+s+", i: "+i+", l: "+l+", f: "+f+", d: "+d+", c: "+c+", o: "+o);
  80.  
  81.           resetVals();
  82.           i = (int)l;
  83.           System.out.println("i: "+i);
  84.           i = (int)f;
  85.           System.out.println("i: "+i);
  86.           i = (int)d;
  87.           System.out.println("i: "+i);
  88.  
  89.           resetVals();
  90.           l = (long)f;
  91.           System.out.println("l: "+l);
  92.           l = (long)d;
  93.           System.out.println("l: "+l);
  94.  
  95.           resetVals();
  96.           f = (float)d;
  97.           System.out.println("f: "+f);
  98.  
  99.           if(!(o instanceof java.lang.String))
  100.                System.out.println("o is not an instance of String!");
  101.  
  102.           if(o instanceof java.util.ArrayList)
  103.                System.out.println("o is an instance of java.util.ArrayList!");
  104.  
  105.           i = 104;
  106.           switch(i){
  107.                case 1: System.out.println("case "+i); break;
  108.                case 5: System.out.println("case "+i); break;
  109.                case 10: System.out.println("case "+i); break;
  110.                case 15: System.out.println("case "+i); break;
  111.                default: System.out.println("default case");
  112.           }
  113.  
  114.           try{
  115.                System.out.println("this try statement is successful");
  116.           }catch(Exception e){
  117.                System.out.println("this exception should NEVER happen");
  118.                e.printStackTrace();
  119.           }
  120.  
  121.           try{
  122.                System.out.println("this try statement is successful, until the next statement");
  123.                i = 10 / 0;
  124.                System.out.println("this statement should NEVER be executed");
  125.           }catch(Exception e){
  126.                System.out.println("this exception should always happen:");
  127.                e.printStackTrace();
  128.           }
  129.          
  130.  
  131.           System.out.println("Finishing Test.init()");
  132.     }
  133.  
  134.     public static void main(String[] args)
  135.     {
  136.         new Test().init();
  137.           System.out.println("Finishing Main method");
  138.     }
  139.  
  140. }
Advertisement
Add Comment
Please, Sign In to add comment