Java AP Curriculum Focus and Java Subset Alyce

Java: AP Curriculum Focus and Java Subset � Alyce Brady 1

Curriculum Topics � Ø Object-oriented programming and design ØDeclaring and constructing objects ØInvoking methods ØInteracting objects ØClass implementations, including method implementations • Parameter passing • Basic control flow constructs 2

Curriculum Topics (continued) � Ø Data Structures ØPrimitive types ØClasses ØArrays and Array. Lists ØMaps and Sets (AB) ØStacks and Queues (AB) ØLinked Lists (AB) ØTrees (AB) ØHeaps, Priority Queues (AB) 3

Curriculum Topics (continued) � Ø Algorithms ØTraversing Linear Data Structures • Accumulate • Find Min/Max ØSearching (e. g. , linear, binary) ØSorting ØTraversing Linked Lists and Trees (AB) ØAnalyzing space and time performance (formal analysis -- AB) 4

AP Java Subset � Ø Why have a subset? ØLanguage is big; can’t cover everything. ØLibraries are bigger; can’t cover everything. ØExam can’t test everything. ØExam should test fundamental ideas, not every esoteric (or interesting, or even useful) language construct. Ø Subset defines/limits what may be on the exam, not what you can cover. 5

Java Subset � Ø Primitive Types (similar to C++) Øint, double, boolean Øarithmetic operators: + - * / % ++ -Ørelational & logical: == != < <= && || ! Øassignment: = += etc. Ønumeric casting: (int) (double), truncation Øchar is not required by subset 6

Java Subset (continued) � Ø String class (similar to apstring) ØDeclaring and constructing strings ØString constants ØString concatenation (+) • converting numerics to strings • converting objects to strings (to. String) ØEscape sequences: \ ” n 7

Java Subset (continued) � Ø I/O Ø System. out. print, System. out. println Ø No other I/O will be tested, so you can use whatever techniques you and your textbook choose, e. g. , keyboard input, text fields in graphical user interfaces, mouse events, applets, etc. Ø Case study also uses Debug. print, Debug. println 8

Java Subset (continued) � Ø Control Structures (similar to C++) Ø if, if - else Ø for, while Ø return Ø Comments (similar to C++) Ø // Ø /* … */ Ø Case study uses doc. comments /** … */ 9

Java Subset (continued) � Ø Using Objects Ø Constructing objects using new, passing parameters to constructors as necessary Ø Variables are references to objects Ø Dot notation for invoking methods Ø Use of this to pass self to other objects Ø Difference between == and equals Ø null reference 10

Java Subset (continued) � Ø Defining Classes Ø public/private static final constants Ø private instance variables (data members) Ø public and private constructors and methods (member functions) 11

Java Subset (continued) � Ø Methods Ø Method calls and method definitions Ø Constructors, accessors, modifiers Ø Parameter passing (always pass-by-value, but passing references by value feels like pass-byreference) Ø Method overloading; signature depends on number, type, order of parameters Ø super. method to call overridden method definition 12

Java Subset (continued) � Ø Constructors (similar to C++) Ø Name is same as class; no return value Ø Initialize instance variables in constructors (no initialization lists) Ø Call super to initialize inherited data Ø static constants are initialized when declared: public static final CONSTANT = init_expr; 13

Java Subset (continued) � Ø Standard Java Library Classes (A list) Øjava. lang. Object Øjava. lang. Comparable (AB only? ) Øjava. lang. Integer, java. lang. Double Øjava. lang. String Øjava. util. Array. List Øjava. lang. Math Øjava. util. Random Ø import statement 14

Java Subset (continued) � Ø Linear Indexed Data Structures Ø 1 D (A) and 2 D (AB) arrays, similar to apvector • bounds checking • my. Array[i]. length • 2 D arrays are AB material ØArray. List class • Core subset of methods • Casting from Object to specific class (and casting more generally in other contexts) 15

Java Subset (continued) � Ø Inheritance and Interfaces ØImplementing interfaces ØExtending classes • inheriting data and methods • overriding methods • dynamic binding (polymorphism) ØAbstract classes 16

Java Subset (continued) � Ø Exceptions (unchecked exceptions) ØUnderstand when they occur ØNull. Pointer. Exception, Array. Index. Out. Of. Bounds. Exception, Arithmetic. Exception, Class. Case. Exception, Illegal. State. Exception, No. Such. Element. Exception 17

Java Subset (continued) � Ø What is NOT in the subset (not testable)? Ø char Ømost I/O Ø main method (used in case study) and applets Ø do/while, switch, break Ø protected visibility (used in case study) Ømany other features 18

Java Subset (AB Additions) � Ø Standard Java Library Classes Øjava. lang. Comparable (officially AB only) Øjava. util. List (interface) Øjava. util. Array. List implements java. util. List Øjava. util. Linked. List implements java. util. List Øjava. util. Set (interface) Øjava. util. Hash. Set implements java. util. Set Øjava. util. Tree. Set implements java. util. Set Øjava. util. Iterator Øjava. util. List. Iterator extends java. util. Iterator 19

Standard Java Lists (java. util) � List (interface) boolean add(Object x) int size() Iterator iterator() List. Iterator list. Iterator() Array. List Linked. List Object get(int index) Object set(int index, Object x) void add(int index, Object x) Object remove(int index) void add. First(Object x) void add. Last(Object x) Object get. First() Object get. Last() Object remove. First() Object remove. Last() 20

Standard Java Sets (java. util) � Set (interface) boolean add(Object x) boolean contains(Object x) boolean remove(Object x) int size() Iterator iterator() Hash. Set Tree. Set 21

Standard Java Lists (java. util) � Iterator (interface) boolean has. Next() Object next() void remove() List. Iterator (interface) void add(Object x) void set(Object x) 22

Collections (NOT in Subset!) � Collection (interface) boolean add(Object x) boolean contains(Object x) boolean remove(Object x) int size() Iterator iterator() List. Iterator list. Iterator() Set 23

Java Subset (AB Additions) � Ø Standard Java Library Classes Øjava. util. Map (interface) Øjava. util. Hash. Map ØJava. util. Tree. Map Øjava. lang. Object • int hash. Code() 24

Standard Java Maps (java. util) � Map (interface) Object put(Object key, Object value)) Object get(Object key) boolean contains. Key(Object key) int size() Set key. Set() Hash. Map Tree. Map 25

Java Subset (AB Additions) � Ø AP CS List. Node and Tree. Node Classes Ø Interfaces for Stack, Queue, Priority. Queue ØThere is a java. util. Stack class, but this is not the same as the AP interface and is not in the subset 26
- Slides: 26