CS 112 Department of Computer Science George Mason University CS 112 Department of Computer Science...

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

Transcript of CS 112 Department of Computer Science George Mason University CS 112 Department of Computer Science...

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

CS 112Department of Computer Science

George Mason University

CS 112Department of Computer Science

George Mason University

Final Review

Lecture 14

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

Lecture 4 Slide 2CS 112 George Mason University

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

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

Lecture 4 Slide 3CS 112 George Mason University

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.

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

Lecture 4 Slide 4CS 112 George Mason University

Chapter 3

• String class again. • String methods -calling them • Using classes

• Random

• Math

• Graphics

• Graphics• Components and containers-frame and panel• Graphics class (paintComponent( Graphics g))

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

Lecture 4 Slide 5CS 112 George Mason University

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

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

Lecture 4 Slide 6CS 112 George Mason University

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

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

Lecture 4 Slide 7CS 112 George Mason University

Chapter 5

• Control Structuresboolean operators <, <=, >, >=, == !=, && || !boolean expressionsstructures

ifif..elseswitchwhiledo…whilefor

compound statements, blocks

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

Lecture 4 Slide 8CS 112 George Mason University

Chapter 5 continued

• Graphics• Custom panels and listeners• Radio buttons, • Dialog Boxes• Determining event sources with if statements

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

Lecture 4 Slide 9CS 112 George Mason University

Chapter 6

• Writing classes, how to• Overloading methods• Interfaces

• Abstract methods• Implementing interfaces

• Graphics• Layouts

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

Lecture 4 Slide 10CS 112 George Mason University

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,

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

Lecture 4 Slide 11CS 112 George Mason University

Chapter 8

• Inheritance-classes• Child classes - extends• Overriding of methods in child classes• Definition, use

• this• super• Graphics

• Timer class• paintComponent method

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

Lecture 4 Slide 12CS 112 George Mason University

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();

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

Lecture 4 Slide 13CS 112 George Mason University

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

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

Lecture 4 Slide 14CS 112 George Mason University

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.

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

Lecture 4 Slide 15CS 112 George Mason University

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

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

Lecture 4 Slide 16CS 112 George Mason University

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()