// Notice that we can't just have a random main() function hanging out // in the middle of nowhere. Every method must be attached to a // class. We get the effect of main() by defining a main method in a // given class. public class Examples { public static void main(String[] args) { // Demonstrates use of wrapper classes. char c = 'h'; Character objectC = new Character(c); char d = objectC.charValue(); String s = "hi"; // These two lines produce equivalent-valued String t = new String("hi"); // String objects. if("hi".equals(t)) // BTW, by convention the message System.out.println("eq0"); // .equals() means value comparison. if(t == "hi") // == is "object identity" testing. System.out.println("eq1"); // t and "hi" have the same value, but else // are different objects, so the identity System.out.println("not1"); // test will return false. // A demonstration of String concatenation, and implicit // toString() calls. Integer anInteger = new Integer(7); System.out.println("i = " + anInteger); // Above line and below line mean the same thing: System.out.println("i = " + anInteger.toString()); // And Java creates implicit wrapper class instances for these... System.out.println("Other numbers are " + 5 + " and " + 2.1); System.out.println(2 + 3 + " = 1 + 4."); // An array of primitives: initialized to 0 int[] intArr = new int[10]; // An array of object references: initialized to null Integer[] fooArr = new Integer[10]; for (int i = 0; i < fooArr.length; i++) fooArr[i] = new Integer(i); } }