The AP Java Subset

41
The AP Java Subset Topics

description

The AP Java Subset. Topics. A Topics. Primitive Types. int double boolean. Operators. +, -, *, /, % ++, -- = +=, -=, *=, /=, %= ==, !=, , = &&, ||, !. Numeric Casts. (int) (double). String Concatenation. + - PowerPoint PPT Presentation

Transcript of The AP Java Subset

Page 1: The AP Java Subset

The AP Java Subset

Topics

Page 2: The AP Java Subset

A Topics

Page 3: The AP Java Subset

Primitive Types

int double boolean

Page 4: The AP Java Subset

Operators

+, -, *, /, % ++, -- = +=, -=, *=, /=, %= ==, !=, <, >, <=, >= &&, ||, !

Page 5: The AP Java Subset

Numeric Casts

(int) (double)

Page 6: The AP Java Subset

String Concatenation

+ will convert numbers to strings and invoke

the toString() method on objects

Page 7: The AP Java Subset

Escape Sequences

\\ \” \n

Page 8: The AP Java Subset

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

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

Control Structures

if if/else while for return (do/while, switch, continue, break – not

tested)

Page 11: The AP Java Subset

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

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

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

Comments

// single line comments /* */ block comments No Javadoc comments

Page 15: The AP Java Subset

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

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

Super

Use to invoke superclass constructor– ex: super(args);

Or to invoke superclass method– ex: super.method(args);

Page 18: The AP Java Subset

Constructors

Be able to implement Initialize all instance variables Don’t need to know default rules

Page 19: The AP Java Subset

Extend & Implement

extend classes implement interfaces Know inheritance!!!

Page 20: The AP Java Subset

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

Equals

Know when to use == or .equals Objects: equals Identity: ==

Page 22: The AP Java Subset

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

Packages

import statement import package.subpackage.class;

Page 24: The AP Java Subset

Exceptions

NullPointerException ArrayIndexOutOfBoundsException ArithmeticException ClassCastException IllegalArgumentException

Page 25: The AP Java Subset

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

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

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

Standard Library Methods (cont’d)

java.util.ArrayList– size– add– get– set– remove

Page 29: The AP Java Subset

AB Topics

Page 30: The AP Java Subset

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

Abstract Classes

AB students are expected to design own interfaces and abstract classes

Page 32: The AP Java Subset

Throwing Unchecked Exceptions

IllegalStateException NoSuchElementException

Page 33: The AP Java Subset

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

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

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

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

Standard Library Methods (cont’d)

java.util.LinkedList– addFirst– addLast– getFirst– getLast– removeFirst– removeLast

Page 38: The AP Java Subset

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

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

Standard Library Methods (cont’d)

java.util.Iterator– hasNext– next– remove

Java.util.ListIterator– add– set

Page 41: The AP Java Subset

Online resources

Acorn online Java API