Final Exam Topics CS100 Fall 2000 Overall: + 1/3 MATLAB, 2/3 Java + closed book + about 6 problems + fill-in-the blank, fill-in-the box + no drawing of box-scope diagrams required +-------------------------------------------------------------------------------------+ JAVA Language Elements + keywords + primitive types (int, double, boolean, char) + identifiers (rules, naming convention) + Issues: - Java is OOP - Java is strongly typed - Everything is an object Flow Control + block statements: ${ statements }$ + condition: $if$, $if$-$else$, $if$-$else if$-$else$ + repetition: $while$, $for$, $do$-$while$ Methods + syntax + components of a header - return type - name - formal parameters (must have types) + how to access (from an object or within an object) + returning values - return value has a type $return $ - $void$ does not return a value but you may still use $return$ w/o a value + returning a value and printing are DIFFERENT! + all variables pass by value, including references + local variables and scope + overloading: keep the same method name, but change the header Classes + class is blueprint; object is instance of class + INSTANTIATION: creating an object using the class + structure of class - instance variable(s) (usually private) - constructor(s) - method(s) - setters (set instance vars -> make public) - getters (get instance vars -> make public - utility (methods used only in class) + $this$ uses: - this.varname when a method has a local variable with same name as varname - refers to current object - may also use as a constructor (not required for exam) + methods inside a class can all "see" eachother + instance vars inside a class can all "see" eachother + $toString()$ - builtin method to print a description of an object - activates when code "prints the object" - user must define in class to make "pretty" output for "printing the object" Objects + create with $new$ operator: 1) new Classname(arguments); 2) Classname refvar; refvar = new Classname(arguments); 3) Classname refvar = new Classname(arguments); + the code $new Classname(arguments)$ returns a REFERENCE to a newly created object + a reference is an address of a newly created object + alias: setting a refvar to another refvar -- they both point to the same object + passing the reference to a method means passing the address of an object to a local variable -- the local variable becomes as alias of the object + objects that have no reference variable connection become "unreachable" Constructors + use rules for methods but, no return type and have same name as class! + may be overloaded + if you do not provide a constructor, Java gives you empty constructor by default + if you give at least one, Java does NOT automatically give you a default constructor $static$ + CLASS VARIABLES: variables in class that are labeled as static + CLASS METHODS: methods in class that are labeled as static + all objects in class can see the same static things + changing a static variable changes that var's value for all objects in the same class + when to use? when all objects in the class need/use the same thing encapsulation + "spread out" code + make methods for getting and setting instance variables + hide information with $private$ when possible + objects "passed inside" another class can directly access members even if the fields are labelled as $private$ $final$ + modifier for variable to make it constant (unassignable) + write constants in all UPPERCASE strings + Strings are objects + use string1.equals(string2) to compare equality of string1 and string2 + arrays of characters + $charAt$, $indexOf$, $String$ as a constructor Box Diagrams + see online file for entire set of rules Arrays: + declaring: arrays are objects! + initializer lists and anonymous arrays + use [] for array indexing: declare, store, extract + $.length$ to find length of current array + initial values are "zeros" (same rules as instance variables) + 1-D, 2-D, multi-D arrays + arrays must have the type inside elements + arrays of primitive values contain those values + arrays of references to objects contain references: primitive values get stored at the "furthest" dimension + use arrays of arrays to simulate multidimensional arrays + to create 2-D array, typically use row major, but could use any arrangement (up to programmer) Select Sort (taught in section) + recognize and/or program the algorithm + use with arrays to sort elements Inheritance: + sub/super class relationship + $extends$ + subclass objects "use" code from superclass + rules for constructor calls in subclass (subclass constr must call superclass constr) (why? constructors do NOT inherit!) + encapsulation and inheritance + $private$ > $protected$ > default > $public$ in terms of privacy + $private$ IVs/methods are not visible/accessible in subclass (use superclass method to obtain in a roundabout fashion) + method overriding (subclass uses same method header, but different body: cannot increase privacy, though) + $super.$: access a superclass member + $super()$: call the superclass constructor + polymorphism: treat a superclass object as if it were a subclass object (a reference to a superclass object can refer to a subclass object) + $Object$ class (all classes are subclasses of $Object$, $toString$, $equals$) +-------------------------------------------------------------------------------------+ MATLAB Basics: + command windows, edit windows + finding help + everything is an array + file management - ASCII - setting path - loading M-Files Keywords: + loops: $while$, $for$, $end$ + conditions: $if$, $elseif$, $else$, $end$ + scalars - numbers - operators - precedence - associativity + booleans - values: 0 (false), 1 (true) - relations + arrays - sizes and dimensions - 1D - 2D - locations of elements - indicies (single index) - indicies (row,col indicies) - creating - linspace - colon - $ones$, $zeros$ - extracting values - inserting values - swapping rows/cols - math - array arithmetic + Loops - repetition - accumulation - conditional update + User-Defined Functions - creating your own functions - function M-files - Variable passing - local vs $global$ variables (scope) - $error$, $warning$ - function functions ($feval$, $eval$, $fzero$, $ezplot$, ...) - returning multiple values - returning no values - basic recursion (a function calling itself) - nested functions - subfunctions - toolboxes + Random numbers - generating random numbers - generating random numbers within a given range + mod function - find the remainder + strings - characters as ASCII codes - converting - num2str, str2num - comparing strings - concatenating strings - $double$, $char$ + Symbolic Math Toolbox - symbolic objects (syms) - $solve$ - $eval$ + Logical Arrays - $isreal$ - find - () - logical function + Cell Arrays - creating cell arrays - viewing the content - expanding cell arrays - cell arrays of strings + Structure Arrays - creating structures - adding/removing fields - nesting structure functions +-------------------------------------------------------------------------------------+ Projects (both MATLAB and Java) + Numerical Methods for solving equations - Lhs/Rhs - Bisection - Newton - overall: searching for a solution from many values processing input from user indeteminate looping basic recursion + DNA - simple distance - weighted distance - user I/O - file I/O - overall: processing arrays of characters/strings random values using user input/file input to obtain data spitting out data to user/file +-------------------------------------------------------------------------------------+