 So, now what we'll talk about is how it all ties together. Now that we're understanding the logic behind the computer, let's start to look at it from the basic machine architecture. And that's actually where this processor that we talked about last lecture and this memory stick will come in to play. We'll flip it over so we don't look at the Dell logo. Well, what's really going on here is these two things are the most important things in programming. Well, this guy, this RAM stick right here, basically what it does is it holds all of our data in place. Without this thing, it doesn't matter where the math goes, it has nowhere to go. Now, our processor, the same kind of thing. If memory is where things get stored, the processor is where all the action kind of comes into play. And that's, like I said, where we start to look at this idea of something known as our basic machine architecture. And so it breaks down into two separate portions, memory and the processor. But even then, the memory and the processor, things actually change a little bit more. The processor gets broken down into two separate sections, our control logic and our arithmetic logic unit, our ALU. It's kind of, it's hidden right here. Now the ALU, the control logic. Control logic acts as sort of our counter. If we think about memory for a second, memory basically is housing things in different little slots. Inside here, there's tons of little slots going on, each one of these black little boxes. So each one of those has just a little bit of a binary string held in it. Well, what the control logic does is it goes to those particular memory addresses. And then the ALU, the ALU acts sort of as that the brain, if you will, of the CPU, of the microprocessor. And it does things like it adds, it does things known as move, moving bits from one location in memory to another. It does things like compare. How do these binary strings compare to these binary strings? And it continues to do a lot of these very basic level computations. We start to build from that. So if we think, for example, multiplication, multiplication is just repeated addition. Two times eight. Well, that's two plus two plus two plus two plus two plus two plus two. Eight times I've added two, which gives me my 16. So it starts to, sorry. So it starts to branch out. First we start with our control logic. We get our memory address. That goes to the ALU, not me, the ALU. And it does its math. What happens once it's taken care of that, once it's gone through that process, it spits that back up into memory. Because once I've done my addition, well, again, I need to put it somewhere. I put it into memory. And again, that memory, if we think about it, really every single one of those blocks are just storing some content. So if I were to think about the word hello. Hello by itself is just three specific, or five specific letters, H-E-L-L-O. Each one of those has to be represented via binary. And that's actually where we get this thing known as ASCII, a standard for taking binary digits and turning them into text. And so you can see each one of our letters, H-E-L-R-O. Each one has their own binary string to them. And each one of those reside in some portion of memory. So everything is like that, numbers, everything. So now that we've talked about going through the computer, especially the CPU and the memory and whatnot, we get into something known as computational thinking. It breaks down into, again, two separate ideas. One is declarative knowledge. Declarative knowledge is this idea of something being very factual, very statement. For example, the memory address of 2000 is H, or 0100100. We also have things like our classroom. Our classroom is going to be in NB 243. High is 3.141592 going on forever. Then we get imperative knowledge. Imperative knowledge is where computer science starts to flourish. We're no longer just making statements, but now we're saying, well, we have to think about how we make that statement. The old idiom of you give a man a fish, you feed him for a day, you teach a man to fish, you feed him for a lifetime. Same kind of thing is going on with our differences in computational thinking. Declarative, we're making a statement once. Imperative, we're turning that into something that we can use forever. So for example, the area of a circle is pi r squared, or how to get to the NB building is to go to the front of the NB building. Open the door, walk through the door, go up the stairwell, go to hang a left at the stairwell once you get it to the second floor, and you're the first door on the right. So much more knowledge just to get to NB 243 versus a factual we are in 243. So a little bit of a difference. So the reason why we do these two different types of knowledge is when it comes to programming, when it comes to coding our program, there's a few things in place. The first thing is simply how we go about talking to the computer. In an earlier lecture, I told you guys about the idea of programming languages and how a programming language is just our way of taking a human readable code, human understandable syntax, and translating it into something that the computer can understand. Well, we have different ways that we can do that. We can use something known as an IDE, an integrated development environment, and we will later on in the semester. Or we can use a text editor, notepad++, sublime text, bluefish, notepad, period. Those are all text editors. They just allow us to mess around with text in a specific kind of way. So say, for example, notepad++. The reason why we'll be using this at the very beginning of the semester is because not only does it allow us to basically just have a text editor, it allows us to type text, but it has what are known as things like syntax highlighting and auto completion, which is going to be very nice when I start to write something up like public class welcome, and you don't see anything right now, but inside this language minibar, you notice that there's a whole slew of things that appear. Each one of these actually allow me to now select the language that I want to work with. So we're programming in Java, so under J, Java. And suddenly, notice how public class, those things changed. Well, we'll get into that in a later lecture, but they are known as keywords. Same kind of thing as soon as I add in some brackets, notice how even though I only added in what we call our opening bracket, that left little squirrely brace is what I like to call it, curly brace as well, we got the other version as well. One of the key things to remember is always make sure to close your brackets. But this is a fully functioning program right here. And I didn't even need to use that IDE, those integrated development environments. Now what this does is by using these programs, we're allowed to do what's known as high level programming. Now high level, it's something like Java for example, Python, PHP, C sharp, Visual Basic. Those are all considered high level programming languages. And the reason why is because, well, a lot is going on in the background that we don't really know about. And that's actually where the compiler comes into play. Where all of this extra knowledge comes into play. Then we get into things like assembly. Assembly is ugly. No one's a fan of assembly, I'll just say that. But we keep on going until we eventually get down to the ones and zeros. So it's just kind of that where you pick up. Do you want to go with a high level language where everything gets kind of built for you? Or do you want to go with the low level you have to build it yourself? So none of them are wrong. They're all just a different way to skin a cat. So that first program we were talking about, getting started, taking that hello world that we were just talking about, and fleshing it out a little bit more. So some things you're going to notice right off the bat, and I'll even bring this version in to copy it down, is we start with public class welcome. Well, public class welcome. We'll get into public in class a little later on, but our program is actually now called welcome. I'm making a welcome program. Inside there, I have to tell it what we call our main method. And so what I've just done is this main method. When I run my program, this is the method that's going to run. This is going to be my execution. And the first thing I just want to do is I'm going to add in something we call a comment. Two slashes. You're going to notice that it kind of grays out a little bit on the screen. See if I can't zoom in a little bit more for you guys. It grays it out just a tad. Now what that allows for me to do is now put in English. Put in things that are just my way of explaining it out to myself. So I will display the message, hello world. Now the compiler, the computer does nothing with this. In fact, it will just throw it away. For us as humans, this is our way of taking this crazy language that doesn't really make a lot of sense and make some sense to it. So now that I've put in display hello world, now it's time to actually put in my code. So we start with something relatively complicated, but system.out.printl in. It looks like it's print capital I in. It's print the letter L in. Print the C's and a semicolon. Now we've done a lot of things here. I just want to go ahead and at least put it all in first before I go into explaining everything. So hello world. So what did I do here? Well system.out.printl, this first portion. Well system by itself. What that's referring to is that's actually talking about my computer, you know, where this message is going to go. Out. Out is referring to now I'm giving an output instead of taking an input in. So we'll see later on in the semester something like system.in. We're using system.out.printl in. This is actually known as a method and we'll get in the methods again later on in the semester, but this method does things behind the scenes. We don't know what it does completely, but we do know that when I use system.out.printl in, I will get it to display on the screen. Display what? That's actually where this print the C hello world comes into play. If you remember your math class for just a moment, you might remember that you saw something that looked eerily similar to this f of x. This was known as a function, function of x. Well, we take that same idea and this time we've just changed it up a little bit. We've gone and said instead of f, f was very uncomplicated. We couldn't understand what f meant. We've turned that into printl in. And now instead of x, again, I don't know what x is, but this air quote, air quote hello world. What that is known as is a string and a string is my way of being able to actually have text representation. Now I can't say something like this. I cannot say something like hello world without my quotations because we're talking to the computer. The computer doesn't understand what hello world with that comma and that exclamation mark is. It doesn't understand that. So what we're doing is we're basically turning it into a little bit. Think of it if you're a video game fan. We're turning this into a little bit of a text box. We're basically stating that here is some text. Then we go and we close out of that parentheses just like we would a function. And we end with this thing called a semicolon. Now the semicolon, the reason why we end with it is just, it's like the period in English. It's our way of saying this is the completion of a sentence and the computer works from there. So now that I've taken this and I've written out my program, when I save it, well I've got to save it a specific way. I have to first save it the exact same name I gave my program. So I called it public class welcome. I want to save it as welcome.java. And I've already written one before but I'll overwrite mine. Now once we've built that in, we need to open up the command prompt. So if you're unfamiliar, in fact let me actually pull one up. If you're unfamiliar with how to do the command prompt, click on the start menu and then type the letters CMD. CMD is going to bring up your command prompt. If you're using a Mac or a Linux machine, you'll want to open up your terminal. From here you'll need to go to wherever you have stored your file. I stored mine on my desktop for example. So I pull up my command prompt, I'm not on my desktop. To go to my desktop I go CB desktop. Now from here, again, if I want to take my program and actually run it, right now it hasn't run, I need to do what's known as compile my program. Java C. Now Java C what this is going to do is this is going to take all of that syntax, all of this source code information that I have down here. And it's going to turn it into machine language. It's going to convert it into the ones and zeros. And so when I type in Java C, welcome.java. Remember that's the file we called it. Java C, welcome.java. When I run that, you see nothing happens. All right. Compiling just converts. That's all it does. In fact, we want it to not do anything. If it does something, it typically is telling us an error. And we'll see those in just a little bit. But once I've taken care of this, what I can type in now is the word Java, our programming language of choice, and our program name. Welcome. Not welcome.java. Not welcome.class, which is what we get when we do Java C. We want to do Java, welcome. And as soon as I hit enter, what do you know? We've just created our first Hello World program. Now, I did say something a little bit earlier about how Java C, we want to make sure that it does not tell us something. Well, let's say, for example, in my code, that bottom bracket on line six. I got rid of it. Boom, it's gone. Well, let's come up here and let's try and compile our program again. Well, when I hit enter, you see I get what is known as an error message, a syntax error. Well, if we take a look at this, this is actually going to be very important. If you are not a fan of reading error messages, you'll become one. But if we take a look at this, you see it says welcome.java five error reached in the file while parsing. Well, if we take a look at what that means, basically it's talking about the fact that we got to the end of our source code without actually completing our proper syntax. So I have not officially kind of built my program. So that's where that error comes in. That was just one. What happens if I do something else? What happens if this quotation at the very end of Hello World? What if I get rid of that? You see it kind of changes colors. And if I go in and I try and compile it again, you see instead of just one error message, I get three error messages all of a sudden, just from one error. So the amount of error messages don't really matter. So how do I tackle this? Because a lot of these are actually going to be a little tricky, tricky. My recommendation is always start with the first error message. Don't worry about the second one. Don't worry about the third one. Only look at the first one. Only try and work on that one. So if we look at it. Unclosed string literal. System.out.println, air quote Hello World, something. It's indicating the line that I have an error. Line four. So this is the only place I should be trying to work for right now. One or two lines above or below it. Well, again, if I add in that quote, like I said, only adding in that single quote. My recommendation, don't start to add. Don't try and figure out what the other error messages mean. Now that you've made a change, compile and run. Notice how it worked that time. Now I'm able to run my code. There you are. Hello World. Now I will throw out one little tidbit. Say for example, this time instead of a capital S, you need a capital S here. I put a lowercase S. And I try and compile it. One, I'm going to get an error message. But what happens if I still try and do Java welcome? Instead of Hello World. Well, what's actually going on here is I'm using a previous version of the file. I'm actually using the previous version that worked perfectly fine. Because I did not compile the program because it crashed when I tried to compile it. It, excuse me, it did not change my welcome file. So if I did something like rm, rm remove. Sorry, that's for Linux. Dell, D-E-L for a Windows machine. Dell welcome.class. That deletes that file. Now let me try and do that same Java welcome. Notice how I get an error message. It's not there. I've deleted it. Oh, I'll compile it. Well, now remember when we compiled, we got an error. So suddenly I can't run my program because I have to fix the error first. I have to fix that before I can go in and I can compile or I can run the program. So we've taken a look at the compiling. We've done that. First we converts and we run the program and then it will display things for us. So a few little tidbits as well before we end. Work with proper documentation. Work with proper indentation. You notice with notepad plus plus it automatically built that in for us. That's actually very nice because it helps readability. Notice how if we take a look over here on the right hand side, a little bit more easier to read because I have a little bit more flow. I can understand what belongs to what. Also, those comments are very useful. They're going to tell you what every line of code does because I won't lie. Sometimes it gets a little complicated. Now if we take a look over here on the bad side of code, notice how everything, even though it's got that line there, everything's kind of bunched up together. It's all stacked on one line. It makes it a little bit more difficult to read. Notice how I don't have any comments as well. Sure, it's the same code. Sure, it's very basic code. We can tell it's going to print something. Again, when we get to more complex code, we'll see examples of where this becomes a little bit more cumbersome. My recommendation is even before moving on, see if you can write that code. Go back and take a pause on the video and write your own hello world. Then try and get it to compile via your command line interface. If you can't or you've got some error messages, make sure that you have your Java in your environment variables. Remember, that's one of the first things we talked about inside of Blackboard.