Transcript for:
Beginner's Guide to Java Programming

If you're struggling in Java, don't worry, because I got you. Just take a nice deep breath, sit back, and I'm going to show you everything you need to know in Java. This video is made so you can just watch it on your phone or follow along if you want.

I've been programming in Java for over 8 years now. I graduated with a computer science degree. And maybe like you, I had a lot of problems learning how to program at all. I had a breakdown in college when I thought I couldn't... past few of the projects so it was really hard for me but I don't want to make it hard for you I'm gonna try to help you out wherever you are in your life with programming and hopefully you find this video helpful this is everything you need to know about Java in 13 minutes hey it's Alex back again helping you learn Java on this channel if you're new here I make a Java tutorial just like this one every single week so if you're new here and consider subscribing computers only understand zeros and ones which makes it kind of difficult for a human So to solve this, what we did is we made programming languages, which are just a bunch of keywords and symbols that help us program a computer.

The one we're learning today is obviously Java, and here's everything you need to know about Java to start getting started. What you see on the screen now is a programming environment. This is where you write code.

You can write code in Notepad or on a piece of paper, but none of those ways has a way to compile your code, which means turn it into zeros and ones. There are a bunch of it. tutorials on how to install Eclipse.

This is the program Eclipse or IntelliJ is a good one. I made a video of installing Eclipse on Mac and Windows. It's on the screen now if you want to check that out.

We'll just set up a file to start learning Java. So I'm just going to go to File New Java Project. Type in the project name like Java Tutorial Epicness.

Hit Finish. Next, expand that up. Right click on the source folder. and go to new class and this is just our java file we'll name our java file like learn java hit this first check mark public static void main and then hit finish and we get some code looking stuff pop up on the screen so like i said a programming language is just a bunch of keywords and symbols and it looks like this java file already has some keywords and symbols in here for us a super useful thing we can do in java is store data so you can store say a number variable in java by doing this int a equals say five.

This takes the value of five and stores it into a. You'll notice this keyword int that stands for integer and there are a bunch of other ones like I'm just going to list a few. So here's a few more there's one called char long and double. Char stands for character so this is how you would store a character variable. You would just put your character inside of single quotes and that would be stored into b.

We've got a few others like long double and there are a bunch more. These are called primitive types since they turn purple. Like how primates are before humans, the word primary means number one.

Primitive just means it was here before, it's built into Java, which is pretty sweet. Let's go on to non-primitive types of storing data because storing data is super cool. If we wanted to change our username, say on Instagram, it's got to store it somehow, right? So to store like a name, like a bunch of character variables, that would be called...

string with a capital S there. We'll name it like string name and set that equal to Susan and then put a semicolon at the end. Most statements will end in a semicolon by the way.

These don't for their own reasons, but if it doesn't have some sort of parenthesis at the end, put a semicolon there. All these symbols help Java parse it, which just means go through and make sense of it all. So that's why these weird little semicolons exist.

So now the name Susan is stored into name. But notice how this isn't turning purple. It's not a primitive type. If it's not turning purple, that probably means it's an object.

And you can do so many things with objects, it's crazy. To do crazy things with your object, we can just type the name of the string. And in this case, it's name.

So we'll just type name. You'll see red underlines pop up, don't worry about it, it's just trying to correct you before you make a mistake. I think it's really stupid because we're not done yet. But after you have the name of your variable, hit a period. And this period is maybe one of the most important symbols in Java because it tells you everything that that variable can do for you.

All that wonderful code built into Java, you have it accessed through this period. The programmer you're writing Java in will most likely have like a little box here and you can scroll through it and this is everything you can do to that variable. So one I like to pick right now would be like to uppercase. So I can just double click on it or you could type it out and then semicolon since it's not. opening a bracket.

Well, how do we see this working? There's this great piece of code to print out so you can see things. It's called system.out.println and then some parentheses. We're pretty much just taking this and sticking it inside of the parentheses of this code. This just puts it on the screen for us.

So I'm just gonna ctrl s or command s to save it and I'm gonna run it and then in your console window, it might be called console, might be called something else, but in a window you should see your name to uppercase. If you want to see something else we can just delete this, do the dot again to bring up what it can do and there's one called to lowercase. Save it again.

Run it again, and now it's all to lowercase. This to lowercase has some parentheses here. And this putting text to the console window code has some parentheses here too. And anything that has parentheses like this is 99% of the time going to be a method. And methods are amazing.

They're the bomb because they just do things for you like what we did now. So let's make a method that puts an exclamation mark say at the end of whatever string you want. To start a method, just write some keywords.

We're gonna write the keywords public, static, void. Don't worry too much about this right now. They're just keywords and every keyword has its own purpose. We'll name it like add, exclamation point, parentheses, say string, s in here, and then some curly braces to finish it off.

I'm just gonna delete these right now because it might look a little confusing. All this method is gonna do... is add an exclamation point to the end.

So we can just print out to the screen out like we did before, that's super useful. To put two strings together, use a plus sign. So in the parentheses, we'll just type s, which is the name of the string, plus an exclamation mark inside of double quotes. Since characters and strings, anything that's not a number or a variable name has to be in quotation marks.

Statements end in a semicolon. We'll save it and run it. And nothing happens because we're not calling the method. So we'll just type the name of the method and then something like hot dogs.

Now we can save it and run it. And we see hot dogs with an exclamation mark. This right here goes here.

And whatever's inside of these curly braces gets run. You can also return the results as a variable. So we can say return, which is another keyword, S plus the exclamation mark.

You get a red underline because this keyword, void, is actually the type of what you want to bring back. So we just want to do a string, and now we can say a string exclaim is equal to what's returned from add exclamation point. It's stored in here, but let's print it out, and it does the same thing.

Remember I said the dot could bring up a bunch of methods that you could use? Well, you can also call them without a dot if it's in the same Java file. But now I'm gonna show you how to used code from another Java file into your Java file.

So I'll just right click source again, make a new class. We'll call it like animal and hit finish. I'll make a method just like we did before.

Say like I am dog and all it does is return I am a dog. If we wanna use the I am dog method, we can just, I'm just gonna save it. Go in here, delete this code for now. To call I am dog, we can just make.

an animal object like this, animal A equals new animal. Anytime you're making an object, it's going to have this format. There are a million types of objects out there you can use. But now we can just say A dot and it brings up what that object can do and look, I am dog is here.

We can just click it and then store that into string dog and then print out dog. Save it and run it and now you see that I am dog message. being returned to the variable doc.

So a class is just a Java file that helps us make objects. Examples of commonly used objects are ArrayList, has the same format as before, but you gotta put these little angle brackets. But a lot of objects will not come in your code. You have to bring them in.

So usually what you'll do is hover over it and you'll see an import. Click the import suggestion and that'll generate this import keyword. followed by like a path to the ArrayList code. This just means bring the ArrayList into our program so we can use it. In ArrayList you can do things like add, you can add a bunch of items, like this is how they store movies, or store a list of users.

You can replace that and all sorts of things. So objects and methods are super powerful. Each object has its own methods, and that's why Java is referred to as OOP, which is Object Oriented Programming.

Each class represents an object which has its own methods, like this one says I am dog, and you can add as many as you want. Now you might be asking, how do I make a method that does something actually cool? Well, we can start another one.

We'll say void since we don't want to return anything. You can do logic in Java. One keyword is if. This is called an if statement.

You would have a condition in here, say like true, and then it would run the code inside of here. This is useful if you have something like a is equal to a five. If a two equal signs. If a is equal to zero, then run this code.

You can tack on another one. Otherwise if a is equal to 1 then we want to run this code Otherwise if it's something else completely then run this code if all statements are super useful You can repeat code by doing a for loop and a for loop format has the keyword for some parentheses And then a format that kind of looks like this in simple terms This will repeat the code inside of here five times you can change it changing this number eight It'll run this code eight times you can put a for loop inside of a for loop, which makes it really interesting. Just got to change this variable.

Now whatever's in here will be run 64 times because it loops eight times and then another eight times inside. You can repeat code until a certain condition is met by typing the keyword while parentheses curly braces and say like while a is equal to five. Again, print out high.

It's actually say while a is less than 50, print high and then increment. eight by one each time. That's what plus plus means.

Now let's just call doStuff so we can see what's going on. Go into the main method, whatever's in the main method will get run when you click run. So we'll just make our animal again, say A and then a period to bring out what we can do.

And now we can see our doStuff method. If we run it, we'll see high printout a lot, and then it'll stop until it gets to 49. Because it started five, go up six, seven, eight, nine, all the way up until... 50 and it'll stop.

Some other good logic ones are try catch. So the keyword try and then catch. It'll try to run the code inside of here. If something goes wrong, an exception is thrown.

An exception means just something went wrong with your program. And if something went wrong with your program, then the code inside of here will get run. Let's use other people's code and methods inside of ours.

We can do that through an API. An API is pretty much just a long list of methods. that you can use that were made from someone else.

Like Google, YouTube, Instagram, Twitter. Most software companies have APIs that you can use and bring inside your program and do cool stuff. And to use someone else's API, you pretty much go to their website, download this jar file. You would right click on your project, go to properties, go to Java build path, add external jars, pop in the jar that you just downloaded, say like Twitter API jar, hit apply.

Do an import statement just like this, but for the name of that jar. And then you could use the code that they wrote in your program. So that's pretty much everything you need to know about Java.

We went over primitive types, variables, storing data, objects, classes, methods, logic, like if-else statements, and also what a lot of the symbols meant. So I really hope this helped you get started. I'm very new at this.

I've been doing Java tutorials for a while, but like trying to do it all at once. was a bit of a challenge for me, so I tried my best. And of course, if you want more, I make a Java tutorial every week, and you can subscribe down below if you don't wanna miss any.

So as always, you could be anywhere in the world, but you're here with me, and I really appreciate that so much. I'll catch you in the next video.