The AP Java Subset
description
Transcript of The AP Java Subset
![Page 1: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/1.jpg)
The AP Java Subset
Topics
![Page 2: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/2.jpg)
A Topics
![Page 3: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/3.jpg)
Primitive Types
int double boolean
![Page 4: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/4.jpg)
Operators
+, -, *, /, % ++, -- = +=, -=, *=, /=, %= ==, !=, <, >, <=, >= &&, ||, !
![Page 5: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/5.jpg)
Numeric Casts
(int) (double)
![Page 6: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/6.jpg)
String Concatenation
+ will convert numbers to strings and invoke
the toString() method on objects
![Page 7: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/7.jpg)
Escape Sequences
\\ \” \n
![Page 8: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/8.jpg)
Input & Output
INPUT IS NOT TESTED Output is restricted to System.out.print and
println Formatting output is not tested
![Page 9: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/9.jpg)
Arrays
One-dimensional Arrays of primitive types & of objects Initialization of named arrays:
– int[] array = {1, 3, 6, 9};
![Page 10: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/10.jpg)
Control Structures
if if/else while for return (do/while, switch, continue, break – not
tested)
![Page 11: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/11.jpg)
Method Overloading
Understand signature of method Depends on number, types & order of
parameters Does not depend on return type of method
![Page 12: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/12.jpg)
Classes
Construct objects with new operator Supply constructor parameters Invoke accessor & modifier methods Modify existing classes Design own classes
![Page 13: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/13.jpg)
Visibility
All classes will be public All instance variable will be private Methods, constructors and constants are
either public or private NO protected
![Page 14: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/14.jpg)
Comments
// single line comments /* */ block comments No Javadoc comments
![Page 15: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/15.jpg)
Final & Static
final keyword is used for final block scope constants
static final class scope constants static methods static final variables NO – final parameters, final methods, final
classes, static variables
![Page 16: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/16.jpg)
null & this
null reference is in the Java subset this is restricted to passing an implicit
parameter in its entirety to another method (obj.method(this))
Descriptions such as “the implicit parameter this”
![Page 17: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/17.jpg)
Super
Use to invoke superclass constructor– ex: super(args);
Or to invoke superclass method– ex: super.method(args);
![Page 18: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/18.jpg)
Constructors
Be able to implement Initialize all instance variables Don’t need to know default rules
![Page 19: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/19.jpg)
Extend & Implement
extend classes implement interfaces Know inheritance!!!
![Page 20: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/20.jpg)
Read and Understand
Be able to read definitions of interfaces and abstract classes
Understand that the abstract methods need to be redefined for non-abstract classes
Write interfaces or class declarations when given a general description of the interface or class
![Page 21: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/21.jpg)
Equals
Know when to use == or .equals Objects: equals Identity: ==
![Page 22: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/22.jpg)
Subclass to Superclass
No casting is needed to convert from a subclass to a superclass
Do need to know class casts:– ArrayList xx = new ArrayList();– yy = (yyclass)xx.get(i);
![Page 23: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/23.jpg)
Packages
import statement import package.subpackage.class;
![Page 24: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/24.jpg)
Exceptions
NullPointerException ArrayIndexOutOfBoundsException ArithmeticException ClassCastException IllegalArgumentException
![Page 25: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/25.jpg)
Standard Library Methods
java.lang.Object– equals– toString
java.lang.Comparable– compareTo
java.lang.Integer– Integer(int value) //constructor– intValue– equals– toString– compareTo
![Page 26: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/26.jpg)
Standard Library Methods (cont’d)
java.lang.Double– Double(double value) //constructor– doubleValue– equals– toString– compareTo
java.lang.String– compareTo– equals– length– substring– indexOf
![Page 27: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/27.jpg)
Standard Library Methods (cont’d)
java.lang.Math– abs (for int and double)– pow– sqrt
java.util.Random– nextInt– nextDouble
![Page 28: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/28.jpg)
Standard Library Methods (cont’d)
java.util.ArrayList– size– add– get– set– remove
![Page 29: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/29.jpg)
AB Topics
![Page 30: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/30.jpg)
Two-dimensional Arrays
Ragged arrays are not tested– int [][] x = new int[3][];
Don’t need to know int[3][3] is an array of arrays
Know that x[0].length is the number of columns in a rectangular two-dimensional array named x
![Page 31: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/31.jpg)
Abstract Classes
AB students are expected to design own interfaces and abstract classes
![Page 32: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/32.jpg)
Throwing Unchecked Exceptions
IllegalStateException NoSuchElementException
![Page 33: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/33.jpg)
Standard Library Methods
java.lang.Object– equals– toString– hashCode
java.lang.Comparable– compareTo
java.lang.Integer– Integer(int value) //constructor– intValue– equals– toString– compareTo
![Page 34: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/34.jpg)
Standard Library Methods (cont’d)
java.lang.Double– Double(double value) //constructor– doubleValue– equals– toString– compareTo
java.lang.String– compareTo– equals– length– substring– indexOf
![Page 35: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/35.jpg)
Standard Library Methods (cont’d)
java.lang.Math– abs (for int and double)– pow– sqrt
java.util.Random– nextInt– nextDouble
![Page 36: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/36.jpg)
Standard Library Methods (cont’d)
java.util.List– add– size– get– set– iterator– listIterator
java.util.ArrayList– All List methods– add– remove
![Page 37: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/37.jpg)
Standard Library Methods (cont’d)
java.util.LinkedList– addFirst– addLast– getFirst– getLast– removeFirst– removeLast
![Page 38: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/38.jpg)
Standard Library Methods (cont’d)
java.util.Set– add– contains– remove– size– iterator
java.util.HashSet java.util.TreeSet
![Page 39: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/39.jpg)
Standard Library Methods (cont’d)
java.util.Map– put– get– remove– containsKey– size– keySet
java.util.HashMap java.util.TreeMap
![Page 40: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/40.jpg)
Standard Library Methods (cont’d)
java.util.Iterator– hasNext– next– remove
Java.util.ListIterator– add– set
![Page 41: The AP Java Subset](https://reader036.fdocuments.us/reader036/viewer/2022081502/56815dfd550346895dcc36e8/html5/thumbnails/41.jpg)
Online resources
Acorn online Java API