// SimpleTest.cs using java.lang; class SimpleTest : Runnable { private int which; [System.NonSerializedAttribute()] internal int x; internal volatile int y; internal const int ONE = 1; internal readonly string JOHN = "\aJohn"; internal const bool b = true; internal const char c = 'h'; internal const short s = -234; internal const int i = 100; internal const long l = 123456789; internal const float f = 1.23456792E8F; internal const double d = 1.2345678912345679E8; internal readonly int pData = 1000; internal static int age = 0; static SimpleTest() { int l = 100; age = 32 + l; } public static void Main(string[] argv) { SimpleTest st = new SimpleTest(1000); st.run(); Thread t = new Thread(st); t.setName("Second Thread"); t.start(); } public virtual void run() { java.lang.System.@out.println(Thread.currentThread().getName()); java.lang.System.@out.println(new SimpleTest(1).JOHN); string s = "\u0003Hello World"; java.lang.System.@out.println(s); test(); new SimpleTest(1000).testDupX(); testArrayInitializer(); testForLoop(); testWhileLoop(5); testTypeCast(s); testLabelledStatement(6); SimpleTest st = new SimpleTest(1000); java.lang.System.@out.println(st.which); java.lang.System.@out.println(st.increment(100)); ArrayTest(); testSwitch(15); testSwitch_0(15); testSwitch_0(-150); testSwitch_1(10); testSwitch_1(1); testSwitch_2(6); testSwitch_2(1); testSwitch_3(6); testSwitch_3(1); testException(true); testException(false); testFinally(true); testFinally(true); testFinally(false); testFinally(false); testFinally(true); testFinally(false); testFinally(false); testFinally(true); testFinally(false); testFinally(false); testFinally(false); st = new SimpleTest(100); st.testSynchronizedMethod(); try { { st.testLock(false); st.testLock(true); } } catch (SimpleException e) { { java.lang.System.@out.println(e.msg); } } st = new ChildClass(1000); try { { st.testLock(false); st.testLock(true); st.testLock(true); } } catch (SimpleException e) { { java.lang.System.@out.println(e.msg); } } java.lang.System.@out.println(testStringBuffer(1234)); } internal static void testArrayInitializer() { int[] a = new int[]{1, 2, 3, 4, 5}; for (int i = 0; i < a.Length; i++) { java.lang.System.@out.println(a[i]); } } internal int count = 100; internal virtual SimpleTest getThis() { return this; } internal virtual void testDupX() { java.lang.System.@out.println("You should see 100 here : " + count++); java.lang.System.@out.println("You should see 101 here : " + count); count = 100; int val = count += 10; java.lang.System.@out.println("You should see 110 here : " + val); } internal static void testTypeCast(object o) { java.lang.System.@out.println("testTypeCast"); if (o is string) { java.lang.System.@out.println("Yes, o is an instance of java.lang.String"); } bool b = o is java.lang.System; if (!b) { java.lang.System.@out.println("No, o is not an instance of java.lang.System"); } java.lang.System.@out.println((string)o); } internal SimpleTest(int w) { which = w; } protected internal virtual int increment(int incr) { which += incr; return which; } internal static void test() { int i = 100; if (i < 100) { i++; } else { i--; } bool b = false; bool c = !b; java.lang.System.@out.println(i); } internal static void ArrayTest() { java.lang.System.@out.println("ArrayTest"); int[] aaa = new int[]{1, 2, 3, 4, 5}; int[][] ddd = new int[][]{ new int[]{1, 2, 3, 4, 5}, new int[]{6, 7}}; java.lang.System.@out.println(aaa[4]); java.lang.System.@out.println(ddd[0][3]); java.lang.System.@out.println("ddd[0].length = " + ddd[0].Length); java.lang.System.@out.println("ddd[1].length = " + ddd[1].Length); int[] intArray = new int[10]; string[] strArray = new string[10]; int i = 0; int j = 0; int k = 0; int m = 0; for (i = 0; i < intArray.Length; i++) { intArray[i] = i; strArray[i] = "Christina Zhang"; } java.lang.System.@out.println(intArray[3]); java.lang.System.@out.println(strArray[3]); int[][] int2DArray = (int[][])System.Activator.CreateInstance(typeof(int[][]), new object[]{10, 20}); for (j = 0; j < 10; j++) for (k = 0; k < 10; k++) int2DArray[j][k] = j + k; int[] a = int2DArray[3]; for (m = 0; m < 5; m++) java.lang.System.@out.println(a[m]); int[][][] int3DArray = (int[][][])System.Activator.CreateInstance(typeof(int[][][]), new object[]{10, 20, 30}); int3DArray[9][19][29] = 100; int[][] anotherArray = (int[][])System.Activator.CreateInstance(typeof(int[][]), new object[]{i + k, 10 + 20 + i + 20 + m}); int[][][][] int4DArray = (int[][][][])System.Activator.CreateInstance(typeof(int[][][][]), new object[]{10, 20, 30, 40}); int4DArray[9][19][29][39] = 1000; } internal static void testForLoop() { java.lang.System.@out.println("testForLoop"); int j = 0; for (int i = 0; i < 1000L; i++) { j++; } java.lang.System.@out.println(j); } internal static void testWhileLoop(int limit) { java.lang.System.@out.println("testWhileLoop"); int i = 0; while (i < limit) { java.lang.System.@out.println(i); i++; } } internal static void testLabelledStatement(long l) { java.lang.System.@out.println("testLabelledStatement"); l++; int i = 0; int j = 0; TestLabel: for (i = 0; i < 5; i++) { while (j < l) { if (j == 4) goto TestLabel_exit; j++; } l++; } TestLabel_exit:; java.lang.System.@out.println((int)l); } internal static void testSwitch(int i) { java.lang.System.@out.println("testSwitch"); string s = null; for (int j = 1; j <= i; j++) { switch (j) { case 1: s = "Jan"; break; case 2: s = "Feb"; break; case 3: s = "Mar"; break; case 4: s = "Apr"; break; case 5: s = "May"; break; case 6: s = "Jun"; break; case 7: s = "Jul"; break; case 8: s = "Aug"; break; case 12: s = "Dec"; break; default: s = "Default"; break; } java.lang.System.@out.println(s); } } internal static void testSwitch_0(int i) { java.lang.System.@out.println("testSwitch_0"); string s = null; switch (i) { default: s = "Default"; break; case 1: s = "Jan"; break; case 200: s = "Feb"; goto case 3; case 3: s = "Mar"; break; case 4: s = "Apr"; break; case 5: s = "May"; break; case 6: s = "Jun"; break; case 7: s = "Jul"; break; case 8: s = "Aug"; break; case 1200: s = "Dec"; break; } java.lang.System.@out.println(s); } internal static void testSwitch_1(int i) { java.lang.System.@out.println("testSwitch_1"); string s = null; switch (i) { case 1000: s = "Jan 1000"; break; case 2000: s = "Feb 2000"; break; case 7000: s = "Jul 7000"; break; default: s = "Default"; break; case 8: s = "Aug"; break; case 12: s = "Dec"; break; } java.lang.System.@out.println(s); switch (i) { case 1000: s = "Jan 1000"; break; case 2000: s = "Feb 2000"; break; case 7000: s = "Jul 7000"; break; default: s = "Default"; break; case 8: s = "Aug"; break; case 12: s = "Dec"; break; } java.lang.System.@out.println(s); } internal static void testSwitch_2(int i) { java.lang.System.@out.println("testSwitch_2"); string s = "null"; switch (i) { case 1: s = "Jan"; break; case 2: s = "Feb"; break; case 3: s = "Mar"; break; case 4: s = "Apr"; break; case 5: s = "May"; break; case 6: s = "Jun"; break; case 7: s = "Jul"; break; case 8: s = "Aug"; break; case 12: s = "Dec"; break; } java.lang.System.@out.println(s); } internal static void testSwitch_3(int i) { java.lang.System.@out.println("testSwitch_3"); string s = "null"; for (int j = 1; j <= i; j++) { switch (j) { case 1000: s = "Jan 1000"; break; case 2000: s = "Feb 2000"; break; case 7000: s = "Jul 7000"; break; case 8: s = "Aug"; break; case 12: s = "Dec"; break; } java.lang.System.@out.println(s); } } internal static void testException(bool throwit) { java.lang.System.@out.println("testException()"); try { { throwException(throwit); } } catch (SimpleException se) { { java.lang.System.@out.println(se.msg); } } } internal static void testFinally(bool throwit) { java.lang.System.@out.println("testFinally()"); try { { throwException(throwit); } } catch (SimpleException se) { { java.lang.System.@out.println(se.msg); } } finally { { java.lang.System.@out.println("Finally clause called"); } } } private static void throwException(bool throwit) /* throws SimpleException*/ { if (throwit) throw new SimpleException(); } [System.Runtime.CompilerServices.MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.Synchronized)] internal virtual void testSynchronizedMethod() { java.lang.System.@out.println("testSynchronizedMethod called"); int count = 0; count++; } internal virtual void testLock(bool throwit) /* throws SimpleException*/ { java.lang.System.@out.println("SimpleTest.testLock() called"); int count = 0; lock (this) { count++; throwException(throwit); } count++; java.lang.System.@out.println("SimpleTest.testLock() finished"); } internal static string testStringBuffer(int data) { return "String concatenation: " + data + "Christina " + "Zhang"; } public /*native*/ virtual void testNative(object o, int i, long[] l) /* throws SimpleException, Exception, ClassNotFoundException*/ { throw new UnsatisfiedLinkError("JNI not supported"); } }