Geek Culture
Published in

Geek Culture

All of AP Computer Science A: Part 1

Everything you need to know to get a 5 on the AP CSA exam, from start to finish.

Huge disclaimer: in no way am I claiming that this is a guaranteed way to get a 5; no one can, and if anyone does then they are either scamming you, or have many caveats, which is still scamming you. Your odds of getting a 5 are determined by the amount of effort you put in to learning and understanding the content. Finally, this is meant as a brief gloss over the entire course. Use it as a review, or as a way to get started, but not as the only resource you ever use.

  1. Basic Structure of a Java File
  2. Variables and Scopes
  3. Int, Long, Double, Float, Boolean (and Char)
  4. Input and Output
  5. Strings
  6. Loops and Conditionals
  7. Arrays and ArrayLists
  8. Functions (finally!) and Recursion
  9. A brief rundown on Object Oriented Programming (for those stressed on time)
  10. Object Oriented Programming

This post only covers chapters 1 through 3.

I’m positive that there is something here that I am missing, and I’ll keep updating this blog as needed.

The order that I’ve chosen is not the same as the order that AP provides; however, I believe that this order is easier to understand.

Without further ado, let’s get started!

Chapter 1: Basic Structure of a Java File

Here, we observe the basic Java file in its natural habitat:

A little file, in a great big folder

Yeah, that’s basically all for now. In chapter 2, we will understand what the public keyword means. In chapter 8, we will learn what the heck static void main(String[] args) is and does.

What I’m trying to say is: take what I’ve written above at face value. For now, the first 2 lines and the last 2 lines are as shown above, and the code goes in the middle.

Chapter 2: Variables (and Scope)

Almost everything in Java is a variable. This chapter will conceptually go over what a variable is, and the next chapter, we will actually define a variable

Let me give a definition

A variable is name with a reference to some value or object.

Pause: Did you understand that? If so, you can skip the entire chapter, and move on to chapter 3. If you didn’t get that, keep reading.

In other words, a variable is a piece of paper, with an id (a name), and an address (the reference). If you were to travel to that address, you would find a house (the value or object).

Terminology:

  • Assign a value to a variable: create a house at a given address, and write that address on a the slip of paper (the variable).
  • Modify the value of a variable: change the house, or some properties of the house. Note that the address is not changed.
  • Change the value of the variable: create a new house at a given address, and write that address over the previous one on the slip of paper (the variable)
  • Assign the value of one variable to another: simply copy over the address from the first slip of paper to the second.

Progress Check 2.1: I want to store a value, say the number 3, and assign it to a variable, say x. Then, I want to assign the value of x to a new variable y. Now, I modify the value of x to be 5. What is the value of y? If I change the value of x back to 3, what is the value of y?

Chapter 3: Int, Long, Double, Float, Boolean (and Char)

It’s time to introduce the primitive datatypes. There are 6 primitive types you will need to know for the exam (there are also just 6 primitive types in general). These are: the Integer, the Long, the Float, the Double, the Boolean, and the Character.

Ok, now we know these primitive types, but how to we use them? We assign them to variables

In Java, all variables have a fixed type; the variable can hold only integers, or only floats, or only booleans, etc.

  1. Integers: numbers like -3, -2, -1, 0, 1, 2, 3
  2. Long: same as integers, but can store bigger numbers
  3. Float: decimals like 2.5, -3.75, 3.1415
  4. Doubles: same as floats but can store higher precision decimals.
  5. Booleans: a true or false value
  6. Characters: a single ascii letter, like a or 3. Note that for special characters, like the space character or the newline character, a backslash is needed, followed by a special code. \n means newline, \t means a tab, and \\ means a regular backslash.

We specify this type right before giving the name of the variable. For instance:

A slightly bigger little file in a slightly smaller great big folder

First, we defined the type: int. Hopefully, you could tell that that meant integer. Next, we give the variable a name: myVariable. Finally, we set it equal to 3 by using the =. Note that this gets a bit confusing; = means assignment. It does not mean the left is equal to the right. Finally, a semicolon tells Java that the line is over. DON’T FORGET THE SEMICOLON EVER

Let’s see how to create each primitive datatype.

Look mom, I got a growth spurt!

And that’s pretty much it! Your school should cover how to modify these primitive types, and if they don’t then drop a comment and let me know, and I’ll be sure to add it.

That’s it for chapters 1, 2, and 3. In the next post, I’ll cover chapters 4 and 5. I’ll put the link here when it’s posted, so stay tuned for that!

If you did enjoy reading this, be sure to clap, and leave a comment!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store