 Hey everybody, it's Brian. Today we're going to be doing the 21st Java video. We're going to be departing a little bit from the norm. I want to take a step back and show you how to manually compile and run Java classes. So here we have just a normal Java class. We've seen this a million times. Just simply spits out, hello from Java. When we run this, you see, sure enough, hello from Java. Well, how does all this work? I mean, it's fine in Danny to use an ID, but what if you really got to get into the nitty-gritty and run it manually? Well, excuse me, in Eclipse, you can right-click your project and go to Properties, or you can just simply select it and press Alt-Enter. And that will show you where your project is located, the location. See Users, Brian Caron's Workspace Test. Obviously, I'm on a Windows 7 box. So, how are we going to run this? Well, first, let's flip and see what's in here. You see, I'm NC, Users, Brian Caron's Workspace, and there's two files, dot metadata and test. Well, the dot in front of this folder denotes that if it were on a Linux Unix system, it would be a hidden folder. And when you go in there, those are just files used by Eclipse for your project settings, your versions, your plugins, anything that you're going to be using. But your stuff is actually in your project folder. And in this case, our project was named Test, so let's actually flip back and you can see the name is Test. In here, we have a dot settings. Once again, that's Eclipse settings. We have a bin, a source, project and class path. These are both Eclipse files. Eclipse stores things in the SRC, which is short for Source. So there's your Java file. This is the actual file right here that has our source code in it. Now, we can't just run the Java file. We have to compile it. So when you run Eclipse, it compiles to a class file. Remember from our previous example, if you open that up into Notepad, you'll see that it is just quite simply a bunch of guck. Yes, guck is the technical name for it. What Java does is compiles it into an intermediate language. .NET does something similar. They actually call it the intermediate language or the IL. This is what Java actually runs. The Java virtual machine loads this and runs it, but that's way beyond the scope of what we're going to talk about. All you need to know is that you need to compile your Java files into classes. And to do that, you open a command prompt. If you don't know how to do this, you go to start run and type cmd and that opens a command prompt. Now, the first thing we need to do is actually navigate to our directory. We are in C, Brian Caron's workspace, test source. So we're going to go CD and you can actually have to show you a little trick, copy and then paste. And that will change to the directory. And when you type a dir for dir directory, it'll show you what's in there. And you see that we have Java file there and it's 128 bytes. Now, one thing you should know is you will need to modify your path. The path is an environmental variable. If you go to a command line and type path, hit enter. If you don't see the path to your Java installation, didn't work the way I hope, C program files, x86, Java, JDK, six, blah, blah, blah. If you don't see that, none of this is going to work. In other words, if you type Java and you don't see a list of options, you get an error of, you know, file not found or something, you need to modify your path. To do that, you go to start. Let me see, let me follow along on my computer. Start, right click on my computer, you can go to your desktop, my computer, go to properties. And let's see here, advanced settings, environmental variables, and then you scroll down here and there's path and you edit that and simply paste it at the end and put a semicolon at the end. That denotes the delimiter and close all that. Let's just clear the screen here. Alright, so we've got everything running. When we type Java, we get a list of options. You can tell if Java is installed correctly if you type Java-version and it tells you the version. Notice that we are using the Sun version. There are a lot of other Java versions out there, but we are using the official Sun version. Alright, now there are three programs you need to know. First one is Java. That is what actually runs classes. And Java C, which is the compiler. That's what we're going to use first. Let's actually just clear the screen so we can see what's going on here. We'll type Java C and if you hit enter, you're going to get a list of options. If you're not familiar with the command prompt, I'm going to walk you through this real quick. It says usage, Java C, options, source file. Here are the list of options. So you're going to give it options, space, and then the source file. So we're going to type Java C and then you're going to simply type in the name and hit enter. Now notice how we didn't give it any options. Well, the reason for that is we are currently in the directory we need to be. Otherwise, you would have to set the class path, you know, specify where to find user files and annotations, which, you know, for the current directory, I believe you can just type a dot. I'm actually going to go Cp short for class path dot. It does the same thing. Alright, let's go back in here. Now you see we've created this class file in the same directory. That's the file we'll actually run. So if you type Java and you type main, notice how you're not typing main dot class. You're just typing main. Java assumes you're giving it a class file. Run it. It says hello from Java. There's our program working. Now Java does the same thing. You just type Java enter and you get all these options. Now what are these options? We're not going to get them all, but what you really need to know is class path. Class path tells Java where to find things. For example, you notice how we've got our main class in workspace test. Let's just delete that. When we go to run this again, and you can just press the up arrow to repeat commands, you're going to run that again. Notice how it says exemption may not found blah, blah, blah. That's a standard area you'll see when you're trying to run Java. Basically what that says is it couldn't find the class. Notice the class not found exemption. I know it'd be a lot easier if they just said, hey, we couldn't find what you're looking for. But that's what's called the call stack. So what we're going to do here is we're going to actually use the class path. And we're going to use the class that Eclipse created. We're just going to copy that. Now you notice how those are two different paths. We're in C users, Brian Cairn's workspace test source. This is C users, Brian Cairn's workspace test bin. So when we go here and we type main, it explodes. It doesn't like it. So what we need to do is give it a class path. Type dash cp main. We need to actually put the path in here. So we'll just right click, paste. Now it says Java class path. And then we've got the path and hit main. Do you think this is going to work? Let's find out. I don't think it's going to. I'll explain why. When you hit enter, it doesn't work. Same thing, class not found. Why not? We gave it the path. Well, press your up arrow. The reason is simple. You see this right here where it says, Brian space Cairn's DOS commands don't like spaces. It treats it as two separate arguments. So you need to enclose that in quotes. Once you do that, it runs just fine. Well, that's it for this tutorial. I'm running out of time. I hope you found this educational and entertaining. Thank you for watching.