Transcript for:
Java Programming Tutorial - Key Concepts and Basics

if you're struggling in Java don't worry because I got you just take a nice deep breath sit back and I'm gonna show you everything you need to know in Java this video is made so you could just watch it on your phone or follow along if you want I've been programming in Java for over eight years now I graduated with the 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 pass through the projects so it was really hard for me but I don't want to make it hard for you I want to 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 computer's 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 key words 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 well you see on the screen now is a programming environment this is where you write code you can read 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 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 of the project name like Java - for real epicness hit finish next expand that up right click on the source folder and get a new class and this is just our Java file well 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 key words and symbols and it looks like this Java file already has some keywords cymbals in here for us a super useful thing we can do in Java is stored data so you can store say a number variable in Java by doing this it's 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 it's going to list a few so here's a few more this 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 in 2b and get 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 not 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 user name say on Instagram it's got a store at somehow right so to store like a name like a bunch of character variables that would be called string with a capital S there donate like in 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 parentheses 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 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 act test 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 dot out dot print line 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 control S or command s to save it then we're going to 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 I 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 call 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 gonna be a method and methods are amazing they're the bomb cuz they just do things for you like 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 keyword it's 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 X Kwame ssin points parentheses it's a 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 going to 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 and 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 hotdogs now we can save it and run it and we see hot dogs with the next formation mark this right here goes here and whatever's inside of these curly braces gets rough 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 going to show you how to use 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 want to use the I am dog method we can just I'm just gonna save it go in here I'll delete this code for now to call I am dog you can just make an animal object like this animal a equals new animal anytime you're making an object it's gonna have this format and 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 I can just click it and then store that into a string Doug and then print out dog save it and run it and now you see that I am dog message being returned to the variable dog so what class is just a Java file that helps us make objects examples of commonly used objects our ArrayList has the same more 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 an ArrayList you can do things like add can add a bunch of items like this is how they store movies or a store a list of users you can replace stet 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 oo P 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 will 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 today like true and then it would run the code inside of here this is useful if you have something like a is equal to 5 if a to equal signs if a is equal to zero then run this code you tack on another one otherwise if a is equal to one then we want to run this code otherwise if it's something else completely then run this code if-else statements are super useful you can repeat code by doing a for loop and a for loop format has the keyword for some parenthesis and then a format that kind of looks like this in simple terms this will repeat the code inside of here 5 times you can change it changing this number 8 it will run this code eight times we can put a for loop inside of a for loop which makes it really interesting just got to change this variable now whatever is in here will be run sixty-four 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 say like wow a is equal to five you can print it out hi actually let's see well a is less than 50 print high and then increment a by one each time that's what plus plus means let's just call do stuff so we can see what's going on go into the main method whatever is in the main method will get run when you click run so we'll just make our animal again say a and that a period to bring out what we can do and now we can see our do stuff method if we run it we'll see high print out a lot and then it'll stop until it gets to 49 because it start at five go up six seven eight nine all the way up until 50 and I'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 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 api's that you can use and bring inside your program and do cool stuff until you 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 that's pretty much everything you need to know about Java it went over primitive types variables storing data objects classes methods logic like if else and also what a lot of this 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 want to 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 [Music]