We left off talking about Object Oriented programming, classes, and objects. Before we can jump straight into writing code and seeing what it does, we need a place to write code, and a way to run it.
Computer-ception: The Java Virtual Machine
Java runs on top of the Java Virtual Machine, or the JVM. Think of the JVM as a little computer that runs on top of your computer's OS. Our code runs inside the virtual machine rather than running directly on the OS. You might wonder why we do this.
Imagine running code straight to the operating system. Windows, OS X, and Linux are quite different. Code written for each OS talks to the OS and asks it to perform things (like drawing something onto the screen or accessing the network) lightly differently. The Java Virtual Machine takes cares of these differences for us. You can run versions of the JVM adapted to Windows, OS C, Linux, and almost anything you can think of. When we write code, we only worry about talking to the JVM, and don't have to worry about all of the OS operations happening underneath.
This concept, by the way, is called 'abstraction' in computer science. We'll talk a bit more about that later.
How your code will run
We write our code in the Java language, and save it to .java files (files ending in the extension .java). You can type code into Notepad or any plaintext editor, and save it as a .java file. However, this isn't code that the JVM can understand or execute. In order to make our human-readable code (trust me, people can read it, and soon you will, too!) understood by the JVM, we compile it.
The Java compiler (and the compiler for just about any compiled language) takes the code we wrote, and turns it into machine-readable code, or bytecode. In Java, bytecode is stored in .class files. These files are what we run on the JVM, and that's how our computer executes our code.
So it would seem that a typical workflow is writing code to .java files, compiling them to .class files, and running .class files in the JVM. That's a bit of a hassle, especially if you're working with a large number of files. Managing the files and finding errors would be all up to you.
Thankfully, software exists for programmers called *Integrated Development Environments", or IDEs. An IDE is basically a program that has a compiler, a text editor, and a bunch of useful features (like checking syntax, highlighting certain parts of code, etc) all built in. We'll be using an IDE for Java called Eclipse.
Installing the JDK
First we'll need to installl the Java Development Kit, or JDK. The JDK is where we get the Java VM and compiler.
You can go right here to download and install the JDK.
The installation process is pretty simple; just make sure to download the correct version for the correct OS.
If you encounter some problems down the line with your OS not recognizing that the JDK has been installed, you might also need to modify your path variable to point to the jdk. It soundsd complicated, but it's not. A tutorial from Oracle on how to do so in Windows is here.
Eclipse is a very useful IDE, and the one we'll use here to code in Java. New versions come out from time to time, so what you see might not be exactly what shows up for newer versions, if you're reading this way in the future. (Plus, if you're reading this in the future, it's like these words are reaching across time to you, which is pretty neat. Hi, future.)
You'll want to go to http://eclipse.org/downloads/ which is where all the variants of Eclipse reside. We just need Eclipse Standard (shown above), which supports Java. Download the proper version and extract the .zip file you download. You'll end up with a folder simply called 'eclipse'.
You don't need to install Eclipse. The elipse.exe file inside the eclipse folder will launch eclipse.
When it first launches, it might ask you where you want to set your 'Workspace'. The Eclipse Workspace is just a folder where all of your projects will be located. Set a custom folder here if you'd like, otherwise the default is fine.
Close the default welcome screen, and you'll see Eclipse! At this point, you're ready to set up a project and start coding! Next time we'll set up our first Java project, and start writing code.