 Welcome to intro to AP computer science a getting started with Tokyo Etik. That would be me say I'm gonna show you how to get started with Java programming now the focus is on AP computer science But this is for anybody who's interested in learning Java So if you haven't done Java programming before there's a few things that we need to do first So for example, we need to download what's called the Java software development kit This is the this is the program that lets us write Java and compile it and do a couple other things Then we also need some sort of editor. We need to be able to edit our code. Now, there are tons of different options I'm gonna recommend one called genie. It's very simple. It's great for beginners. Now, those of you that can't download Let's say you're on a Chromebook or something you can also use a website called repel dot IT And this is an online coding environment You just sign up with your Gmail account or whatever you use and then you can code directly in the browser So I'm gonna show you a simple program in Java just how to get a Java program working We're gonna show you how to compile it and then finally execute it. So let's go ahead and get started So first as I mentioned, we need to download the Java SDK now depending on your system Let's say you're a Windows user. You're a Mac user. I'm a Linux user That's why it may look a little bit different to you So this is the this is the link here It's oracle.com slash Java slash technology slash downloads. I'll put a link down below for you There is Java development kit 20 again You can choose, you know, whichever operating system if you're a Windows person if you're a Mac person Or if you're Linux person, you choose the one that's correct for your system You just download it and install it should be good to go second thing is you need to download a Programming editor again, as I mentioned I use genie uses with all my students It's you know featured enough that it's not super basic But it's also doesn't do too much that's confusing for beginners So you just go ahead and click download here It will take you to the right version for your operating system again Whether it's Linux Windows or Mac and just install it and then you can run it as I mentioned alternatively you can go to this website replit.com actually, I don't know I put repl.it I think that works as well and You just basically go there you create an account and you can go ahead and click on create repl And then you just have to tell it what language you're doing So in this case, there'll be Java and we would just choose the very first one where it says Java Rebellet and then it gives a little title you can keep that or you know do whatever you want So you do create repl now I'm gonna go ahead and type this into genie because this is what I use with my students But you can go ahead and type everything in here now. You can see that they've actually already done it for you There's a couple things they've done a little bit differently than I would do and I'll point this out here in a minute So let me go over to genie. I'm gonna open that up so if you open up genie and you haven't used it before you should see where it says untitled and Then it's basically just a blank page now. I have mine set up a little bit differently already I do have a video about genie if you want to take a look at that I'll try to put a link down below if I forget somebody remind me and Basically right now we can start typing our program. The first one we do is I'm gonna go ahead and hit file And I'm gonna save this I've created a folder somewhere I think it's the documents and Java files and This part is important. The way we name our files is very strictly I don't know strictly enforced in Java other languages aren't quite so strict But Java you got to do things a certain way So what we're gonna be doing today is is printing hello world on the screen. So I'm gonna call this hello world dot Java notice it is a capital H. It is a capital W. This is part of the naming convention for Java you have to do it this way also notice there are no Spaces we can't have spaces and it is dot Java no space at the end So I'm gonna go ahead and click save and this tells the computer says hey, this is a Java file So you see where it says here hello world dot Java Now unlike other programming language. So for example, this is a Python. I could just type print hello world and We would be done. That's a perfectly valid Python program, but this is not Python. This is Java Java is what's known as a class based or an object oriented language Everything has to be a class So we need to create a class and you'll learn more about that as you go through this video series Now the class name has to match the file name So hello world no dot job I'm gonna go to the next line. I'm gonna put a left brace or you some people call it curly brace and Then I want to put public static void main string args notice the parentheses and pull space there and Some extra curly braces. So this is the bare minimum that you need for a Java file to execute Okay, so I have a class and Then this parenthesis or sorry this brace and this brace. This is the opening brace This is the closing brace. So everything in between is part of the hello world class I've created what's called main method and this is just got to basically memorize this It's public static void main string square brackets and then args and the parentheses and then Left brace and right brace or opening brace and closing brace. Then what happens is everything here So your code goes here You're for now, well, you'll learn more as you go on for now This is the part of the code that actually gets executed. So as I said earlier, what we're gonna do is we're gonna print hello world This is like the standard programmer first program. So I put system dot out dot print ln parentheses quotes or double quotes, I should say and hello world exclamation point and At the very end of the line, I'm gonna put a semicolon So this line here is a comment. So slash slash is a single line comment This is not executed the computer basically just pretends. It's not there But we put it in there so that humans know what we are doing so to execute a Java program we first have to compile it to something called bite code and again It's something you learn more about later. So it's a two-step process So in genie, there is a button here. Yours might be a little different based on your operating system But it's around here somewhere and if you hover over it, it'll say compile the current file So I'm gonna go ahead and click that And you'll see down here. It's a little hard to see because of the colors. It says J a V a C Hello world dot Java wherever you saved it So this is the Java compiler and it says compilation finished successfully So if I were to go to that folder, you know, what was that document's Java files? Now, you'll see hello world dot class So this is something called bite code as a human being you wouldn't understand it It's all like numbers and symbols This is what we're working on. So this is converted into this and then when we want to execute it We click this button here, which says run or view the current file So I'm gonna go ahead and hit run you can see down here. It says hello world You'll see program exited with code zero. That means there were no errors, which is a good thing So we're happy about that. So this is your very first Java program So you should try this and get it to run if it doesn't work You can't move forward. There's there's no point in trying anything else because you're stuck Let's go ahead and real quick and go back to replete and take a look out of it I don't know why I did that to me So you see here. It says class main is this is main dot Java So replete gave you main dot Java to start with notice It's no different based the same thing I typed. It's just you know, they just call theirs main instead so if I click run and You see also see Jav AC so this is compiling for you and then it prints out a little world So we get the same result on both both systems, I guess you'd say again, I prefer to do it here in genie I think there's a lot of value in learning this But if you're if you don't have a systems capable of doing that then feel of course feel free to use whatever works for you Now here are some common mistakes you might see So if I take out that quotation mark and I command s I save it and if I have to hit compile You'll see we'll get an error says error Unclosed string literal says hello world dot Java. So that's the program the file that we're in There's a six here. It tells us exactly where the error is And it says unclosed string literal. So there's a little Pointer here points to here. This is the opening quotation mark. It's because we're missing the closing quotation mark So we save it we compile it Do they get see what happens when we get rid of the semicolon? I'm not sure if that matters or not, but let's see Okay, yeah, it doesn't matter duh Same thing. Hello world Java six error semicolon expected. It actually points To the end of the line. So it tells you where that error is So it tries to tell you what problems you have now. Let's say if I misspelled print LN Let's try and compile that Again Cannot find simple it tells you where the problem is it's pointing to the area where the problem is It says print n string. It says it does not know what that is And so if you make a mistake, it kind of tries to tell you what the problem is Let's see if we to the void will do void Okay, so again cannot find simple now this time it's in line three So it's kind of telling us what the problem doesn't what void is So, uh, it's kind of cool. Now, let's go ahead call this hello world two And compile it Now notice how it compiles, but if I try to run it What runs because the old ones in there? Let me get rid of the old one real quick documents Because the old one's still there. So I'm gonna go ahead and move that to the rubbish bin And now I'm gonna compile it and I'm gonna run it And you get an error could not find or load main class hello world This is a common problem that beginners have is they forget that this has to match This so if these two don't match it will compile, but when you run it you get this Class not found exception because it's looking for hello world not hello world two So make sure they match. Okay, so that's it. That is your first java program. So just to review We Went to the webpage where you can download the java sdk. You got to download and install that first It's pretty big to 300 megabytes. Then you need to download the genie editor. There are others This is just the one that I use Visual studio code is a popular alternative. You choose whatever works for you Then there is also repel.it which is an online coding environment If you can't download or install that on your computer for some reason you can go ahead and use that instead We did the hello world example. And again, you have to make sure that everything is Capitalized correctly make sure everything is spelled correctly if I change this p to a capital p. It will not work And you'll get an error says Identify in this case identifier expected So the error message that changes a little bit based on what kind of problem it is And then there's a lot of different things here that you need to keep track of but this is always going to be your basic structure Of your main java program As you move forward at least for now and yeah, I think that's about it. So We talked about compiling make sure you compile it first every time you make a change you have to save the file Compile it then you can execute it because sometimes what will happen is I see students do this a lot Is they will Let's say they'll compile it. Okay, it's running then hello world. I am here That looks very funny then they run it And they say well it didn't work. Well, that's because they didn't compile it again So you have to compile it before you execute. Okay, so now you can see that the changes have You know shown up where we expected them to Okay, so that is it. Uh, yeah If you have any questions comment down below and as I like to say keep on coding. Take care