440 likes | 452 Views
Final Review. Final Details. Monday, December 11 th 7:00pm – 10:00pm HCC 1325. Sections Covered - Detailed View. 1.1-1.2, 1.4-1.6 2.1-2.6 3.1-3.3, 3.6-3.8 [covered 3.4, 3.5 in class] 4.1-4.4 [covered 4.5 in class] 5.1-5.5, 5.7-5.8 [(basically) covered 5.6 in class]
E N D
Final Details • Monday, December 11th • 7:00pm – 10:00pm • HCC 1325
Sections Covered - Detailed View • 1.1-1.2, 1.4-1.6 • 2.1-2.6 • 3.1-3.3, 3.6-3.8 [covered 3.4, 3.5 in class] • 4.1-4.4 [covered 4.5 in class] • 5.1-5.5, 5.7-5.8 [(basically) covered 5.6 in class] • 6.1-6.5, 6.7, 6.8 [covered 6.9 in class] • 7.1-7.2, 7.6-7.7 [covered 7.4 in class] • 8.1-8.5 • 9.1-9.5 • 10.1-10.6 • 11.1-11.3 • some parts of 12 covered in class notes
Sections Covered - Broadly • Chapters 1-11 • (except for Graphics track) • … with minor exceptions…
Other Topics (from before midterm) • Running time / Big O notation • Working with references handout • including null/this • Merge sort • Command line arguments • printf
Other Topics (after midterm) • More detailed treatment of some topics • polymorphism (e.g. covered Collections) • file output (e.g. covered buffers and generic Writers) • File input • Call Stack • Scanning tokens • Regular Expressions
Chapter 1 • Computer processing • The Java Programming Language • Program Development • Object-Oriented Programming • (very basic)
Chapter 2 • Character Strings • Variables and Assignment • Primitive Data Types • Expressions • Data Conversion • Interactive Programs
Chapter 3 • Creating Objects • The String Class • Packages • Formatting Output • (plus more detailed coverage of printf) • Enumerated Types • Wrapper Classes
Chapter 4 • Anatomy of a Class • Encapsulation • Anatomy of a Method
Chapter 5 • The if Statement and Conditions • Other Conditional Statements • Comparing Data • The while Statement • Other Repetition Statements
Chapter 6 • Software Development Activities • Identifying Classes and Objects • Static Variables and Methods • Class Relationships • Interfaces • Method Design • Testing • (covered the same material in class)
Chapter 7 • Declaring and Using Arrays • Two-Dimensional Arrays • The ArrayList Class
Chapter 8 • Creating subclasses • Overriding methods • Class hierarchies • Inheritance and visibility • Designing for inheritance
Chapter 9 • Polymorphism • polymorphic references • through inheritance • through interfaces • Searching • linear search • binary search • Sorting • insertion sort • selection sort • merge sort
Chapter 10 • Exception Handling • The try-catch Statement • Exception Classes • I/O Exceptions
Chapter 11 • Recursive Thinking • Recursive Programming • Using Recursion
Running Time – Big-O • For a parameter n… • e.g. the length of a string or size of an array • … count the number of steps performed… • loop through n elements = n steps • loop inside a loop = n2 steps • Ignore constants… coefficients… • 3n + 2 steps = O(n) • n2 /2 steps = O(n2) • “cutting problem in half at each step” = O(log n)
Working with References • null reference • Object variable not assigned anything • When does this cause an exception? • this reference • When does this simplify code?
File I/O • Where do the exceptions happen? • How do we handle them? • Why do we want to buffer? • How do we buffer? • Using Scanner • with default tokens • with defined tokens
Regular Expressions • Given regular expression • yes/no matching questions • give informal description • Given informal description • write regular expression • pass appropriately to Scanner
What Kind of Questions? • Look at the exercises in the text • finding errors in code • finding differences in code • explaining/defining concepts • predicting output of code • writing methods or classes • specifying/justifying design from requirements
What Kind of Questions? • Similar format for lecture material • e.g. specify running time • e.g. find null reference problem • Using regular expressions • Predicting tokens parsed • Describe call stack • including exceptions • explain stack trace
It May Be on the Test if… • It is in the text • It is in the lecture notes • It is something I said in class or wrote on the blackboard • It was part of a lab/assignment
What Code Do You Need to Know? • Officially: everything as per previous slide • Unofficially: • I try to only assume you know “important” methods and classes • … but I decide what is “important” • in general… little used methods that occur rarely in the notes will be given implicitly • but you should know enough code to solve problems without help/look-up
Examples • There will be definitions (again) • abstract class • checked exception • final method • overridden method
Examples • There may be explanations required… • Explain why a static method cannot refer to an instance variable. • Give two differences between an abstract class and an interface.
Examples • Draw a UML diagram for a single class hierarchy representing these animals, with abstract classes grouping animal types • parrot • gorilla • horse • bat • penguin • Add an interface for flyers
Examples • Correct the problems Flyer polly = new Parrot(); Animal koko = new Gorilla(); Gorilla junior = koko.makeOffspring(); polly.layEgg();
Examples • Define appropriate classes and public methods for the given requirements. • Every salesperson will be assigned a unique ID number, and a numbered office with a phone. Salespeople will sell vacuum cleaners at a fixed price. When inventory runs out, the top salesperson will be designated employee of the month.
Examples • Find the exception in this code, and handle it. public static void main(String[] args) { FileWriter fileout = new FileWriter(“names.txt”); if(fileout!=null) fileout.write(“John Smith”); else System.out.println(“No name written to file”); }
Examples • Find the exception in this code, and handle it. public static void main(String[] args) { Student s = new Student(4533453,”tsmith”); String fname = s.getFirstName(); System.out.println(fname); }
Examples • Given this information in file.txt: 7 | 5 | 5p ,| 4 • Write the code that will print these tokens to the screen using a Scanner/delimiter: • “7 | 5 | 5” and “ , | 4” • “7 | “ and “ | “ and “p ,| 4”
Solution Scanner filein = new Scanner( new File(“file.txt”) ).useDelimiter(“p”); while(filein.hasNext()) { System.out.println(filein.next()); } “5”
Examples • Yes or no expression matching • [1-7]*a? 43 • (17)+(17a)? 17a • [abc][def](di)? bed • [123]+(45)?a* 12312345aaaa • [ab][bc][cde]* abcde • [A-C]DEF? ABCDE • [truck].[stop]+ trstopstop yes no no yes yes no yes
Examples • Describe the strings matching the expressions • (cat)+ • [cat][cat] • cat? • [ca]?t* • (c?a+)t? • [c-t]a?[c-t]*
Examples • What is the value in variable temp after: int temp = 30; String stemp = temp + “12”; temp = temp + Integer.parseInt(stemp); • Again: Collection<Integer> l = new ArrayList<Integer>; int temp = 40; l.add(40); temp = l.size();
Examples • Write a method that picks a random character in the string “string”.
Examples • What is wrong with this? • How can it be corrected? int count=1,max=0; while(count=max) { System.out.println(count); count-=2; }
Examples • A LinkedList implements Collection • Write a method that adds every word in the sentence “This is a sentence” to a LinkedList, then prints the size.
Examples • Given double[] input, write a method that returns the highest value
Examples • Write a class NamedArrayList that extends ArrayList by adding a name for the array list in the first position.
Examples • What is wrong with these declarations: • char[] chars = {“d”, “a”, “b”}; • String[] = new String[5]; • Scanner[] sc = new Scanner(5);
Examples • Write a recursive function that returns true if the input is a power of 3. • Write a recursive function that returns true if a string contains only the letter ‘s’.