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.