Transcript Chapter 12
FINAL EXAM
Final Exam
» Wednesday, Dec 14: 8:00 - 10:00 AM (Frny G140)
» Cumulative (weighted towards recent material)
» 40 MC (2 points each), 6 programming (20 points
each) = 200 points total
Old Final Exams Available On Website
Chapter 12
Java: an Introduction to Computer Science & Programming - Walter Savitch
1
Chapter 1: Introduction to Computers
and Java
Chapter 12
Hardware, memory
Object Oriented Programming: Encapsulation, Polymorphism,
Inheritance
Java Programs: .java, .class files, byte-code interpreter
Java: an Introduction to Computer Science & Programming - Walter Savitch
2
Chapter 2: Primitive Types, Strings, and
Console I/O
Chapter 12
Variables (int, char, float, etc): declarations, assignment, naming
Type Casting: Implicit and Explicit
Integer/Float Division, Parentheses/Precedence Rules
String class: concatenation, indices (0 to n-1)
String methods: length(), equals(), trim(), charAt(), compareTo()
Scanner: need to import java.util.*, next(), nextLine(), nextInt(),
etc
Java: an Introduction to Computer Science & Programming - Walter Savitch
3
Chapter 3: Flow of Control
Chapter 12
If-else statements, nested if-else statements
Comparison operators (==, !=, >, <=, etc)
Boolean operators: &&, ||
Switch statement (make sure to have “break;”)
While loop: 0 or more iterations
Do-while loop: 1 or more iterations
For loops: for(initialize; boolean_check; update_action)
Nested loops
Boolean type (only “true” or “false” values)
Java: an Introduction to Computer Science & Programming - Walter Savitch
4
Chapter 4: Defining Classes and Methods
Chapter 12
Class definition: “public class Class_name {“
Public/private data variables
Method definition: “public type method_name {“
Methods return values (int, string, etc) or don’t (null)
Invoking methods: “object_name.method_name();”
Creating objects: “Class_name variable_name = new
class_name();”
The “this” parameter
Information hiding/encapsulation
Objects variables: references (memory address) vs. data
Equals methods for classes
Java: an Introduction to Computer Science & Programming - Walter Savitch
5
Chapter 5: More About Objects and
Methods
Chapter 12
Static methods: called without an object (e.g. Integer.parseInt() )
Wrapper classes: Integer, Double
Automatic boxing and unboxing
Method overloading: different parameters (cannot change return
type)
Constructors: default and others
Java: an Introduction to Computer Science & Programming - Walter Savitch
6
Chapter 6: Arrays
Chapter 12
Creating/accessing arrays
Arrays are a reference to memory segment
For loop: stepping through arrays (.length) (watch out for:
ArrayIndexOutOfBounds exceptions)
Arrays of objects
Sorting arrays: selection sort
Multi-dimensional arrays
Java: an Introduction to Computer Science & Programming - Walter Savitch
7
Chapter 7: Inheritance
Chapter 12
Declaration: “public class Class_name extends Class_name2”
Overriding method definitions (“final” modifier: method can’t be
overridden)
Superclass constructor calls: “super(parameters)”
Interface implementation: “public class Class_name implements
Interface_name”
Implement/Extend: can implement multiple interfaces (comma
separated) but extend only one class
Java: an Introduction to Computer Science & Programming - Walter Savitch
8
Chapter 8: Exception Handling
Chapter 12
Try/catch/finally block
Throwing exceptions: “throw new Exception(“info”);”
getMessage for exceptions
Defining your own exception classes: “public class Class_name
extends Exception”
Methods throwing exceptions: “public void method_name()
throws DivideByZeroException” – don’t have to handle
exception in this method but must in calling method
Multiple exception handling (hierarchy)
Java: an Introduction to Computer Science & Programming - Walter Savitch
9
Chapter 9: Streams and File I/O
Need: import java.io.*;
StringTokenizer class (can use split if you want)
Be sure to try/catch IOExceptions
Text Files:
- PrintWriter outputStream = new PrintWriter(new FileOutputStream(“filename”);
- BufferedReader inputStream = new BufferedReader(new FileReader(“filename”);
- reads nothing at end of file (null)
Binary Files:
- ObjectOutputStream outputStream =
new ObjectOutputStream(new FileOutputStream(“filename”);
- ObjectInputStream inputStream =
new ObjectInputStream(new FileInputStream(“filename”);
- throws EOFException at end of file
Chapter 12
Java: an Introduction to Computer Science & Programming - Walter Savitch
10
Chapter 10: Dynamic Data Structures
Chapter 12
Need: import java.util.*;
Vectors: declaring, adding elements, setting elements, retrieving
elements
Linked Lists: creating classes (link to object of same type)
Empty List: null pointer (last item always points to null)
Generics: no primitive types, defining classes and methods
Java: an Introduction to Computer Science & Programming - Walter Savitch
11
Chapter 11: Recursion
Three things needed:
1. Branching statement
2. Recursive call
3. Stopping case (aka “Base case”)
Can always write recursive methods as iterative but not always
easier to write/understand
Binary Search
Merge Sort
Chapter 12
Java: an Introduction to Computer Science & Programming - Walter Savitch
12
Chapter 12: Window Interfaces Using
Swing
Event-driven programming (button clicks, etc)
Need: import javax.swing.*; import java.awt.*; import
java.awt.event.*;
Declaring swing class: “public class Class_name extends JFrame”
JLabel, JButton, JTextArea, JTextField, JPanel, ContentPane
Constructor: set size etc, be sure to “setVisible(true);”
Layout Managers: FlowLayout, BorderLayout, GridLayout
ActionListener method for handling events: “… implements
ActionListener”
Chapter 12
Java: an Introduction to Computer Science & Programming - Walter Savitch
13
Chapter 13: Applets and HTML
Chapter 12
Same imports needed as swing
Classes: “public class Class_name extends JApplet”
Need: “public void init()” method: no constructor, no setVisible
Java: an Introduction to Computer Science & Programming - Walter Savitch
14
Chapter 14: More Swing
Chapter 12
Menus: JMenu, JMenuItem, JMenuBar
Nesting menus
Icons, JScrollPane
Layout Managers: BoxLayout, CardLayout
Inner classes
Java: an Introduction to Computer Science & Programming - Walter Savitch
15