410 likes | 554 Views
The AP Java Subset. Topics. A Topics. Primitive Types. int double boolean. Operators. +, -, *, /, % ++, -- = +=, -=, *=, /=, %= ==, !=, <, >, <=, >= &&, ||, !. Numeric Casts . (int) (double). String Concatenation . +
E N D
The AP Java Subset Topics
Primitive Types • int • double • boolean
Operators • +, -, *, /, % • ++, -- • = • +=, -=, *=, /=, %= • ==, !=, <, >, <=, >= • &&, ||, !
Numeric Casts • (int) • (double)
String Concatenation • + • will convert numbers to strings and invoke the toString() method on objects
Escape Sequences • \\ • \” • \n
Input & Output • INPUT IS NOT TESTED • Output is restricted to System.out.print and println • Formatting output is not tested
Arrays • One-dimensional • Arrays of primitive types & of objects • Initialization of named arrays: • int[] array = {1, 3, 6, 9};
Control Structures • if • if/else • while • for • return • (do/while, switch, continue, break – not tested)
Method Overloading • Understand signature of method • Depends on number, types & order of parameters • Does not depend on return type of method
Classes • Construct objects with new operator • Supply constructor parameters • Invoke accessor & modifier methods • Modify existing classes • Design own classes
Visibility • All classes will be public • All instance variable will be private • Methods, constructors and constants are either public or private • NO protected
Comments • // single line comments • /* */ block comments • No Javadoc comments
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
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”
Super • Use to invoke superclass constructor • ex: super(args); • Or to invoke superclass method • ex: super.method(args);
Constructors • Be able to implement • Initialize all instance variables • Don’t need to know default rules
Extend & Implement • extend classes • implement interfaces • Know inheritance!!!
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
Equals • Know when to use == or .equals • Objects: equals • Identity: ==
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);
Packages • import statement • import package.subpackage.class;
Exceptions • NullPointerException • ArrayIndexOutOfBoundsException • ArithmeticException • ClassCastException • IllegalArgumentException
Standard Library Methods • java.lang.Object • equals • toString • java.lang.Comparable • compareTo • java.lang.Integer • Integer(int value) //constructor • intValue • equals • toString • compareTo
Standard Library Methods (cont’d) • java.lang.Double • Double(double value) //constructor • doubleValue • equals • toString • compareTo • java.lang.String • compareTo • equals • length • substring • indexOf
Standard Library Methods (cont’d) • java.lang.Math • abs (for int and double) • pow • sqrt • java.util.Random • nextInt • nextDouble
Standard Library Methods (cont’d) • java.util.ArrayList • size • add • get • set • remove
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
Abstract Classes • AB students are expected to design own interfaces and abstract classes
Throwing Unchecked Exceptions • IllegalStateException • NoSuchElementException
Standard Library Methods • java.lang.Object • equals • toString • hashCode • java.lang.Comparable • compareTo • java.lang.Integer • Integer(int value) //constructor • intValue • equals • toString • compareTo
Standard Library Methods (cont’d) • java.lang.Double • Double(double value) //constructor • doubleValue • equals • toString • compareTo • java.lang.String • compareTo • equals • length • substring • indexOf
Standard Library Methods (cont’d) • java.lang.Math • abs (for int and double) • pow • sqrt • java.util.Random • nextInt • nextDouble
Standard Library Methods (cont’d) • java.util.List • add • size • get • set • iterator • listIterator • java.util.ArrayList • All List methods • add • remove
Standard Library Methods (cont’d) • java.util.LinkedList • addFirst • addLast • getFirst • getLast • removeFirst • removeLast
Standard Library Methods (cont’d) • java.util.Set • add • contains • remove • size • iterator • java.util.HashSet • java.util.TreeSet
Standard Library Methods (cont’d) • java.util.Map • put • get • remove • containsKey • size • keySet • java.util.HashMap • java.util.TreeMap
Standard Library Methods (cont’d) • java.util.Iterator • hasNext • next • remove • Java.util.ListIterator • add • set
Online resources • Acorn online • Java API