Developer Blog, Tutorials

Interactive MNIST

Welcome back! This marks the first deep learning blog post on this developer blog!

Today I’ll teach you step by step how to create this site. There are multiple steps we need to go through to create this classifier:

  1. Pre-process the MNIST dataset.
  2. Build and train the classifier model.
  3. Converting our model to Tensorflow.js format.
  4. Create an area for users to write numbers.
  5. Load the model into the browser.
  6. Run predictions off of user input.

The project source code can be found here.

Before we start let’s install some requirements for the backend. Run this in your terminal to install all the required libraries

$ pip install tensorflow tensorflowjs scikit-learn

Pre-processing the MNIST dataset

The Modified National Institute of Standards and Technology database (MNIST database) has the largest database of handwritten digits that is essentially the “Hello World” of machine learning. Running a Convolutional Neural Network (CNN) off of this dataset is simple and can yield great results.

100 images from the MNIST dataset

Let’s explore the dataset. The dataset has 60,000 images of size 28×28 pixels. They are in black and white, so they only have 1 extra dimension. The dimensions of our input are thus (28, 28, 1).

If you’re curious about how neural networks work then check this amazing video by 3Blue1Brown:

Thankfully this dataset is by default packaged with Tensorflow, so we don’t need to install it from anywhere else. Let’s start writing our model.py file.

import tensorflow as tf
from sklearn.preprocessing import OneHotEncoder  # For later

Next we’ll load the MNIST dataset from Tensorflow.

(X_train, y_train), (X_test, y_test) = tf.keras.datasets.mnist.load_data()

Here, we are utilizing Python’s method of unpacking variables. By default when we call tf.keras.datasets.mnist.load_data() we will be returned 2 tuples of 2 lists of arrays. For ease, we are unpacking all of this in one statement. We are returned NumPy arrays that represent the images of handwritten digits

If we were to print the shape of X_train we would get returned (60000, 28, 28). We want to have the inputs to be of shape (60000, 28, 28, 1) for the CNN later.

input_shape = [28, 28, 1]

X_train = tf.reshape(X_train, [X_train.shape[0]] + input_shape)
X_test = tf.reshape(X_test, [X_test.shape[0]] + input_shape)

X_train = tf.cast(X_train, dtype=tf.float32)
X_test = tf.cast(X_test, dtype=tf.float32)

X_train /= 255
X_test /= 255

This block converts our shape into the (60000, 28, 28, 1) we are looking for by utilizing tf.reshape().

Line 1: We start off by defining what our target input shape is. We will save this in a list rather than a tuple so that we can use the variable in lines 3 and 4.

Lines 3-4: In lines 3 & 4, we reshape our X_train and X_test NumPy arrays. We use tf.reshape(array, shape) to reshape our array. For flexibility we won’t hardcode 60,000 into our input_shape because this value can change. Instead, we will use the first value of the shape of X_train and X_test respectively. By adding the 2 arrays together, the reshape function will reshape the old array to our desired (60000, 28, 28, 1). This returns a Tensor object, which is computationally different from a NumPy array.

Lines 6-7: We want to ensure that our values in the arrays aren’t whole numbers because our model will have a hard time to learn it. To remedy this we cast the reshaped X_train tensor to be of type tf.float32 which is just a 32-bit float number.

Lines 9-10: We will normalize the tensor so that the values will be between 0 (black pixel) or 1 (white pixel) and all values in between.

With this, we’ve prepared our inputs. Now to prepare our outputs!

y_train = tf.reshape(y_train, [-1, 1])
y_test = tf.reshape(y_test, [-1, 1])

encoder = OneHotEncoder(sparse=False)

y_train = tf.convert_to_tensor(encoder.fit_transform(y_train))
y_test = tf.convert_to_tensor(encoder.fit_transform(y_test))

Lines 1-2: We prepare the label arrays to be One Hot Encoded.

Line 4: We initialize the OneHotEncoder provided to us by sklearn.preprocessing and assign it to a local variable, encoder.

Line 6-7: We create a tensor off of one hot encoding done by our encoder.

With this done, we are ready to create the model and train it!

Build and Train the Classifier Model

We’ve prepared our data, now let us create a model that can actually use the data efficiently. With the model architecture I’m providing I get a 98.84% validation accuracy after training for 10 epochs with a batch size of 32. If you want to use your own model here, that is completely fine, but make sure the shape is (28, 28, 1).

model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Conv2D(32, (3,3), activation="relu", kernel_initializer="he_uniform", input_shape=input_shape))
model.add(tf.keras.layers.MaxPooling2D((2,2)))
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(125, activation="relu", kernel_initializer="he_uniform"))
model.add(tf.keras.layers.Dense(10, activation="softmax"))

Line 1: We use a Sequential() model from Tensorflow.

Line 2: Our input layer is a Conv2D layer that has 32 neurons, a convolution filter of shape (3, 3), using a relu activation function and he_uniform to initialize the neurons. Since this is the input layer, we pass the argument input_shape=input_shape, since we have input_shape defined above to be [28, 28, 1].

Line 3-5: We build the hidden layers of the model ending with a Dense layer with 125 neurons and using the same functions as the input layer.

Line 6: We add the output layer which is a Dense layer with 10 neurons (representing our 10 outputs, 0-9) and using softmax activation.

Now that we built the model, let’s compile it!

opt = tf.keras.optimizers.SGD(lr=0.01, momentum=0.9)
model.compile(optimizer=opt, loss="categorical_crossentropy", metrics=["accuracy"])

Line 1: We create a Stochastic Gradient Descent (SGD) optimizer with a learning rate of 0.01 and momentum of 0.9 as our optimizer of choice. I don’t use the “ol’ reliable” Adam() optimizer because the Adam optimizer has a chance to not converge which shouldn’t be an issue in this dataset but I would still use SGD. The choice is up to you, the reader, and if you’re still interested in this, you can check out this article.

Line 2: We compile our model with our SGD optimizer, and record loss with categorical_crossentropy. Since we have all classes represented in this dataset (meaning there are roughly equal images for all numbers in this dataset)

Now with a compiled model, here comes the fun part… training the model! Don’t worry, this model doesn’t take too much time to train. On my 2018 Mac Mini (6-core Intel i5) it takes 100 seconds, or a little over a minute.

h = model.fit(x=X_train, y=y_train, epochs=10, validation_data=(X_test, y_test), batch_size=32)
model.save("model.h5")

Line 1: We combine everything we’ve done above to train the model with 10 epochs and a batch size of 32.

Line 2: We save the model we trained as model.h5

This marks the end of needing to use Python for our project. Yes we could have done this in Tensorflow.js, but I’m more familiar with Python and I want to leverage the converter that Tensorflow.js provides

Converting our model to Tensorflow.js format

We got a model saved as model.h5, but Tensorflow.js won’t be able to leverage this, so we will convert our model.h5 to Tensorflow.js format. To do this, assuming you installed tensorflowjs like instructed in the start of this article, you can run this command in the terminal:

$ tensorflowjs_converter --input_format=keras /path/to/model.h5 /path/to/destination 

Since we used Keras to create our model, we have to specify this to Tensorflow.js when converting.

After doing this we will be able to work on the front end.

Creating a writeable area for users

Let’s take a break from all this machine learning tasks and focus on creating a frontend environment for our users.

First we start in index.html,

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Interactive MNIST</title>
    <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.0.0/dist/tf.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.0.0/p5.min.js" integrity="sha512-At/xiUTqCg8jxnCMRNDhDVDm4qxlyPt1K+GrDhUvRvR8MjlBq0RH65OVVaCXn3OuvyVWK8CdlQpxgrc/5YspHw==" crossorigin="anonymous"></script>
</head>
<body>
    <button id="guess">Guess</button>
    <button id="clear">Clear</button>
    <p id="out"></p>
    <script type="text/javascript" src="index.js"></script>
</body>
</html>

We import the tensorflow.js and p5.js JavaScript files in the head of our document, then create 2 buttons, one to send off to the model to guess what the user drew, and one to clear the drawing area. After that we add an empty tag that will host our output. Lastly, we import the script that we are going to create.

Speaking of which, let’s work on index.js,

function setup(){
    let canvas = createCanvas(280, 280);
    background(0);
}

function draw(){
    strokeWeight(24);
    stroke(255);
    if (mouseIsPressed){
        line(pmouseX, pmouseY, mouseX, mouseY);
    }
}

If you’re familiar with p5.js you’ll understand the importance of the function names having to be setup and draw, as if they were any different, they wouldn’t be called. Now let’s break down what’s happening in each function.

setup(): We create a p5.js canvas object of size 280 by 280 pixels. We then set the background color of the box to be black (to match the dataset, we will be drawing in white).

draw(): This is what allows us to draw. We set the strokeWeight which is essentially the thickness of what we draw. For the photos in this tutorial I used a weight strokeWeight of 8, but when I revisited it, I founded that I need to change the strokeWeight to 24. If the stroke isn’t too thick, then during resizing the image, the input will lose details. Then we set the color of the stroke, and as said before we set it to be white. Then we add the condition that if the mouse is pressed, then draw a line at the mouse coordinates.

Now this is all you need in the file to have the drawing capability, and you might be confused because a lot of variables and functions aren’t defined in my index.html file, but thats all taken care of by p5.js. If your IDE shows an error, keep on writing and check if it is a real error in the Developer Tools Console of your browser.

At this stage, your site will look something along the lines like this:

Our barebones site!

And you can write on it if you click and drag within the black box.

Say hello back 🙂

Load the model into the browser

Now for this step you must understand the consequences of using Tensorflow.js to load a model. It must be hosted somewhere. It can’t locally use the files on your computer. The options to load your model are defined in the docs. For my file hosting, I used GitHub Pages, and I suggest you do as well.

For this article you can load the model however you see fit, but if you want to host it on GitHub Pages, you can take a look at my repository to see how I did it (while you’re there be sure to star the repo and follow me :D). Be sure to also have at least 1 commit where your model (in .json format is on the repo)

Now with that out of the way, let us get our model that we worked so hard on into the browser. Editing our index.js file, we will add this to the start of the file:

let model = null;

let loadNeuralNet = async () => {
	model = await tf.loadLayersModel('type://your/storage');
}
loadNeuralNet().then(r => console.log("Model Loaded."));

// setup() and draw() ...

We start off by making model a global variable so that we don’t need to pass it as arguments. We need to use an asynchronous function loadNeuralNet() because tf.loadLayersModel returns a promise, so we need to get the actual model loaded. After creating the function, we can simply call it and then use .then to provide us confirmation that we loaded the model.

Congratulations our model is loaded in the website, and if you open your console you should see the Model Loaded. message. Let’s get on to using the model now.

Run predictions off user input

Let’s start off by making the buttons added a while back actually useful. We will first made the Clear button have some use.

//...

let out = document.getElementById("out");

document.getElementById("clear").addEventListener("click", () =>{
    background(0);
    out.innerHTML = "";
})

We start by getting our output area which is another global variable that we will use later. Next we add an event listener to the Clear button. When the button is clicked we are essentially setting the background of our p5.js canvas to be black (but in reality clears the canvas) and clear any output from previous runs. Now let’s address the elephant in the room. The Guess button:

//...

document.getElementById("guess").addEventListener("click",() =>{
    const input_length = 28 * 28;
    let inputs = [];
    let img = get();
    img.resize(28, 28);
    img.loadPixels();
    for (let i = 0; i < input_length; i++){
        let bright = img.pixels[i * 4];
        inputs[i] = bright/255.0;
    }
    let predictions = predict(inputs);
    console.log(predictions);
    out.innerHTML = "The computer thinks you've drawn a " + predictions[0];
});

This is significantly larger, but still understandable.

Line 3: We add another event listener similar to the Clear button, but we have a different function to run when clicked.

Line 4: We create a constant that stores the value of the product of our input_shape that we used when creating the model.

Line 5: Initialize an empty array that we will use to predict on.

Line 6-8: p5.js provides a get() function that essentially grabs the image created at the instant the user clicks Guess. After that, we resize the image from our previous 280 x 280 pixels to 28 x 28 pixels (sounds familiar doesn’t it ;)). After that we use the function loadPixels() to get all the pixel values of the image the user draws. All of these functions are done in place, so we don’t need to set img = img.resize(28, 28); and such.

Line 9-12: We create a for loop to add info to our inputs array. We then find the brightness of a pixel. Since p5.js stores its pixels in RGBA format, we need to access that A which stores the info that we care about, so we index it at i * 4. Then we add the pixel to the inputs array after normalizing it to be between 0 and 1 and all decimals in between.

Line 12-15: We then find the predictions by using predict() which is a function that will be introduced next. After that we log the prediction into the console and then change our out area to output our predictions. We use predictions[0] for reasons that will be clear when we introduced the predict() function.

Now let’s write the predict() function we’ve heard so much about.

//...

let predict = (inputs) => {
    let tensor = tf.tensor(inputs, [28, 28, 1], "float32");
    tensor = tf.expandDims(tensor, 0);
    let outputs = model.predict(tensor).dataSync();
    let predictions = Array.from(outputs).map(n => parseFloat(n.toPrecision(5)))
    return [max(predictions), predictions];
}

Line 3: Declaring our predict() function and requiring an argument (which will be the inputs from our previous code)

Line 4: We create a tensor using the tensorflow.js library since that is what is required to use for predictions. We give tf.tensor() the array we want to be a tensor, then the input shape (for our model), as well as the data type (which is good ol’ 32-bit float values)

Line 5: We expand the dimension of our tensor because the model will expect a tensor of shape (1, 28, 28, 1), and since we don’t want to screw up the data we can’t create a tensor of that shape like in line 2. But we can use expandDims() to create that extra dimension we need.

Line 6: This is the best part! We finally predict with our model! After running model.predict(tensor) we need to call .dataSync(); to get the data in a format we can use.

Line 7: Now we create an array that will contain 10 values (which are the probabilities of each class). Since it’s an array we can use it’s built in functions

Line 8: Now we return an array with 2 elements, the final prediction and the predictions array entirely. I’ve done it this way because I want to incorporate a bar graph in the future showing the relative probabilities of each class, but this is optional to you.

Final Thoughts

You’re done! You’ve created a way to interact with machine learning that can work on desktop, phone, or tablet! Now all that’s left is to clean it up and make it look presentable. This is all up to your own taste however, so I’ll leave it to you. If you want inspiration you can check out my code. There are a few things you need to keep in mind when making a pretty frontend however:

  • The id of both buttons are important, so if you change it in index.html you need to change it in index.js as well in the event listeners.
  • If you want to change the size of the writing window, ensure that it can be resized to 28 x 28.
  • Be careful if you change the colors of the stroke or the background, that may lead to problems with prediction later on.
  • Be creative and unique!

NOTE: The model will tend to be inaccurate. This is not because of training, rather it is likely because of the input. When checking the 28 x 28 images, I have noticed many imperfections that the model has to deal with. Do try and change model architecture and how you train it if you are unsatisfied. Just remember the input shape has to be (28, 28, 1) if you decide to use this frontend code.

If there are any questions leave them in the comments and I’ll try my best to answer them.

UPDATE: Upon revisiting the site after witnessing the model to be inaccurate, I realized that the model wasn’t the issue, rather it was the inputs that we give the model. Let’s compare 2 images. One is the input for the model while the other is what we give the model (assuming strokeWeight(8); in our draw() function).

Training Data
User Input

Look closely between the two images. Our training data trains the model using a thicker brush. Our input however is like drawing with a pencil. This small difference may not seem like much to us as humans, but remember a computer runs on numbers. Each and every shade of white on each of the 784 pixels are important in order for the model to perform well. To remedy this I tried upping strokeWeight and thankfully when I used strokeWeight(24); instead of the old strokeWeight(8); I got much more accurate responses.

Training Data
strokeWeight(8);
strokeWeight(24);

With this small adjustment I’ve noticed the model behaves a lot better towards user input. Though it is not that close to our training data, we can simply up the strokeWeight, and I’ve noticed that using 32 behaves better than simply 24.

Tutorials

Acing AP Computer Science A | What is Java?

Welcome back! In this article we are going to be talking about what exactly is Java, and why do we use Java for AP CS A?

I’m sure that you’ve heard of multiple programming languages before, like Python, C/C++, PHP and so on. 700 programming languages exist, so why does CollegeBoard use Java only?

Well in this part of the series we are going to take a look at exactly that. But to do so I’ll need to define some simple terms that I will use throughout this article:

  • Virtual Machine – A computer that lives on your computer. (This is an oversimplified definition)
  • Execute – A computer or machine that carries actions dictated by given code
  • Run – Interchangeable with execute (see above)
  • Shell – A program that takes commands from the keyboard and gives it to the programming language to execute.
  • Source Code – Code that you have written.
  • Machine Code – Code that computers understand
  • Execution Flow – Steps the machine takes to run source code that you wrote

With those out of the way, let’s get started! In this article we will be talking about:

  • What is Java?
    • What is a high-level programming language?
    • What is an object oriented programming language?
    • What is a statically typed programming language?
    • What is an interpreted programming language?
    • What is a compiled programming language?
  • Why should we use Java?

I know it seems like a lot of reading, but I promise it won’t be that much. These topics aren’t covered on the AP exam, but I feel that it is important to know what you’re working with before you start working with it.

What is Java?

Java is a high-level, compiled, object-oriented, and statically typed programming language. I know, it is a lot of words that you likely aren’t familiar with. In this article we will go over each of the words that I described above, and by the end of this you should be able to understand what I just said.

Java was developed by Sun Microsystems (now acquired by Oracle) in 1995. Java’s main goal was to let programmers write once, run anywhere (WORA). We will see why this was a core philosophy of programming languages later in this article.

Today, Java has released its 14th version to the public, and over 3 billion devices use it. It’s a popular language, and we will discuss why it is later in this article as well.

What is a high-level programming language?

Before we tackle this definition, let’s talk about computers. As you may already know, computers don’t comprehend commands like we do in English, it uses binary. You may be familiar with what binary is, essentially 1 or 0 (computers don’t actually use the numbers that we know, but we assign numbers to it for simplicity. In reality computers use states of high power, or 1, and low power, or 0). Our computers use these 2 states to do everything. This means to program a computer, it must eventually be done in 1s and 0s.

But this is really inefficient. Imagine programming with purely 1s and 0s. To write my first name in binary, it would look like this: 0100000101101110011010010111001101101000

That’s where a high-level programming language comes in. A high-level programming language is a language that allows humans to write code that will be converted to machine code (essentially a couple steps from binary) where it can run.

Java, Python, R, PHP, C++ are all considered to be high-level programming languages.

You might be wondering, how do we convert code that humans write into code that machines can understand? Well it can be done by interpreting or compiling the code.

What is an object oriented programming language?

In a short form, an object oriented programming (OOP) language is a language focused on programming with objects.

Objects are a customizable way to store and represent and handle data. If you don’t understand this that is fine, the AP CS A curriculum involves working on objects in Java, so we will get into this in more depth later in the series.

Most modern programming languages like Java, Python, C++, and Ruby are all examples of object oriented programming languages

What is a statically typed programming language?

A statically typed programming language is where you have to declare your data types manually. We will understand this more in the next lesson about Unit 1, but just know for now that statically typed programming languages make understanding code much much simpler.

Java, C, and C++ are examples of statically typed programming languages.

What is an interpreted programming language?

We saw that a high-level programming language needs a way to turn into machine code. One of the ways is via an interpreter.

Think of this scenario, you are a chef who found a recipe for the best food in the world. Problem is, the recipe is in pure gibberish.

You need to cook this recipe for “personal fulfillment” so you desperately try to get the recipe translated so you can actually cook it.

Luckily your friend speaks fluent gibberish. With him at your side, you are able to translate the recipe step by step. He’d translate a line of the recipe for you, then you’d cook whatever he said. This would repeat until you’re done with the recipe. For this entire process, you need him at your side.

This is a crude example of an interpreted programming language. An interpreted programming language does exactly as you type. It goes line by line in your code doing the following:

  • Read the line
  • Translate the line to machine code
  • Run the machine code line
  • Move to next line and repeat

PHP, Ruby, Python, and JavaScript (JavaScript is not related to Java!) are all considered interpreted languages.

Pros of an Interpreted Language
  • Very flexible*
  • Dynamic
  • Likely has a shell
Cons of an Interpreted Language
  • SLOW

What is a compiled programming language?

Let’s go back to the recipe example. Before finding your friend, you realize that Google Translate can actually translate gibberish into English.

Perfect! You can use this to translate your entire recipe into something you can understand!

After translating the entire recipe into English, you don’t need Google Translate anymore. You can make the food as many times as you want as long as you have the translated recipe.

This alternate approach to our recipe problem roughly depicts how a compiled programming language works. A compiled programing language translates all of the source code into machine code. After it translates it all, it then executes the compiled machine code.

C/C++, Go, Haskell, Rust, and Java are all considered to be compiled programming languages.

Pros of a Compiled Language
  • Compiled code runs very fast
  • Typically statically typed
Cons of a Compiled Language
  • Needs time to compile the source code first
  • Completely dependent on the platform

Now let’s talk about that last part of the cons. “Completely dependent on the platform”? Well that boils down to what is running the code. Are you on a phone executing the code or on a computer? Each platform needs its own machine code built for it.

Let’s talk about C++ for a bit, its a very popular compiled programming language. C++’s execution flow starts off with your source code. Using a compiler, it converts your source code into machine code. That code can be run on your computer that you compiled the code on.

That’s cool but what if I wanted to make it say a phone app, will the machine run on the phone? Nope. In order to run your source code on a phone, you’ll need to recompile the code for the phone compatibility. And with this compiled code for the phone you can’t run it on anything else thats not that platform, like your computer.

Naturally this is very confusing. It’s also very inefficient. This is why Sun Microsystems decided to follow the WORA philosophy.

But Java is a compiled language, how does it behave differently than C++? Well that’s Java’s secret, it compiles its source code not into machine code for a computer, it compiles its source code into machine code for the Java Virtual Machine (JVM).

“Woah! That’s cool, it translates it into virtual machine code, but how is that beneficial to me?” Well if you recall, interpreted programming languages don’t have the same pitfall as compiled languages, so after compiling the source code into JVM code, the JVM interpreter interprets the JVM code into instructions for your computer.

By adding the JVM, Java is able to run on any platform as long as a JVM is installed on it. Sun Microsystems realized this and brought it to life. With a simple intermediary step in the execution flow, Java is able to be a WORA language. You’d only need to compile it once and it’d run on any system with JVM installed.

Why use Java?

I’ve gone through a lot and you might be wondering what is the point of using Java still. I’ve explained the big ideas about it, but what makes it so appealing to CollegeBoard that they have an entire class dedicated to it?

Java is very, very popular. As I’ve said before, Java runs on over 3 billion devices. Because its a “universal” language, Java can be used for many applications, few including:

  • Phone Applications (Android is built on Java)
  • Video Games (Minecraft)
  • Web Development (Used for backend and server side technologies)

Because Java has a wide reach, it’s become well integrated into the IT industry. Finding an IT job that doesn’t require even basic knowledge in Java is really difficult. Because of this need in the IT industry, it makes sense that CollegeBoard tries to get us ready for the industry by teaching us one of the world’s most popular and important programming languages.

Thanks for tuning in to this article, the next one will be starting the AP CS A curriculum. We will be talking about Unit 1: Primitive Types.

Tutorials

Acing AP Computer Science A | Introduction

Hello! Welcome to what I hope to be an informative tutorial series on how to do well on the AP Computer Science A exam offered by CollegeBoard.

In this introductory article, I aim to provide general knowledge about the AP Computer Science A course and provide grounds on which we can build on and learn.

In this article, we will be talking about:

  • The AP Computer Science A course offered by CollegeBoard
  • My Goals for these tutorials
  • What I’ll be covering in these tutorials
  • Pre-requisites for this series

The AP Computer Science A Course

The AP Computer Science A course is composed of 2 major things: programming in Java, and how to think like a programmer. 

Now, you might be wondering what it means to program in Java and to think like a programmer. Well, let’s break it down.

CollegeBoard requires students enrolled in the AP Computer Science A course (which we will refer to as AP CS A or just AP CS) to be familiar with 10 units:

  1. Primitive Types
  2. Using Objects
  3. Boolean Expressions and if Statements
  4. Iteration
  5. Writing Classes
  6. Array
  7. ArrayList
  8. 2D Array
  9. Inheritance
  10. Recursion

You may not understand one or even all of these units. Don’t worry; throughout the series, I will ensure that I will cover and teach all units listed above.

But what about the “thinking like a programmer” part of the AP CS A course? Well, CollegeBoard has also outlined 5 elements to this part:

  1. Program Design and Algorithm Development
  2. Code Logic 
  3. Code Implementation
  4. Code Testing
  5. Documentation

There won’t be specific questions based on the above elements, but the form of questions and the answers will align with one of those topics.

(ex. “What is the output of this program?” falls under the second and fourth element)

If you want to learn more about the AP CS A course as outlined by CollegeBoard, click here.

My Goals for this Series

In this series of articles that I will release, I hope to teach you the content for the AP CS A exam in the simplest way possible. I also hope to help you build interest in programming. Programming is more than just sitting behind a computer typing away. Its a way of thinking, a form of problem-solving that if you can pick up can help in other aspects of your life. I also want to help you understand how and why some aspects of programming are implemented the way that they are. 

What I’ll be Covering in these Tutorials

In these tutorials, you should expect to learn:

  • What is Java, and why should we use it?
  • Units 1 to 10 as outlined above
  • Tips & Tricks
  • How to think like a programmer
  • Things to watch out for on the AP CS A exam

Pre-requisites

The AP CS A course will rely heavily on algebra 1 concepts. So naturally, you should have completed or should be familiar with algebra 1 going into this course. My school requires calculus before you can take the AP CS A class, but seeing from the test and the course, you don’t need to have more math knowledge than algebra 1.

None of these courses will teach you how to install Java, so you’ll need to have it installed for the upcoming classes. Here is an official tutorial for all operating systems, but you can find other tutorials to help you install Java.

Lastly, and this is optional, you can install an IDE (or Integrated Developer Environment). It’s like a text editor but built to make programming easier. The one likely recommended to you by CollegeBoard and probably your class is Eclipse. However, I personally recommend using IntelliJ IDEA Community EditionPlease note that on the AP CS A exam, you will have to handwrite your code, so don’t get dependent on your IDE.

Coursework for the class will be posted on my GitHub, so follow me there if you are interested!

The next article will be about What is Java? which will talk about well, what Java is. See you in the following tutorial!

Please note that I am not associated with CollegeBoard nor am I a verified teacher for AP CS A. I am a student that is trying to teach other students.

Featured image from Unsplash.