The only page you need to score 5 on the AP exam!

What's in the exam?
1)Introduction Java Language Features:
    -Variables, Types, Operators, If, For, While, For-each, return etc.

Every programming language starts with variables. A variable stores information. It could be a number, a text or a boolean(whether a statement is True or False). 
A type of a variable shows us what kind of information the variable holds. In Java there are two types of types;
    -Primitive types are the basic types of data: int, double, short, long, float, char, boolean and byte.

    -Reference types are types that reference objects: Strings, arrays, objects. Reference types store addresses. 

Now, if we want to do some operations on our variables, Java has really simple operators for this. Such as:
    -Arithmetic operators: +, -, *, /, %
    -Assignment operators: =, +=, -=, *=, /=, %=
    -Increment/Decrement operators: ++, --
    -Equality, Relational, and Logical operators: ==, !=, <, <=, >, >=, !, &&, ||

    Remainder: System.out.println("Hello");
    -\n: prints to new line
    -\": prints double quote
    -\\: prints backslash

Okay variables are done. One of the most crucial part of the exam is loops. There are three kinds of loops;

    -For loop
    -While loop
    -For-each loop

Loops are great. But my life saver in Java are the if-else statements. They are really simple and it's really easy to implement them into your code. I say a life saver because you can make the code do whatever you want with the if-else statement. It has a really simple syntax:

2)Classes and Objects:
    I want to make cupcakes. I want chocolate cupcakes with white frosting and colourful sprinkles. These will be the specifications or the templates of my cupcakes. This will be the class. If I bake cupcakes, those would be the objects.
Constructors help you create an object how you would like them.
Methods are your machine functions. For example: Setting your oven to 100 degrees or opening your browser on your computer.
Math is a default Java class with the method pow, which returns us the second power of a.
Method overloading
Method override
3)ArrayList vs Arrays:
Arrays and ArrayLists are lists of things. But they are different:
    -Arrays have fixed lengths while ArrayLists don't.
    -ArrayList can only be in reference type while arrays can also be primitive.
    -They have different methods to do the same thing.

4)Sorting and Searching:
    -Selection Sort, Insertion Sort, (More efficient: Quick Sort, Merge Sort), Sequential Search, Binary Search
     Selection Sort: This is a "search and swap" algorithm. First, it finds the smallest element in the array and then exchanges it with a[0]. Then it finds the smallest element in the subarray from a[1] ... a[n] and replaces the smallest element with a[1]. It continues to do this until the list is completely sorted. The time it takes for this algorithm to sort any array for the worst case is given by t=n^2.

    Insertion Sort: In this algorithm, we start sorting with a[0]. We look at the next element, if a[0] is bigger than a [1], it switches their places. Then we look at the relationship between a[1] and a[2], as you would expect if a[1] is bigger than a [2], it switches their places.This goes on until the algorithm reaches to the end of the array. The time it takes for this algorithm to sort any array for the worst case is n^2.

    Merge Sort: While there is more than one element in an array:
            1)Break the array into two halves.
            2)Mergesort the left half.
            3)Mergesort the right half.
            4)Merge the two arrays into a sorted array.
        It continues to divide the array until each part has one element, and then it sorts the array using the insertion sort algorithm. The time it takes for this algorithm to sort any array for the worst case is log(n),which is faster than the previous ones.
     Quick Sort: This is the fastest algorithm,on average, known for large n. While there are at least two elements in the array:
            1)Divides the array from a random point.
            2)Quicksort the left half.
            3)Quicksort the right half.
        It continues to divide the array until each part has one element, and then it sorts the array using the insertion sort algorithm. This is faster than the prior because it does not have to sort the subarrays after merging them.

    Sequential Search: It basically checks every element until the desired element is found in the array.
    Binary Search: It divides the array in half and checks the middle element, then it divides the two subarrays again and checks the middle element until the desired element is found. This is way faster than sequential search.

5)AP Computer Science Standard Interfaces and Classes:
A class can inherit another class. The class that inherits is called a subclass, the other is called a super class. For example we have three classes: Person, Student, Teacher. About their relationship we can say that a Student is-a Person and a Teacher is-a Person. However, we cannot say that a Person is-a Student. This is called polymorphism.

Polymorphism is a mechanism that ensures that the correct method is called for an object disguised as a more generic type. To be more clear, lets imagine that we have a solid superclass which contains a cube class and a sphere class and both subclasses contain a getVolume() method which have different formulas. If we call, and assume that solids is an array that contains a number of cubes and spheres:
double volume = solids[0].getVolume(); 
In this case, the compiler knows which object solids[0] is and it will call its own get volume class. So polymorphism helps us deal with an array that contains more than one different type of object.

Why do we us polymorphism?
The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. An important thing to notice is that, also stated above, you don't have to know the exact type of the class you're using, just the base type (in this case, solids), and you will get the right result. This is very useful in more complex systems as well.

Back to properties of Classes in Java;

Java doesn't support multiple inheritance, so one class can only inherit another class. However it can implement multiple interfaces.
An interface is a reference type, similar to a class, that can contain only constants, method signatures, default methods, static methods, and nested types. We can say that interfaces are more abstract than abstract classes and that we have to define all methods in the interface.
An abstract class is a class that is declared abstract —it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed. When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class.
Why do we use an Abstract Class?
An interface is like a pure abstract class. Abstract class can be used as a base to ensure that every subclass has this function and implements it accordingly. 

Why do we an Interface?
The main use is polymorphism, or the ability to perform the same operation on a number of different objects. If different objects all implement the same interface and have the same method, you can store all of those objects in a Vector, for example, and iterate through the Vector calling that method on each one.

Abstract class vs Interface
By using abstract classes, you can inherit the implementation of other (non-abstract) methods. You can't do that with interfaces - an interface cannot provide any method implementations.

6)Case Studies(Labs): (Needed files are below)
    1)Gridworld: test

    2)Magpie Lab: This Lab is aimed to study the natural human language. Like a chatbox. You type a phrase and the computer comes up with an answer. It sounds really complicated and difficult.In fact it is really easy at this level. In my opinion all you need is a basic understanding of java and to use strings and if statements really well.
Main Goal: To be able to use strings, substrings and all its methods properly. Example questions can be found in the zip file down below. For this lab you can solve "Strings Quiz" and "String Quiz 2"

    3)Picture Lab: Working with 2D arrays and playing with the pixels of the images.

Online sources, tutorials and teaching available on this page. For help contact Mert Karakas. and are also great websites for practicing.
Mert Karakas,
Feb 23, 2015, 3:55 AM
Mert Karakas,
Mar 22, 2015, 8:07 AM
Mert Karakas,
Feb 13, 2015, 1:15 PM
Mert Karakas,
Mar 22, 2015, 8:19 AM
Mert Karakas,
Mar 22, 2015, 8:16 AM