Welcome to DrJava. Working directory is /Users/smtuttle/humboldt/s15cs444/444lectures-and-labs/444week01-lab //======== // NOTE: I added additional comments to these in-class projections // after class, and also added some blank lines for readability. //======== // remember: all Java variables of a class type // are really references ("friendly" pointers) -- // they are null if they are not pointing // to a class instance; > String name; > name.length() java.lang.NullPointerException > name = "Eclipse"; > name "Eclipse" > name.length() 7 //======== // ANOTHER important Java thing-to-know: // when comparing class instances using ==, // what ARE you comparing? // ...whether two references reference the SAME object // in memory! (NOT whether those objects are // equivalent in value!! // thus: > String moniker = "Eclipse"; > name "Eclipse" > moniker "Eclipse" > name == moniker false // why is this false? // because == for references means, do the two references // reference the SAME object (the same location in // memory) // // if they DO reference the same location in memory, // == DOES return true; // // this causes name to reference the same object // that moniker references: > name = moniker; > name == moniker true > name "Eclipse" > moniker "Eclipse" // because of this, when it is reasonable to compare // instances of a class for equivalence -- for // equivalent content -- that class will have an // equals method > name = "DrJava"; > moniker = "DrJava"; > name == moniker false > name.equals(moniker) true > moniker.equals(name) true > name = "DrJava"; > name += " is useful"; > name "DrJava is useful" // bit more demonstration of Java arrays > String names[]; > names = new String[4]; > names { null, null, null, null } //======== // in Java, + can be a String concatenation operator // if at least one of its operands is of type // String // (the other, if an object, will automatically have its // toString method called to get that object's String // depiction; // if it is a primitive type, and you are using a new // enough version of Java, you'll get "auto-boxing" -- // the compiler will construct an instance of the // primitive type's wrapper class, and call toString // method of that...!) > for (int i=0; i<names.length; i++) { names[i] = "looky" + i; } > names { looky0, looky1, looky2, looky3 } //======== // Java does NOT allow some things C++ does -- // thou shalt NOT go outside of an array's bounds! // (0 to (length-1)) > names.length 4 > names[4] java.lang.ArrayIndexOutOfBoundsException //======== // but like C++, you can initialize an array using // { } (but only as part of its declare statement) > int stuff[] = {1, 2, 3}; > stuff { 1, 2, 3 } > stuff = {4, 5, 6}; Invalid top level statement > stuff { 1, 2, 3 } //======== // note, too, that if you have an array of objects, // an array reference is an object, // and can have methods called using it: > names { looky0, looky1, looky2, looky3 } > names[2] "looky2" > names[2].length() 6 // (created posted example application class ShowArg) //======== // (DrJava aside: compiling CLEARS Interactions window ... // although previous *actions* from the Interactions // window from the current "session" are still // available via Tools->History...) Welcome to DrJava. Working directory is /Users/smtuttle/humboldt/s15cs444/444lectures-and-labs/444week01-lab //======== // calling ShowArg with different command-line arguments and different // numbers of command-line arguments > java ShowArg moooooo moooooo > java ShowArg moo are you moo // note: // you can use run in DrJava's Interactions window, // but NOT in a "regular" bash shell...! > run ShowArg moo mooooo moo > java ShowArg WHERE IS MY ARGUMENT?!!!!! >