CMIS 241 DE Week 2 Read parts of chapter 2 this week. pages 70-75, 85-87, 90-92 Java has 8 primitive types: int and its 3 variants of byte, short and long for integers, float and double for real numbers, char for single characters, and boolean for true/false . char is occasionally useful (actually, almost anything you would need a char for you can do with a String [of one character]). Here's a demo program illustrating char if you're unfamiliar with char: http://sensei.ad.umuc.edu/dwills/cmis141/CharTest.java It is an applet, so it can be directly run from the web site: http://sensei.ad.umuc.edu/dwills/cmis141/CharTest.html boolean is occasionally useful. Here's a demo program illustrating boolean if you're unfamiliar with boolean: http://sensei.ad.umuc.edu/dwills/cmis141/BooleanTest.java It is an applet, so it can be directly run from the web site: http://sensei.ad.umuc.edu/dwills/cmis141/BooleanTest.html Here's a brief explanation of how to make an applet for those who might be interested (not required for this course): http://sensei.ad.umuc.edu/dwills/cmis102a/FirstApplet.java The other category of types is the reference types, which are classes, interfaces, and arrays. "Reference" because what is held in a variable of one of these is not the thing or data itself but a "reference" to the thing/object/data. For example, String s="freddy"; the variable s is a reference to a String object that holds the "freddy" data. "freddy" is not directly in s (unlike a primitive type variable like int x=123; x holds 123, x directly is 123). Another example: Date mydate; //a reference variable that can reference a Date object mydate = new Date(12,23,2000); mydate is now referencing the newly created Date object whose instance variables month, day, year are the values 12, 23 and 2000, respectively. This Date object exists somewhere in the memory of the Java Virtual Machine (JVM). mydate is actually some kind of memory address of that object (but we can't directly determine or manipulate that address) [Note that String objects can be created using special syntax without the new operator, as a convenience to us. The above example could also be done like this: String s = new String("freddy"); ] pages 85,86 discusses aliases (reference variables that are referencing the same object) and garbage (an object that no longer has any references to it, thus is inaccessible by the program and thus unusable "garbage") and if your program runs long enough and/or is using lots of memory the garbage collector will automatically run to find and recycle these inaccessible objects. ******************************************************************* The section about data levels on page 75 is a bit confusing but the library analogy is useful to get an idea of what the author means: Application/user level of data is how the data type (ADT) might be used in an application program (e.g. by a programmer using the String class to declare objects to represent names and then to call methods that manipulate that data). Logical/abstract level is what the set of data is (e.g. a String object is a sequence of characters) and what can be done to it (e.g. a String object can be input and output, it has a length, it can be copied to another String object, etc.). Implementation level is how the ADT is actually implemented (e.g. String has an underlying array or linked list). You as a programmer may be only a user of the ADT (such as when you use the built-in array and String types in Java, those ADTs have been implemented by the compiler writers; or when you use someone else's X class). You might be an implementer of an ADT when you create a class type, such as the Date class. You or other programmers could then be users of that class for various applications. ******************************************************************* pages 90-92 review arrays. Here are 2 demo programs illustrating arrays: http://sensei.ad.umuc.edu/dwills/cmis141/ArrayStuff.java http://sensei.ad.umuc.edu/dwills/cmis141/ArrayStuff2.java They are applets, so they can be directly run from the web site: http://sensei.ad.umuc.edu/dwills/cmis141/ArrayStuff.html http://sensei.ad.umuc.edu/dwills/cmis141/ArrayStuff2.html