AP® Computer Science—Semester A

The taming of the code.

  • Course Length: 18 weeks
  • Course Type: AP

Schools and Districts: We offer customized programs that won't break the bank. Get a quote.

Get a Quote

This course has been approved by the College Board, which indicates that the syllabus "has demonstrated that it meets or exceeds the curricular expectations colleges and universities have for your subject." Please contact sales@shmoop.com if you would like to add this course to your official record of AP course offerings.

It has also been granted a-g certification, which means it has met the rigorous iNACOL Standards for Quality Online Courses and will now be honored as part of the requirements for admission into the University of California system.


So you want to learn to program. You've come to the right place. In the span of eighteen weeks, we'll take you from coding n00b to coding better than Matthew Broderick.

Except…without accidentally starting World War III.

There are plenty of tutorials out there willing to teach you all the surface-level business of variables and loops, but there's so much more teeming beneath the surface. In order to really know how to program, you're going to need a strong foundation in logic and computer memory from an advanced Comp Sci course like this one.

Pats back.

But don't get daunted, Shmooper—you don't even need to know a line of code before starting this course.

After catching the basics, we'll move on to bigger topics, like

  • object-oriented programming.
  • sorting algorithms.
  • recursion.
  • software engineering.
  • computer ethics.

But wait: that's not all. You'll also be applying all your knowledge to programming projects—both big and small. Think of them like proof of all the knowledge you've gained from the course.

Next step: hacking the main frame. But for now, let's learn some programming basics.

Oh, by the way: this is a two-semester course. You're looking at Semester A.

AP® is a trademark registered and/or owned by the College Board, which was not involved in the production of, and does not endorse, this product.


Unit Breakdown

1 AP® Computer Science—Semester A - Get with the Program

In this unit, we aren't assuming you know anything about programming (no offense, Shmooper). We'll start with a conversation about why you're learning to program and what being a computer scientist means. Then we'll get you set up writing your own programs. By the end, you'll be using Java to print words to your computer screen like a pro.

2 AP® Computer Science—Semester A - Logic and Conditions

According to the computer, there are no sort-ofs or maybes. To get you ready for all the yes-or-no instructions you'll have to give, we're going to talk about the logic invented by our good friend George Boole. After learning the theory, you'll be putting it all into practice by giving the computer conditional instructions. The things you'll be able to do are…un-Boole-ievable. (Cringe.)

3 AP® Computer Science—Semester A - Loops

Sometimes, a Shmooper needs to repeat code over and over again. You could copy and paste the code, but why do that when you could use some syntax that will run it as many times as it needs? Once you start adding loops to your code—changing up factors like the number and order—you'll turn a finite number of lines into an infinite list of instructions for the computer.

4 AP® Computer Science—Semester A - Making Lists and Leaping Dimensions with Arrays

You're going to start having bigger and badder data, so you better have a way to store it. In this unit, you'll learn about Arrays—and their big brother, ArrayList—to help keep your stuff nice and organized. Organizing other parts of your life? You're on your own for that one.

5 AP® Computer Science—Semester A - Methods and Objects

Java's object-oriented, but up until this point you've been doing things…not-object-oriented-ly. You won't after this unit, though. We'll start talking about methods and classes, both of which will get your code looking cleaner and more readable in no time. And if that isn't enough, you'll also be learning ways to handle errors.

6 AP® Computer Science—Semester A - You Down With OOP?

We saved the best for last, Shmooper. Before the end of the semester, you'll be learning some object-oriented programming (or what the cool programmers call OOP). It's all about encapsulation, abstraction, inheritance, and polymorphism—and Java has a lot of tricks up its sleeve to help you program objectively. Or something like that.

7 AP® Computer Science—Semester B - The World of Recursion

From factorials to fractals, we'll be diving into the world of recursion, binary trees, and file systems. Stack overflows come free of charge.


Sample Lesson - Introduction

Lesson 1.03: Intro to the Java Language

A coffee mug with the words mocha java written on it
""I'll have a tall, half-calf, double skinny mocha; hold the COBOL.""
(Source)

As you may know, Java is an island somewhere in Indonesia, not far from Christmas Island or Kuala Lumpur, home to what used to be the world’s tallest buildings.

That Java has nothing to do with our Java, so stop asking about it.

We’re here to talk about the Java programming language, which also has nothing to do with coffee, so don't even start on that one. Despite its confusing name, Java has some pretty great things going for it, like

  • it has lots of measures in place to help you debug.
  • it has a clear orientation for writing code.
  • it encourages caffeine consumption (probably).
  • it's the language used on the AP Computer Science A exam.

We'll look at some of Java's best features, then get you squared away so you can run Java from the comfort of your own computer.

Then maybe we'll take a field trip to the island.


Sample Lesson - Reading

Reading 1.1.03a: Java Rocks

Travel back with us to the early 1990s. The Hubble Telescope is on its way to snap some epic pictures, persons still unknown have stolen $500 million of artwork, from a Boston museum, and Calvin and Hobbes are about to retire.

Meanwhile, James Gosling and a team at Sun Microsystems in California are creating a language to power an interactive handheld entertainment device. Ah, the memories.

We now know that device (whatever it was) didn’t quite pan out for James and his crew. However, the language they created lived on when people realize it had some pretty awesome features.

You can see a year-by-year summary of Java’s development here.

The Java programming language has evolved into an ideal language for developing business and personal applications. It has way more features than we'll be able to cover and can do some pretty amazing things. Don't worry: we only need to know a subset to hit all the important points.

There are almost as many good reasons to learn Java as there are actors waiting tables in Los Angeles. We only have room here for six (reasons, not actors).

Reason One: It Can Run Anywhere

Java is platform independent. Sun Microsystem developed Java so that it could be "written once, run anywhere." That means anytime you write in Java, you have to compile it down to bytecode, which lets the code run on any device with a Java Virtual Machine (JVM).

It sounds more complicated than it really is. Almost all devices, computers, phones, DVD players and Smart TVs run the Java Virtual Machine. Java even powers car navigation systems, ATMs, lottery machines, medical devices, and parking payment stations.

When they say anywhere, they mean anywhere.

Reason Two: It Powered the Interwebs

Even though Java isn't a buzzword on the internet any more, those Sun Microsystem folks developed it specifically for the web. They release the first version during the rise of the internet in 1996. The language is built around developing web-based applications, both for business and personal use.

Now it's all about JavaScript (and Ruby on Rails), which sounds like it should be a very similar language, but it really isn’t.

Reason Three: It's Super Classy

Java is object-oriented, which means it uses classes that represent real world objects. Classes are coded and tested separately, and then linked together to make a complete program. Because of the (some would call freakish) modularity, object-oriented programs are easier to debug than programs using other orientations—like procedural and functional languages—so they’re easier to maintain.

Reason Four: It's Simple

Dodge ball is a simple game. Throw balls at people. Don’t get hit by balls people throw at you. Simple, but not easy.

We've got the bruises to prove it.

Java is just like dodge ball—simple, but not easy. It's considered simple because the language was built to take care of lots of things for you. Case in point: garbage collection, which is a built-in feature of Java, takes care of computer memory so that you don't need to think about it.

In some languages, developers have to worry about assigning things to memory and then destroying them when they're no longer needed. The garbage collector in Java automatically recycles memory for reuse so you don't have to.

Now if only it'd save us from our psychotic gym teacher.

Reason Five: It's Free

Yes, you can put your wallet away: everything from the Java Development Kit (JDK) to its Integrated Development Environment (IDE) is free. We're going to set up your development environment pretty soon, and it won't cost you a dime.

Reason Six: It's Kind-of a Big Deal

Even today Java's sill being used. Google chose the Java language to power an obscure little operating system called Android. The irony in the language having originally been built for a multi-faceted entertainment device isn't lost on us.

Let's not get ahead of ourselves, though. Not everyone loves Java. Many programmers complain that it's overly verbose and complicated, like an annoying orange.

It's basically the tech equivalent of kale: you either love it or you hate it, but you can’t avoid it. It's everywhere.

Even if we just talk about games, we come up with some pretty popular titles.

If you aren't a gamer, so much of the world is powered by Java that it's hard to ignore. So let's get it set up on your computer.


Sample Lesson - Reading

Reading 1.1.03b: Setting Up Your Environment

To write programs in Java, you need to make sure you have an appropriate programming environment. You might already have it, but we’ll help you if you don’t.

As we said earlier, there are two kinds of programming environments. If you don’t remember that, then maybe we didn’t mention it. You’ll have to look back to find out.

Environment One: The Command Line

A command line environment is relatively easy to set up and use. You only need two things: a text editor and the Java Development Kit (JDK).

Text Editor

Before you open up Microsoft Word and try to code some Java…don't. A text editor isn't the same as a word processing program like Microsoft Word. Instead of giving all the formatting baggage you get from Word, a text editor saves just the text.

Windows and Mac both have native text editors (Notepad and TextWrangler), but there are lots of free programming-friendly text editors available like Notepad++ and SublimeText.

We're going to talk about Brackets , though. Never heard of it? Brackets is an open source (i.e. free) text editor that supports lots of languages, including—you guessed it—Java. Both the installation and the running is easy.

If you already have another text editor or want to search for one yourself, feel free to find what works for you.

After you're done, go ahead and skip to the section called Java JDK. We won't spoil what it's about, but it has to do with the Java Developer Kit.

Environment Two: Integrated Development Environment

An Integrated Development Environment (IDE) is different from a text editor in that it has special features that make writing code easier (usually). For example, an IDE generally works with projects. That way we can group all of our code together to make it easier to run.

Most IDEs have tutorials that provide step-by-step directions for setting up your first program. A pretty standard, and absolutely free, IDE for Java development is Eclipse. We highly recommend downloading Eclipse. It can be a lifesaver when you have a particularly nasty bug.

If you go the Eclipse page, there's a big Download button near the top. After you click on that, you'll be directed to a web page where you can select the program you'd like.

Hint: you'll want to select Eclipse IDE for Java Developers.

Then…download and follow the set-up instructions.

The Java JDK

Whether you're using a text editor or an IDE, you also need the Java Development Kit (JDK). The JDK provides the tools to actually write and run Java applications and applets. You can download the most current JDK here. Running code in the command line can get kind-of complicated, so make sure you check out this installation run-down to make sure everything's copacetic.

Especially if you're doing this on a Windows computer. Seriously. The difference between a 32-bit and a 64-bit Windows operating system is huge.

A Note on Downloading Software: If you're not allowed to download software at your school—and you don't have a text editor, IDE, JDK, or any combination of the three—talk with your teacher about setting it up. If you already have other software installed (DrJava, CodeWarrior, etc.), you can use that instead. The environment won't change your code.

It can just make things a little easier.


Sample Lesson - Activity

Activity 1.03a: Testing the Environment

Is your text editor and/or IDE set up? Good. Let's get to writing a program.

Step One

First, in your editor or IDE type the following code. Make sure you type the code exactly as you see it. The Java compiler won't forgive you for making mistakes—even if they're tiny.

Especially if they're tiny.

class FirstProgram {
      public static void main (String[] args) {
            System.out.println("Hello, Shmoop!");
      }
}

Save your file as FirstProgram.java. Go ahead and make a directory (directory and folder are different names for the same thing) to hold all of your Java programs. If you're using a shared computer, make sure you save the file to a directory you can always access. For example, our path would be:

/ShmoopShmooperson/AP_CS/Projects

Step Two

After you've saved your file, try running it. If you're using an IDE, you'll need to click the Run button (in Eclipse it's a circular green button with right-facing arrow). If you're using a text editor, you'll need to go to your computer's command line or terminal.

First, though, you'll need to know where your file "lives" on the computer. If you've never navigated the directory structure of a computer before, figure out the location of your file using Mac Finder or Windows File Explorer.

Mac Terminal

On a Mac, you can get to the terminal window by going to Applications → Utilities → Terminal. This opens a window that'll allow you to compile and run your program.

Once you have a terminal window open, you'll need to navigate to the folder where your program's saved. You can use the command cd to change directories within the file system.

For example, we would use the following command to get to our projects:

cd AP_CS/Projects

To list all of the files within a folder or directory, type ls.

To move up one level in the directory, type cd ../.

Once you're at the folder that contains your FirstProgram.java file, move on to the "Compiling Your Program" step.

Windows Command Line

In Windows, go to Start → Run, type cmd, and press Enter. Once you have a command window open (which should look like this, btw), find the directory where your program's stored. You'll use Disk Operating System (DOS) commands to find it. You can use the command cd to change directories within the file system.

For example, we'd use the following commands to get to our projects and list everything in the folder:

cd AP_CS\Projects
dir

To list all of the files in a folder, type dir

To move up one level in the directory, type cd ../

Once you find the folder with FirstProgram.java in it, move on to "Compiling Your Program."

Step Three: Compiling Your Program

Every time you compile a program, it converts the code into Java bytecode, which is the language in-between Java and the physical zeros and ones your computer understands. To get it to the computer level, it goes through the Java Virtual Machine(JVM).

To compile our program so the JVM can read it, type

javac FirstProgram.java

into the terminal or command line. If you don't have any errors or typos, breathe a sigh of relief and thank the programming gods for your good fortune. You'll know your code's error-free if it doesn't say anything. If you have a compilation error, you'll get error messages (and you'll need to debug), but more on that later.

Every time you modify your program at all, you have to save and recompile it—unless you don't actually want the computer to run your changes. If you press the up arrow on the keyboard, the previous command will show up in the prompt. Which is pretty nice.

Now that the program compiled, run it. Type:

java FirstProgram

If you did it all right, "Hello, Shmoop!" should display in the terminal or command window.

If you're still having trouble getting your program working, use the following checklist to…check your work.

  1. Was the Text Editor or IDE installed correctly?
  2. Did you save the program with the correct file name (including correct capitalization)?
  3. If you’re using a terminal or command line, did you navigate to the right folder? You can double check this by typing ls in Mac or dir in Windows.
  4. Did your program compile without any errors?
  5. If there were errors, did you correct your errors and then save and recompile the program?
  6. When's the last time you re-started your computer? We love groaning at the classic IT question as much as anyone else, but sometimes the problem really is because the computer's ignoring the program you installed. If that's true, the best thing you can do is restart the computer.

Since today is the start of our programming practice exercises (and since you'll be writing programs. Every. Single. Day.), it's super important to make sure everything is set up correctly.

If you're still having trouble, take a look at the documentation that came with your IDE or text editor. If that fails, look online. Another person probable ran into the same issue at one point or another and (hopefully) fixed it.

Once you've gotten the computer to write "Hello, Shmoop!" to the screen, take a screenshot and submit it below.

Then add "Can follow long-winded sets of directions" onto your resume.


Sample Lesson - Activity

Activity 1.03b: Commanding Presence

Here's another reflection activity, Shmooper. All nice and shiny and ready for your opinions.

You've just worked with the terminal (a.k.a. command line), possibly for the first time, in this lesson. Don't worry: you'll be doing a lot from now on.

The thing is, on TV and in the movies, whenever a hacker's shown working on a computer, they're using the terminal to execute functions and "hack into the mainframe."

When you've finished this course, though, all those crazy, mystical illusions about computers won't actually be that mystical. So let's start with what you believe about computers and hacking.

What do you think about the media's portrayal of computer science and hacking? Tell us in about 100 – 200 words. As you write, be sure to include something about

  • what computer science is versus what the media makes it look like.
  • why the terminal looks so impressive.
  • whether or this perception of computer science being really complicated is good or not.

For instance, if Shmoop were writing a reflection on whether we think the terminal should have a black or white background, we'd write:

I think the terminal should have a black background because it's easier on the eyes. However, sometimes I prefer the white background because it doesn't look as intimidating as the black background does. I think coding should be accessible to everyone, so I want to make it look as friendly as possible.

All right, now it's your turn. Tell us how you feel about the media's perception of computer science.