21 Days:
Wk1
. Wk1Ref
. Applts
. Swing
. Grph
. D13-14
. D15-21
. D22-28
cc12: Miscl . SQL . EJB . Vocab . (NotesHelp) . J2EE . Web misl: Getting Started . 21 Days(src) . Dictionary(foldoc) . Unicode . Tables . Print . html misl: Doc Swing (J.H.University) . Drag and Drop Recipe |
******************************************************************************** B19 - Teach Yourself Java 2 in 21 Days. 2nd ed. Lemay and Cadenhead. © 2001. ********************************************************************************
-----Jan/2002 B19: Starting with pg.9. About "21st Century Java" "Day 1".
-----Jan/26/2002 SAT B19: Starting with pg.51. Near end of "Day 2". - AN IMPORTANT KEY IDEA: Designing an effective class hierarchy involves a lot of planning and revision. As you attempt to put attributes and behavior into a hierarchy, your'e likely to find reasons to move some classes to different spots in the hierarchy. The goal is to reduce the number of repetitive features that are needed. (pg.51) - [ ]Q: Is Java a "recursive" language? That is, can a method call itself? - Single and Multiple Inheritance; Interfaces; Packages. (JPG) (pg.53,54) - default, classes have access to only classes in java.lang(basic language features) (pg.54)
-----Jan/31/2002 THU B19: Starting with pg.62.bottom. In "Day 3". - A variable can be declared anywhere in a java block, as long as it is before it is used. - Local variables must be assigned a value before being used. - Instance and class variables are given a default value when declared... Numberics: 0, Characters: '/0', Boolean: false, Objects: null. - A variable name must start with '_', '$', or a letter. - Java uses the Unicode character set. This offers the standard character set plus thousands of other characters. - Java variables names are case sensitive. - Kinds of variable types... a primitive type, name of a class or interface, or an array. (See Day 5) - Eight primitive types. They store integers, floating-point numbers, characters. and Boolean values. These types are more efficient since they are built in and are not objects.
-----Feb/02/2002 SAT B19: Starting with pg.65.top. In "Day 3". - "One of the most important ways to improve the readability of your program is to use comments." (pg.67) - Java has comments like C, plus comments with "/**" and "*/". They are considered official documentation. Javadoc can be used to create this document. (pg.68) - java.sun.com/j2se/1.3/docs for javadoc created official documentation on Java's class lib. This documentation is also downloadable from java.sun.com/j2se/1.3/docs.html
-----Feb/05/2002 TUE B19: Starting with pg.68.mid. In "Day 3". LITERALS - A literal integer can be made "long" two ways, consists of enough digits, or appending a "L" to the number. - Prepend a "0" (zero) in front of an integer for an octal literal. Base 8. - Prepend "0x" in front of and integer for a hexadecimal literal. Base 16. - A literal containing a "." is a "double". - A literal containing a "." and appended with a "F" is a "float". - Exponential samples of literals: double x = 12e22, y = 19E-95;
-----Feb/07/2002 THU pg.69.bot. In "Day 3". - Boolean literals - are these two: true and false. You can not use 1, 0. - Character literals - examples 'a' 'b'. 11 escape codes. The Unicode set has the Ascii set plus thousands more. - String Literals - A string is an object in java, not an array like in C. The string object has methods to operate on strings. Strings can contain Unicode. More unicode info at the Unicode Consortium Web Site Example: String myString = "this is a string literal";
-----Feb/09/2002 SAT pg.72.top. In "Day 3". - Division assigned to an integer truncates the decimal portion. - Many operations involving integers often produce integer results. (pg.73) - You can combine assignments as follows: x = y = z = a * (b + 7); - Be careful when using Assignment Operators. Example: int x = 3, y = 3, z = 20; x = x / z + 5; // 5 ... (x / z) + 5 // decimal portion truncated y /= z + 5; // 0 ... y / (z + 5) // decimal portion truncated - Prefix and postfix operators increment or decrement by one. Example: int a, b, c = 4, d = 4, e = 1, f; a = c++ * 2; // 8 ... a = c * 2; (c incremented afterward) b = ++d * 2; // 10 ... b = (d+1) * 2; (d incremented before) f = ++e * 2 * ++e * 100; // 1200 ... (Caution: pg.77)
-----Feb/14/2002 THU pg.71.bottom. In "Day 3". - String literals are stored as a "String" object. - [ ]?: String objects are used freely. ===Comparisons - Comparisons operators return Boolean, true or false. - Comparison operators: == != < > <= >= ===Operator Precedence. (pg.79) [*]Q: '>>>' is the UNSIGNED SHIFT RIGHT operator. What does it do differently than
the other two? "...use the >>> operator which shifts 0's into the leftmost bits."
-----Feb/26/2002 TUE pg.85. Start of "Day 4", Working with Objects
-----Mar/02/2002 SAT pg.87.mid, "Day 4", Working with Objects - // Samples of creating new objects. String myString = new String(); URL myUrlAddress = new URL("http://java.sun.com"); VolcanoRobot robbie = new VolcanoRobot(); Random seed = new Random(6068430714); Point pt = new Point(0,0); - StringTokenizer class, is used to divide a string into substrings using a delimiter. (pg.87) - Allocation and deaolocation of memory for objects is automatic. Periodically, java does garbage collection and finds objects that are not being held on to by your program, and deletes them. (see: "References to Objects") - Java has three types of variables. class Day3 { float amount = 25000.0F; // instance variable. [T] (sj) static float amount2 = 5000.0F; // class variable. [T] because of static public static void main(String[] arguments) { float amt = 14000.0F; // local variable. [T] System.out.println("Initial amount..........: " + inv1.amount); inv1.amount *= 1.4F; System.out.println("Initial amount..........: " + amt); amt *= 1.4F; } } - Note: System.out.println(myString); // DOES linefeed after the output. System.out.print(myString); // Does NOT linefeed.
-----Mar/04/2002 MON pg.89.mid, "Day 4", Working with Objects ===Accessing and Setting Class and Instance Variables - Dot notation used to access instance variables. Left of dot is the object or class. Right of dot is the variable name. If the variable is also another object then you can place another dot on the right and access one of that objects variables. - Note: 'Point' is part of the java.awt package. To use 'Point', use this line... import java.awt.Point; // Allows use of Point object in this package.
[ ]Q: Is a program an example of a package? (probably "no")
-----Mar/05/2002 TUE,WED pg.91.top, "Day 4", Working with Objects ===Class Variables. - You may use either, class name or instance on the left of the dot. For better readability, it is better to use the class name to indicate it is a class (or static) variable. - Some examples of String literal and some String methods: String str = "A tropical guppy, has colorful big tails." str.length(); str.charAt(5); str.toUpperCase(); str.subString(26,32); str.indexOf('g'); str.indexOf("guppy"); ===Nesting Method Calls. - "A method can return a reference to an object, a primitive data type, or no value at all". Example: String name = "John"; int lgth = name.length(); - Methods returning objects make it possible to combine method calls, the same as combining variables, instances, or classes. Example: lgth = name.subString(1,3).length(); - The System class is part of the package: java.lang. It supports things for the system you are on. - System.out is an instance of the class PrintStream. (for standard output) ===Class Methods. - Example using String class: String s2 = String.valueOf(5); - "Class Methods also can be useful for gathering general methods together". Example, from the Math class: int maxVal = Math.max(firstVal,secondVal);
-----Mar/07/2002 THU pg.95.top, "Day 4", Working with Objects ===References to Objects. - IMPORTANT: When assigning an object to a variable or using an object as a parameter of a method, you are using refering to the address of the object. You are not creating a copy of the object. (pg.95) - Java uses references but does not support pointer arithmetic. Most of the same functionality is still provided by using references and arrays. This avoids many drawbacks of allowing pointer arithmetic. (pg.96.bottom)
-----Mar/08/2002 FRI,MON,TUE pg.97.top, "Day 4", Working with Objects ===Casting - When your variable is smaller and want to use it as something larger, then an explicit cast is NOT NEEDED, since not loosing precision. - // Primitive Data Examples: s=short, i=int, l=long, f=float. ss = (short)ll; // CAST NEEDED ll = ss; ll = (long)f1; // CAST NEEDED f1 = ll; i1 = (int)(f1/f2); // CAST NEEDED i1 = 11; i2 = 3; f1 = i1/i2; f1 = (i1/i2); f1 = (f1/i2); f1 = (i1/f2); - The one restriction of source and destination of class references (or object references) must be related by inheritance. - // Subclass Example: DC10 is a subclass of Airplane. genericPlane = dcTen; // no cast needed for going to a supper class. dcTen = (DC10)genericPlane; // must cast when going to a subclass. ===Primitive types with Objects (pg.100) - You CAN NOT use primitive types interchangably with objects, even if cast. - Java does provide a class for each primitive type. The name of each class in most cases is the same as the primitive type with the first letter capitalized. - The two exceptions are: Character for char, and Integer for int. - The rest are: Boolean, Byte, Double, Float, Long, Short, Void. ===Other common tasks to perform on objects: 1) Compairing objects, 2) Determining the Class of an Object, 3) Testing to see if an object is an instance of a given class. (1) Compairing objects. - Use "==" and "!=" to see if two references to objects point to the same object. - To compare strings, use the "equals" method of the string class. (pg.102) Example that returns true or false: str1.equals(str2); - If you use two literal strings that match, java allocates it just once, and gives you back the references to the same string object. (2) Determining the Class of an Object. - String name = myObject.getClass().getName(); (3) Testing to see if an object is an instance of a given class. - "instanceof" is an operator. On the left goes the instance, on the right a class name. The right side of instanceof can also be an interface name. ===Link List: Create a class to create nodes. Call it "Node". This class should contain an instance variable of type "Node". Etc.
-----Mar/12/2002 TUE,WED pg.107, Start of "Day 5", Lists, Logic, and Loops. - IMPORTANT: Arrays in java are implemented as objects. - Each of the following, declare an array variable. Point[] pt; Point pt[]; float[] fnum; float fnum[]; int[] temps = new int[99]; // array object of slots containing int's. - The following declare an array of ten slots to later hold String objects. String[] str = new String[10]; - Array slots (or cells) when created with "new", each get initial values: 0 for numeric, false for Boolean, '\0' for char, and null for objects. (pg.109.bottom) - Examples of custom initial values: // Note: Point(int x, int y) // int...32 bits (4 bytes)...+/- 2,147 M Point[] ptArray = { new Point(23,5), new Point(234,56), new Point(3,4) }; String[] namesAy = { "Joe", "Jack", "John", "Jennifer" }; - read to midtop.pg.110. ===Accessing Array Elements (pg.110) - The first slot of each array subscript is zero. - Java checks all refererences to arrays to be sure the subscript selects an existing slot. - Number of elements of an array: myArray.length - Array object slots can contain primitive types or object references. - An array of objects in java is really an array of references to those objects. ===Changing Array Elements (pg.111) - Arrays of String Objects are shifted differently than arrays of other Objects. - Shifting slot contents of arrays of ... . objects: DOES NOT COPY the objects, the REFERENCES to them ARE COPIED. . primitive types and Strings: DOES COPY THE VALUES of the data. - Arrays are simple to use, but provide much functionality for Java. ===NOTE: POSSIBLE TOOL(S) XLN MAY WANT TO MAKE USE OF... - http://www.alphaworks.ibm.com/nav/Java?open&c=Java+-+Utilities (#1) J2C++ - Developer tool for integrating C++ objects with Java applets and applications. ===NOTE: THE "MAIN" FUNCTION AND MULTIPLE CLASSES IN ONE FILE. (sj) - Having more than one class in one file is okay. The class with main() is where the program execution begins. Only one class can have main().
-----Mar/14/2002 THU pg.113, "Day 5", Lists, Logic, and Loops. ===Multidimensional Arrays (pg.113) - Java does not technically support multiple dimensional arrays. To get this functionality, use arrays of arrays. - Here is a valid java example of arrays of arrays: int[][] dayValue = new int[52][7]; // 52 arrays of (arrays of 7 ints). ===Block Statements (pg.114) - Block Statements can be used anywhere single statements are. C language and others call them compound statments. - IMPORTANT: Local variables declared in a block recieve a scope of that block. ===Conditionals (pg.115) - // The "if" statement in java must evaluate to a boolean or use a boolean // variable. This is different than C, where you were allowed to use an int. // Java Example of "if": if (temp > 95) System.out.println("Its getting hot out today!"); else System.out.println("Its not hot out here yet!"); - // Java provides the "switch" statment and works the same as in C. The test value // can be any of these primitive types: byte, char, short, int, (and not long). Example: switch (id) { case 10: name = "Jack"; break; case 12: name = "Jennifer"; break; case 14: case 15: name = "Joe"; break; default: } - "break" cause exit of current block statement. In other words, execution jumps to the statement after the closing curly brace of the code block you are now in. - In the above example, the "id" of 14 and 15 both set name to "Joe". This is controled by the placement of the break statements.
-----Mar/15/2002 FRI pg.121, "Day 5", Lists, Logic, and Loops. ===for Loops - for (inititialization; test; increment) {body;} - Execution sequence: Init, then test=true, then body of loop, then test=true, incr, body, test=false, exit. - "break" allows exit of loop at any time. "continue" goes to the next iteration of the loop. - Init and incr sections can have multiple statments seperated by commas. - Init section can also initialize data. This data is local to the loop. - Any of the three sections of the for loop or the body, can be blank. ===Other Loop Info - break and continue statments also allow an optional label. (pg.127,128) Exectution jumps to the label. Label syntax: labelName followed by a colon ':'. ===Day 5 Summary - [ ]Q: What does the book mean by the term "list"? - [ ]Q: What is the difference between "&" and "&&" operators, since java conditions must be boolean? (See: DayCounter.java line=36 pg.119) - NOTE: "Java also guarantees that every operand of an operator (except the conditional operators &&, ||, and ? :) appears to be fully evaluated before any part of the operation itself is performed." (from)
-----Mar/18/2002 MON,TUE pg.133, Start of "Day 6", Creating Classes and Methods. - A java program is made of a main class and other classes to support main. ===Inheritance - IMPORTANT: To specify the inheritance superclass, use the "extends" keyword. Example: class DemoRobot extends Robot { // body of class } ===Questions - [ ]Q: With the object form of primitive types, what is the easiest way to reference them or modify their value? - [ ]Q: When passing primitive types to a method, is pass-by-reference obtainable without using an object or array form? ===Overloading - Method Overloading. ===The "this" keyword - The "this" keyword is used to specify the current instance. You may omit the keyword when it is implied. "this" should be used only inside the body of instance mehtods. Static (class) methods can not be referenced with "this". ===Variable Scope and Method Definitions - When using a variable, it is important to know its scope. - The sequence java checks to find a variable definition when it is referenced is found: (pg.139) - Using identical variable names as other visable variables can cause unexpected bugs. (pg.139,140) - Be aware of defined variables in superclasses to avoid mysterious bugs. (pg.139,140)
-----Mar/26/2002 TUE pg.140, "Day 6", Creating Classes and Methods. ===Passing Arguments to Methods (pg.140) - Object parameters are pass-by-reference. The function DOES modify the source. - Primitive parameters are pass-by-value. The function DOES NOT modify the source. ===(Sun) Sample code. Have also now coded some with ArrayList and JTable classes. - SimpleTableDemo.java - to understand why each reference is the way it is. Determine if data and methods are Instance, Class, or Local. - (djg) // Loop sample to find value of spread sheet titles, A15, B15..., Z15, AA15, AB15, AC15... // numAt initially pointing to the first numeric digit. for (numAt--; numAt>=0; numAt--) { cc = vnStr.charAt(numAt); cVal = Character.getNumericValue(Character.toUpperCase(cc)); aVal = Character.getNumericValue('A'); digitVal = (((cVal + 1 - aVal)) * (int)Math.pow(26.0,digitPower)); col = col + digitVal; digitPower += 1.0; }// (end B19, wk1)
******************************************************************************** -----Jan/18/2002 FRI ===Plan. - Cover Week 1. Then do IBM RoboCode. Then do rest of two weeks of book 19. - (Anand) For Trex: Our focus will be on application programming more than applets. ******************************************************************************** B18 - Teach Yourself Java 1.2 in 21 Days. 3rd ed. Lemay and Cadenhead. © 1998. "You'll be introduced to all aspects of Java software development using the most current version of the language and the best available techniques." (pg.1) ******************************************************************************** -----Jan/17/2002 THU B18: Introduction..... ===Page 1. - Some options for adding interactive programming to the web: . Macromedia Shockwave . Microsoft ActiveX - Java applets - "small programs that run inside the browser as part of the page" - Java applets have numerous purposes. - [ ]Q: Like "Java applets" as one example, what other forms of Java are there? - Java can be used for internet and "general-purpose software development as well". - Java programming tools, that make it possible to develop functional Java programs: . Symantec Visual Cafe . SunSoft Java WorkShop. - Better way to learn full scope of the language is to work directly with it via: . Sun's Java Development Kit. - available for free: java.sun.com // end