Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 112 Department of Computer Science George Mason University CS 112 Department of Computer Science George Mason University Final Review Lecture 14.

Similar presentations


Presentation on theme: "CS 112 Department of Computer Science George Mason University CS 112 Department of Computer Science George Mason University Final Review Lecture 14."— Presentation transcript:

1 CS 112 Department of Computer Science George Mason University CS 112 Department of Computer Science George Mason University Final Review Lecture 14

2 CS 112 George Mason UniversityLecture 4 Slide 2 Basics Chapter 1 Computer Basics Binary-1s and 0s Bits and Bytes Characters Encryption into binary, ASCII and Unicode(Java) Networks Java language, compilation, interpretation, Java Virtual Machine

3 CS 112 George Mason UniversityLecture 4 Slide 3 Chapter 2 String class String variables Printing to the monitor, System.out.println Concationation of strings Primitive Variable Types ints, doubles, chars, booleans Arithmetic operators +, - * /, ++ --, -=,+=,*=,/= Chars-uppercase and lower case, subtract 32 from a, get A Wrapper classes Integer, Double, methods, calling methods of class Data conversion -casting Graphics Drawing on screen, coordinate system, drawing methods (drawRect) etc.

4 CS 112 George Mason UniversityLecture 4 Slide 4 Chapter 3 String class again. String methods -calling them Using classes Random Math Graphics Components and containers-frame and panel Graphics class (paintComponent( Graphics g))

5 CS 112 George Mason UniversityLecture 4 Slide 5 Chapter 4 Classes Using and Writing Using classes- Jbutton button = new Jbutton(“press me”); declaring and instantiating objects of a class. constructors button.addActionListener(this); calling class methods Class is a template, has variables and methods defined. Writing classes Constructors- default constructors- other constructors Variables-instance-private Methods - non-static, public Methods-non static in classes Void and those that return a value Parameters Accessing with an object of the class Accessing methods of static classes

6 CS 112 George Mason UniversityLecture 4 Slide 6 Chapter 4 continued Static Static variables Static methods-can’t call non static Variables Global Instance Local Graphics Components interactive (buttons etc) Events Interfaces required to activate components-requires methods of interface to be defined in class that implements interface

7 CS 112 George Mason UniversityLecture 4 Slide 7 Chapter 5 Control Structures boolean operators, >=, == !=, && || ! boolean expressions structures if if..else switch while do…while for compound statements, blocks

8 CS 112 George Mason UniversityLecture 4 Slide 8 Chapter 5 continued Graphics Custom panels and listeners Radio buttons, Dialog Boxes Determining event sources with if statements

9 CS 112 George Mason UniversityLecture 4 Slide 9 Chapter 6 Writing classes, how to Overloading methods Interfaces Abstract methods Implementing interfaces Graphics Layouts

10 CS 112 George Mason UniversityLecture 4 Slide 10 Chapter 7 Arrays single and double dimensioned Declaring and creating arrays of primitives Declaring and creating arrays of objects Accessing an array element For loops to access all array elements and manipulate them Command Line Arguments Using arrays as parameters of methods Graphics Listener interfaces for mouse,

11 CS 112 George Mason UniversityLecture 4 Slide 11 Chapter 8 Inheritance-classes Child classes - extends Overriding of methods in child classes Definition, use this super Graphics Timer class paintComponent method

12 CS 112 George Mason UniversityLecture 4 Slide 12 Chapter 9 Polymorphism- means many forms Polymorphism in Java classes - late binding Classes- Assigning an object of a child class to a parent object Calling methods with this parent object calls the child method of the same name if it exists Book b = new ComicBook(); //assigning a child to a parent object b.method1(); //call to method1 will call ComicBook method1 if it exists. Interfaces Polymorphism Can declare variables with type equal to some interface Can then assign an object of any class that implements that interface to the interface object; Suppose you have an interface Interface and a class implementing that interface ClassB. You can declare a variable Interface I; You can assign to I an object of type ClassB I = new ClassB();

13 CS 112 George Mason UniversityLecture 4 Slide 13 Chapter 9 continued Sorting Sorting 5 8 1 3 Selection Sort- Order n squared Given list above, go through list and find smallest Swap that with whatever is first in the list now. 1 8 5 3 Go through the remainder of the list and get the lowest 3 Swap that with the second element of the list 1 3 5 8 Continue until finished Insertion Sort Order n squared Put first element into sorted list in proper place 5 813 Put next element into sorted list in proper place 5 8 1 3 Continue until all elements are in sorted list

14 CS 112 George Mason UniversityLecture 4 Slide 14 Chapter 9 continued Searching looking for a particular element in a list Looking for 8 in this list 1 6 4 10 20 5 8 Linear Search Order n Begin at the beginning and look through the list for 8. Binary Search Order Ln(natural log) n Must first sort the list 1 4 5 6 8 10 20 Then go to the middle of the list say 6 Check if 6 is larger or smaller than your target 8 As it is smaller, drop the first half of the list Go to the middle of what is left say 10 Ask again whether this is bigger or smaller, it’s bigger Drop the last half of the list and continue until you find the element of the list is exhausted.

15 CS 112 George Mason UniversityLecture 4 Slide 15 Chapter 10 Exception Handling in Java try…catch block throws clause Checked vs unchecked exceptions I/O from files and input from keyboard- checked exceptions Split panes Scroll Panes

16 CS 112 George Mason UniversityLecture 4 Slide 16 I/O I/O Classes FileReader,BufferedReader FileWriter,BufferedWriter InputStreamReader, BufferedReader Methods readLine(), write() StringTokenizer class Declaring an new object for each line of input, String line = in.readLine(); default uses blanks to separate elements of line StringTokenizer tokenizer=new StringTokenizer(line); Use hasMoreTokens() in a while loop to process all words in each line. While (tokenizer.hasMoreTokens()) Inside the loop use String word = line.nextToken()


Download ppt "CS 112 Department of Computer Science George Mason University CS 112 Department of Computer Science George Mason University Final Review Lecture 14."

Similar presentations


Ads by Google