Java Basics - For Complete Beginners | Grant Klimaytys | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Java Basics - For Complete Beginners

teacher avatar Grant Klimaytys, Software Engineer

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

15 Lessons (1h 22m)
    • 1. Introduction

    • 2. Setting Up Java

    • 3. What is Programming

    • 4. Hello Java Classes and Entry Point

    • 5. Variables in Java

    • 6. Operators in Java

    • 7. Homework Make a Simple Age Calculator

    • 8. Converting Variable Types in Java

    • 9. Methods in Java

    • 10. Comparing Stuff in Java

    • 11. Arrays in java

    • 12. Round and Round We Go Loops in Java

    • 13. Classes and Objects in Java

    • 14. Inheritance in Java

    • 15. Summary of the Basics of Java Programming

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

Have you ever thought, "I can't program" ?

I once thought that but I tried anyway. Turns out it was pretty easy and after a few months I became self employed, ramping up my earnings substantially!

Well this Java course is where you can start right now! I will guide you through the following steps:

- Learn very basic, newbie friendly Java coding in a few short lessons
- Begin to understand how to structure code
- Understand some fancy terms like objects and classes
- And other programming tidbits!

By the end you will upload a simple project to the project gallery showing off your brand new Java skills! From there you can start creating Android apps in your next course!


Meet Your Teacher

Teacher Profile Image

Grant Klimaytys

Software Engineer


My very first software program was the artificial intelligence brain of an underwater robot in the early 2000's, still the coolest project I have ever worked on!

Since then I have designed and built websites, software and apps using all manner of languages and frameworks. Javascript, Bootstrap, .Net, Python, PHP - you name it, I've probably used it.

These days I focus on building quality cross platform apps using Xamarin studio in C#, Xcode and Swift 2 and Android Studio.

If you're considering becoming a freelance developer then I can honestly say it is the best life in the world. You will have no boss, earn an hourly rate of $60 - $150 and take holiday whenever you want!

Of course you have to learn how to make good apps first, which brings me to my second pa... See full profile

Class Ratings

Expectations Met?
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Introduction: hello and welcome to this basic course on learning Java. Now, this course is for you if you've never programmed before or you've only programmed a little bit. And you have no idea what things like variables, methods, structures, classes. You have no idea what all that stuff means in this course. I'm gonna take you through step by step exactly what each of those things mean and how you can use them to create a program for your own needs. Now you're here for Java. Of what? You're actually going to learn of the basic building blocks of most programming languages. Such a C sharp, swift objective. See Scotland anything new and great python PHP, etcetera. So you're not just learning java here. You're actually learning to code. You're learning the fundamental building blocks that lets you make anything for mobile laps to software as a service to websites. Absolutely anything you can think off. So let's go through what you're actually going to do in this very short course here we start with ah, quite scary looking list off words that are probably not familiar to you. If you've never programmed before or if they are familiar, you might not know what some of these actually mean. So in this course, we're gonna go through every single one of thes, and once you have all of these or even half of these in your mind, then you'll be able to create almost anything you can think off. We're gonna go through variables. Variables is just a way off storing things in memory. Then we're going to look a operators, you know, operators already there something from maths Plus two plus two. Plus is the operator minus divide times and a whole bunch of others that are programming specific. Then we have conversions. So in programming we have, let's say, a number. But to a computer, it needs to know if that is a specific kind of number. Is it a number that's a word or did a number? That's the number. And I know that might not mean anything right now, but you'll see why that's important. When we get on to that, then we'll look at comparisons. Comparisons are ways that we look at two bits of data, two variables and we see if they're alike or if their difference and then we do something with that so a very simple example might be if I have two apples. One is red. One is green. A comparison would say, Is Apple one equal to Apple to on the computer would say no, because the colors are different and that's a comparison in programming. Then we have loops. Loops are valuable to go through lots and lots of data round in a circle, pulling one row at a time from a big long list of data and then doing something with it. Loops are everywhere in programming, and they're actually the biggest problem that we have as programmers in terms of making our programs efficient. So I'm going to show you how to run loops, what they're all about, and maybe give you one or two pointers toe. Watch out for when you're running loops in your own programs, then we're gonna look it. A raise Arrays are just a fancy way of saying a list of items. It's an array, so I have five apples on. If I ran a loop of those apples, I'd pull out one apple little time from that list and do something with the apple like slice it up and eat it then we're gonna have methods. A method is exactly what it sounds like. A method is just a way off doing something. So if I said to you, here is a method to make rice pudding, you get some rice, you put water in the rice. You add whatever else you need for rice pudding, you shove it into a pan providence, the oven and outcomes rice pudding. You would call that the method for creating rice pudding so you might say rice pudding cooking method. That's simply a method, and we used them everywhere in programming. Then we have classes. You can probably think of classes as a blueprint on how to do something so a class might be a recipe by itself. A recipe just kind of sits in the recipe book and isn't a manifest thing yet. So you have a recipe for a chocolate cake just because the recipes there doesn't mean that the chocolate cake actually exists yet it's simply a way off creating chocolate cakes or what you do is you. Then follow that blueprint that recipe, and at the end you have a chocolate cake, and that's simply what a class is in programming. It's a blueprint to create something. Finally, we have inheritance and inheritance is something that we add on to classes, mostly in order to have short cuts in programming so we don't repeat lots of code. I won't tell you what those are now, cause you can see for yourself as you go through the course. So I'm very much looking forward to teaching you all these basics. And once again, once you have all these basics down, you'll be able to program the basics off pretty much any programming language you can think off. 2. Setting Up Java: jump onto Google and search for J. D. K. Then click the very first link that you see, which is with oracle dot com. Oracle maintains and develops Java. Now when you click it, it tells you you can download Java S E, and you want to make sure that you have the J. D. K selected. So if I scroll down, there are many, many different things you can download for Java, however, you probably only need to click the first item now. One. This downloads page scroll down, and what we need is the Java SC development kit. So click accept license agreement and over a download, download the correct version for your operating system. So I'm running on a Mac. I'll get the Mac one. If you're running on Windows, you probably get the Windows X 64 if you're on Windows 10 nowadays. But check if you need the X 86 or X 64. Okay, you can also get demos and samples and downloads on this page, but don't worry about that for now. Simply get the J. D. K. Once you have the J. D. K. You've downloaded and installed it, preferably restart your computer, so everything registers. Then we're going to get to the actual item we will be using to create our Java code. There are many idee ease or development environments you can use for Java, the most popular of which is probably Intel E. J or Net beans. If you're making APS for Android, you would get Android Studio. But this is just a very simple short section. So what we're going to use is something called Dr Java, and Dr Java is very simply a way off compiling a Java program without too much fluff inside the program itself. So it allows us to write code and then compile it, and it's a great way just to learn what to do properly. So head over to Dr java dot org's click on the main page, and we want to download this jar file. Go ahead, click that, and once that's done, I use the direct link here. Once that's done will look at how to run it, and there we have our downloaded jar filed. If you double click it on a Mac, you won't be allowed to open it. So what you have to do is right click, then click open and then bypassed the security click open. You only have to do that once and then OS X will trust it in the future. If you're on windows should have no problem simply running that jar file right? That is Doctor Java installed and we are ready to go. One final thing is that down at the bottom, inside of compiler output, it tells you that you have Java installed and you have a compiler ready if you get errors here and simply go into the Doctor Java website and see what people say concerning how to fix them. 3. What is Programming: Now, if you are completely new to programming, it might be a little bit of a mystery to you. Why do we do it? What's it for? Well, programming is mighty simple to think about. If you think about Lego. Lego is comprised of different sizes, colors and shapes, off breaks. They're all little individual pieces, and by themselves they don't really mean anything. But what you can do as the builder is create items out of all of those blocks, and you can create pretty much anything you can think off. So that, in a nutshell, is really what programming is. It's taking all of these little tiny blocks on manipulating them, sticking them together to get them to perform a certain function like, for example, we've created a working house. So in this section, I'm going to teach you some things about programming. Whatever language we're doing it in doesn't really matter. But I'm going to teach you the correct way off handling all of those little blocks and how to put them together into things that perform a much larger action on a much grander scale . 4. Hello Java Classes and Entry Point: welcome to this very first lecture on Java in here. We're actually going to start creating our first Java program. So open up, Dr Java, and let's create something. Let's first look at how a Java program structures itself because you can't just jump in and start writing coat. The first thing you're going to see when you see a program is something along the lines of public class, my thing. And then you'll see this strange bracket, which is called a curly brace, and you'll see another curly brace that matches up to it further down. So in programming, these are an opening and a closing brace. Now what do public class? My thing, I mean well, public in programming generally means this thing that I'm about to write is available to other parts off my program. So public means exactly what it says. It's public. Then class tells our program or our computer that this thing we're about to write YSL contained inside of what's called the class, which is my thing, a class you can think off as a big storage box that you can put anything into. Okay, now we have our class, and how does Java know what to do or where to start. Well, every application needs what's called an entry point, and the entry point takes the form of this public static for weight main. And there's some more to write. But first I'll explain what we have here public, you know about static means that only one of these things can ever exist in programming. Now, don't worry too much about what that means right now, but static is a helpful way off telling our computer Hey, this is where you should come to start the program on. What does the computer do? It looks for a static main. So it's his oa found one. This is where I'm going to start the program running. We won't worry about void for now. I'll explain what that does later on an inside of Maine, we have something called a string and we have to square brackets one after the other and arcs. And what does this do? Well, we're going to get into that much later, but for now, you can just think about this as a little bit of information that gets passed over to our program when it starts, and then What we do here is open the curly brace and we close the curly brace until notice . Dr. Java highlights with Green The area between those braces. Now this is a simple Java program. How do we know this? Well, if I first saved this somewhere and in Java, you need to call your file my thing the same name as the class name. Otherwise it throws a wobbly. So I'll just say this on my desktop. And now we have over on the left hand side, my thing dot Java file over on the right, we can hit, compile, and down in the bottom there's a box that says Compilation completed. That's good. That means everything works as we expect it. So Java recognizes everything we've written as a valid and legitimate program. Thing is, it doesn't do anything at the moment, so let's make it do something inside of the public static main. Let's have a system dot out Don't print line. That's l n and type. Hello May or put your name there if you like, and that is a circular bracket before their and a circular bracket at the end, and then we have this text which is between two quotes. Now I'm going to compile this and I'm going to save the files. Then I'm going to click, run and down at the bottom of Dr Java. It tells you we are running my thing and it gives us this green text called Hello, me! And this is what this line does. Our system dot out dot print line will send us back some text. So that's really the very basic First Java program that you write. We have this thing called a class that holds all of our bits and pieces. Then we have this thing inside of that class that tells Java where to start our program and then inside of there we have some instructions that do things for us, and in this case we're simply printing out some text to ourselves. Now try and remember this lesson very well, because this whole class thing on the entry point of the application, it's very important and universally applicable to all your Java programs. 5. Variables in Java: welcome to this lecture on variables in Java. Last time we created our basic hello world program in Java and we learned that we create a class and we put code inside of that class. We also learned that this public static void main gets called as the first part off our application or the entry point to it. Now let's remove this system dot out dot print line. Let's just leave main. I'll create a bit of space in here and we first have to talk about variables. What is a variable and why would you want to know what it is? While the why is easy Because variables are the smallest building blocks of all programmes there, like the really small, tiny Lego pieces that you stick in key places in your models. What are variables? Variables are basic pieces off information. Now I can say to you, here is number nine remember the number nine and you remember it. If I ask you to write the number nine down, you could write it down. If I ask you to put it in your phone, you can do that too. But the thing is, with programming, we can say to it, Remember the number nine, But we have to tell it what kind of thing the number nine is. And that is the essence of variable. It's a kind of thing. So let's start with our number nine Example, which is called Interject an integer, is simply a whole number like 1234 or minus four minus 36. And the way we declare a variable interject in Java is by typing int and then put the space in. And then we type the name of the variable. So let's just call this the letter a. And if we want to make it equal to something, we can type equals nine. And then in Java, we put a semi colon at the end of our line to indicate it has finished. Now our program holds this variable A, which has nine stored in it. Off course you could do the same with into B is equal to 10. Let's hit, compile, and everything compiles nicely. There are no errors now. What if I want a decimal number? Well, let's try. Int C is equal to 9.87 now hit compiled who and we haven't era, and whenever we hit, compile inside off any I d. E. What we're doing is we're asking the program to translate this to code that can be run and interpreted. And if it finds a problem, it will tell you. And this is good because you don't want problems to happen when someone else has your code . Because when that happens, your code crashes and the whole program gives up, so it's much better to find. Your hair is now right down in the bottom. We have possible loss off precision required int found double. Okay, what does that mean? Well, this is a pet peeve of mine, and it's that whenever we compile things, it gives us cryptic messages. If we are beginners, if you're an experienced programmer, then this is no problem to understand. What this is saying is that the integer C on this side cannot hold something with a decimal point in it. It can only hold a whole number so it could hold 987 but it cannot hold 9.87 because inter jizz are simply whole number stores. So how do we get around that? Well, we can change it to something called a double and a double. If I click, Compile does allow us to store a decimal. There are many different kinds of ways of storing numbers in your programming, and each of them has their limits. If you're doing really big maths, you probably want to try a double or what's called a long. Alternatively, if you have lower numbers, you can define what's called a float float. De is equal to 9.86 Now let's see what happens if I compile. We have an era, and that's because floats need to have an F at the end of them. And when we click compile, everything works fine now. So always remember that doubles don't require anything added to the number floats require an F at the end. Now, whilst we're on this subject off numbers, what we're going to do is print out these numbers and see what our system says they are. So we weren't system don't out Dr Print line. Open your brackets and let's output see first. And then let's copy that over. Drop it in and then output D Now I'm gonna escape to change D to 9.87 So these are nominally the same number. I'll hit, compile and then run, and that's correct. They're both the same number. Now. You may ask why I've done that well in the subsequent lectures where I go into operators like addition, subtraction, multiplication, you're going to see why I did that and why. It's important to know what kind of numbers you're working with, right? Just going to remove the system outlines and go over to more variable types that you really need to know about, the first of which is what if I want to store something like a one or a zero, True or false? Well, it's a special type for that, and that is called a Boolean that's called this e is equal to, and we define it by writing true bore false and these kind of things help us to keep track off the state of an application. For example, if I was playing music and I hit the play button, I would say Boolean is playing is equal to true, so I know my music is playing. If I hit the pause button, I would say Boolean is playing is equal to false because the music is no longer playing, so these are very handy to help you keep track of what's happening. Finally, what if we want to store a word? Well, that is simply string if is equal to and then we open up our quotes and put our word in clothes are quotes and put the semi colon in. Now we have what's called a string on a string holds a bunch off text for us. Now, one final thing before we end. This lecture is we cannot mix these types of variables, so I cannot say integer G is equal to name, because if I try and compile that, I get this horrible era that says, Hey, dude, you can't put a string where I'm expecting an integer. And of course, this works both ways. So if I try to write String G is equal to seven and I compile it. I have the same era just the opposite way around. It requires a string, yet I gave it an integer, so just know you cannot mix and match your variable types, and this is called typing when we program not typing as in the keyboard, but it means that our variables have to stay will be put in a particular kind off box. Okay, that's pretty much all there is to these simple variables. There is a lot more as we go on through the course and you'll see we can expand on this idea of variables, so stay tuned for that. But in the meantime, that is variables covered. 6. Operators in Java: Let's discuss one of my favorite topics in programming, which is operators. I know it sounds a little sad, but hey, I am who I am. These things fascinate me, and you're about to see why. Let's start with our basic public class called My Thing and inside off our public static void Main. Let's write some code. Let's have a interject. A is equal to 10 and an insurgent B is equal to 11 now. What does it operate? Well, it's simply something like addition or subtraction, multiplication and division. So let's see what that looks like. Let's have a system dart out dot print line and inside the brackets, let's have a plus B and we want a lower case Be now. When we hit Compile, it should compile fine. And when we click run, we get a result out off 21. And that's what we expect. It's added A and B. What about subtraction? Let's compile it and run it. We get minus one. That's fine. Let's multiply, compile and run. 110 which is also correct. Now he has the tricky bit. What if I divide, compile and run? We have a result off zero, however 10 divided by 11 is more like no 0.9 something. So what's happened here? Well, when we divided an inter job by an integer the type the variable type that we get back is also an integer. And if you recall inter jizz only store whole numbers. So what does the system do? It simply drops out the point part, which is a little bit inconvenient, you might say, Right, let's try with a double instead hit, compile and then run. And now we have our long number North 0.9 known. I know and I know etcetera recurring. So that works with doubles. Now, if you recall in a previous lecture, I said, We have to watch out For these types, a number isn't just a number, so let's see what happens if we copy these two. These three lines paste them below. Let's change these two floats floats on. Let's call it C on D D. Let's have C divided by D. Now, when we compile and run this, we might expect the result to be the same. But look at that. When we use a double, we have much more precision when we use afloat. We have less precision. So if your program or APP is doing something maths based, then you have to be very careful as to which kind off variable you're using cause division , for example. And this is a prime candidate for errors. We'll just drop the decimal point of your number. Floats will give you a much shorter number than you expect, and doubles take up more memory to give you a longer number. So in the future, when you're making your raps, really think about these points, right? Just going to remove some of these lines to give us some space. And what I'm Gates do is define a string. A is equal to grant, and let's make a String B is equal to is on a String. C is equal to awesome because I have to say it. No one else will. Now we can add strings together so I can say a plus B plus C. And when I compile and run this, it does what's called concatenation, and that simply means putting strings one after another. When were Comcast in ating strings? We can also add other strings on the fly, so my sentence has no spaces. I can add quotation space quotation and after b I could do the same, and this is going to add two spaces into my sentence for me so you can add strings on the fly. As you might expect, you cannot subtract strings. You, of course, cannot multiply them, and you cannot divide them. You can only con captain eight strings. You can remove strings from the end of existing strings, but that's a more of an advanced topic, and you'll come across that bit by bit in your Java development career, so that handles operators inside off Java in a very basic sense. 7. Homework Make a Simple Age Calculator: Here's a little homework to challenge you and test everything you've learned so far. What I would like you to do is put your age into a variable. Then I would like you to put your mother's age or your father's age. If she doesn't like her age, going out in your videos into a variable and then I would like you to add, subtract, divide and multiply those two values and print out all of those four results in one go so you can use all of the tools I've shown you so far to do that. I won't give you any answers for this because I think it's much better if you attempt this by yourself. And that, in one sense, is what you have to do when you're learning to program is you have to challenge yourself like this without readily available answers, and you will learn so much faster. So good luck with that task 8. Converting Variable Types in Java: converting variables in Java. Now, this is not something I'd recommend you do if you can avoid it. But sometimes you simply cannot avoid it. So what do I mean by conversion? Well, if we have a string a equal to three as a human, we can read. That is a number that's fine, but a computer cannot. So if we try to do something like in to be equal to four and then we said Sister dart out dot print line A plus B. I think you know what would happen if we compiled it and then tried to run it. Or maybe you don't know what would happen because we have a result of 34 and what job has done is assume that you want to convert this four to a string. So it's added three plus four in the string sense and given you 34 now you can see how this would cause issues. So what we're going to do is try and convert our string A to an integer before we run our arithmetic. So let's try int c is equal to inter Gia, and when we put the word integer on brackets like that we're doing what's called casting and we're saying Take the value of A and cast it as an integer Now this is something you're going to see around the Internet, and it's not wrong in and of itself. But in Java, at least if we try and add B and see if we try to compile it, we will get an era. So if you see this kind of thing around the Internet, feel free to ignore it. What we have to do instead is say in C is equal to inter gia DOT has in and then we give it I was string inside off brackets, then Java goes and does some clever calculations and works out that you can change this string to a number, gives you back the string and now when we compile and run it, we get the correct result off seven. However, if I change my string to my name, I compile we get Nowhere is on compilation. But when I run it, we get this horribly long error here and all that saying is basically Hey, man, I can't turn a word into a number because I'm not a magician, so that is how you can convert from a string into an integer. Now what if I have an integer or some other kind of thing that I want to convert to a string? Well, you will find that you can use a method called Dot to String, but there's a little trick here that a lot of beginners get stuck on. If we simply use it on the interview a that I've declared here, you're going to find that let's a string result is equal to a dot to string, and you'll find this all over the Internet. You'll try it out by compiling, and it will tell you integer cannot be d referenced. What does that mean? Well, basically, the error that you're getting is the fact that we do not have a two string method for this declaration. Off interject. What we have to do is declare this Inter Gia in the following way into J A. Equals nine. Now, if we compiled, it'll work because we now have access to the to string method. What if we have something like a double that we want to convert to string? Well, if we compiled that, it wouldn't work so what we're going to do on the string result line is access the double class, which has the dot to string method, and we pass it over the actual double that we want to convert. Now, when we compile everything, compiles happily so generally inside these classes, like inter during double, you will find a two string method that can grab a primitive variable. So let's try that with integer and change this into your class. It's compile that that also works. There are many other kinds of conversions, but look those up as and when you need them for now. Like I said at the start of this lecture, if you can avoid this conversion situation, then by all means do. 9. Methods in Java: methods in Java now methods is a generic programming term. That means basically a block off code, and it's kind of a container for this block of code. You may not know it, but you've already come across what's called a method. This public static Freud main is a method. It contains a bunch of instructions that get executed for us. So why would we ever want to do things like putting our code inside of methods? Well, I'll show you why. Let's have into a equal to three and be equal to four. Then let's have int C equal to five and into D equal to six. Then, of course, we can have our integer result. One is equal to three plus four. Rather, that's have a plus be Let's have integer results. Two is equal to C plus de. So now we have two new numbers. One is called result. 11 is called Result to that adds them for us. Now. This doesn't seem like a lot of hard work, But what if we had 2000 numbers and we wanted to add them all up between them? Can you imagine writing 2000 numbers or lines of numbers and then 2000 operations. Well, I bet you count, and this is where methods come in very, very handy. So let's define a method before we see why it's handy. Underneath, off the closing curly brace off are void main. Let's have a public static for now. Void and numbers. This is the name off the method, just like Mane, is the name of the method here, and we're going to pass this over an integer called A and a interject called B. Then we open our curly bracket and close it. You may be wondering, How is this A and B related to this A and B, and the answer is, they're not. Everything contained inside of a method is only reference herbal. By that method, that means only all of this code can see those inter jizz any code inside here. I cannot see these images. They basically don't exist as far as its concerned. So I could have as many methods as I like where I haven't A and A B, and those A and B's won't get mixed up in inverted comments. They'll always be separate. All right, so we created our method and what do we want to do in it? Well, let's say int result is equal to a plus B. Then let's print out the result system dot out dot print line result. Now we can come back into our main method, and we could get rid of these two lines and simply call add numbers, which will ask us for two numbers. So let's have A and B and let's have another one at numbers off C and D. Now let's compile. Everything's okay and let's run and down here we have our results printed out. So can you see the power of methods? Now, instead of writing out the additions here and then the system print line, we simply said Goto add numbers and pass it these two items So off it went, gave it the two items which were added and then printed. So methods are a way off enclosing first of all, a bunch of instructions we want to execute, and secondly, there are a great way to decrease the amount of code that you actually have to write. There's a fundamental rule in programming that you should make as many methods as you as makes sense, basically not as many as you can, but as many methods as makes sense for your program, and you should name them things that make sense to humans reading it. So add numbers tells me exactly what this method does. 10. Comparing Stuff in Java: one thing that very frequently comes up when programming, no matter which language, is the need to compare your variables or some kind of objects. So let's look at how we do that now. In Java. It's a little different if you're from various other programming languages, and there are a few Gutches that you need to watch out for, and what I'm going to show you in this lecture is the more correct way to do things as off the latest J D case. So let's have to inter jizz integer A is equal to nine, and Inter Giambi is equal to nine as well. And how do we compare these? We use what's called an if statement and then in brackets I'm going to show you the older way of comparing things. If a is equals equals to be open your curly brace and close it. A man inside of here, we can have our system dot out doc print line, and we will send ourselves an equal message back. So what this line does is compare a to B and if that if they're the same value and there's a bit more to it than that. But for now, just think about it in that way. Then I would like you to print out equal. So if we compile that and then run it, we now get our equal printed out. Now, once, if they're not the same, well, we can have an else statement that goes hand in hand with if and we open our curly brace and close it. And again we can have system out dark print line to tell ourselves not equal. And then let's change the value of B two B 93 compile and run. And now we get numbers are not equal now what if we want to go the other way round? So we want to check if a is not equal to be Well, this is simple enough. Instead of two equal signs, we have an exclamation and then an equal sign. And that simply means not equal to generally in programming you, when you find an exclamation mark, it means not. And so here we can type not equal exclamation really can't spell exclamation or equal. And if we compile and run that we will get not equal exclamation. So that's how you check for equality and non equality with numbers such as interviews or doubles or floats. But what about strings? Well, let's turn these into strings and another string. Let's call this my name and let's have the other one as my name. Now let's try and compile this. That's fine. Run it. And it tells us that these strings are equal. Now is a little gotcha here. When we are programming in Java and we're using stringy qualities, we do not want to use this notation I won't go into why? Because that doesn't really matter. Here. I'm simply trying to give you a jump start in the Java world. So when it comes to comparing strings, we should use a dot equals and then in brackets B. And what this does is get the actual value from B and compare it to the value off A. It may seem the same as with the equals equals signs, but in the background, it's not really and tow. Avoid ariz in your programs. Always use this notation for your string, I said. I will compile that and run it, and it tells us, Oh, we have a slight error. In my logic, they're not equal because I've changed the logic into equals instead of not. And let me put, not equal here. Re compile that and run it and they are both equal. Okay, now what if we want to check if these values are not equal and then we want to add a further check down the line? Well, we could do something like this. So the 1st 1 says equal and then underneath off the first if statement, we can have another else. If so, we can check something else. And for example, we could say if a or exclamation a dot equals B and that means a does not equal be. Then we can perform another function. So systems are out, Dr Print line not equal. And then we can have a else that gives us a default statement or execution. Now, what this is doing is comparing equals here. And then it's saying, If this doesn't work out, then comes the next one. And if a doesn't equal be, then do this. But if that doesn't work out, then come down to this one. So it kind of goes down in little systematic process checking which one it should run and you can have as many, if else statements as you like, all chained up together. So if I put grunt to up there, hit, compile and run, I have not equal. Let's skip the 1st 1 found this one is true, so it skips the rest of them. Now, in this case, it doesn't make sense to have three because I've their equal or not. But in other cases you will have a need for this. For example, if you're trying to compare some, use the input that's come back and you want to compare 10 things that could come back. You would use something like this. However, it starts to get a little messy, and program tends to run on if you have lots of, if else statements all chained up. So there's an alternative for comparisons in Java, and that is a switch case statement. So let's remove all of this. If else code. Let's also remove string, be and create a simple interject A, which will be equal to four. Now we can create our switch statement so we do that by switch open brackets re pass it over our interview. Then we opened some curly braces and close them inside off those curly braces, we start defined cases. So if we have a case, where are in such A is equal to three. We put a coat on in and then we write some code to execute. So we put something like System got out dot print line three and then after that and this is optional. We put a brake statement that tells us to stop executing this case. We can also have a case where by Inter Juries four and we can put a system out print line that returns for. And of course, we can break out of that once it's done so we can have as many cases as we like, and it's advisable to have a default case and this you defined by default, and this will be system out default. And then we break out of that one. Let's compile that and then run it, and it tells us our system out is four. So those are switch case statements, and if you ask me, they're a little bit neater, a little bit more organized than if else statements. But those two methods together provide all of the comparison power that you need inside of Java 11. Arrays in java: a raise in Java. First of all, what is an array where youth can think of an array as a list of items that are stored inside of one variable or container or box? Or however you want to think about variables? They're very useful because it's nice having a list of stuff that we can access using just one variable you can imagine. If we had 100 names we had to store and we every time we wanted to access the name, we'd have string a equals grant and String B equals etcetera, etcetera. Writing that 100 times is pretty painful, so that's where a raise come in extremely handy. So let's learn how to define an array. We do that by first typing the type of variable we're going to put in the array, and then we open a square bracket and close a square bracket, and this means we're going to have an array or list off strings. Then type my strings as the variable main is equal to open your curly brace and start adding the items that you want to have in your array. So word me, whatever it is, la P and close off your line. Now we have an array with three items in it. Cold, different names or strings. So how do we access, say, string number two or one or three? Well, let's look at that. Let's have a system dot out dot print line and we're going to print out from my strings. And the way we access a particular item in the list is by opening a square brackets and then giving it the number where that item lies. Now, in a raise and in programming in general, the first item lies on the index zero. So most programming languages use what's called a zero based index. Item number two lies under one and item number three lies under index to. So let's pullout index number one. And we should get the word me transmitted back to us when we run it. And there we have it. So if you're not familiar with this indexing concept, if you only take away one thing from this lecture, it should be that indexing is zero based as a general rule in pretty much every programming language you can think of, right. We don't just have to have strings. We can, of course, create a raise off in Tages and we will call this my intense is equal to, and we can pass it over any number that we like off inter GIs close off our brackets and declare the line. Accessing the inter jizz in here is the same as with my strings. There's one final thing we need to know about a raise that you'll come across very often because when you have an array, you might want to loop through it until the arrays empty. So one final piece of information you need to know is how long is my array, how maney elements are inside it the way you find that out? And I'm just going to do a system got out dot print line for this is by accessing the array dot length property, and that counts the number of elements that you have in your array. So in my intense we have six elements. Then if I compile and run, we get the number six presented back to us. That's gonna come in handy when we look at loops in Java so we can extract all of the values out of an array. Knowing the length is also useful. If we do something like accessing a certain element in the array, as long as we have the maximum length of it, we can make sure using some careful coding that the index never goes past the maximum element. Because if it does, we will get some kind of era. And I'll just show you what I mean. If I change my strings to access Element number five, which doesn't exist, way to compile, which is fine. Then I'll run and look, we get this red writing that tells us the Array Index is out of bounds, as in, Hey, man, you've gone past the line and I'm going to crash now. So if inside of this system out statement where we accessed Element five, we could also have something like an if else statement that checked that we could actually access Element five, that's just a side note. So the main thing to take away from this lecture is the construction of a raise and the fact you can put different types off a raise together 12. Round and Round We Go Loops in Java: round and round we go loops in Java. Why do we want to know about loops? Because they save us a lot off time when we're doing things like traversing through a raise . For example, let's see what a loop actually looks like, where one version is called the Four Loop, and if we open our brackets, we can say int I is equal to note. Semi colon I is less than 100 semi colon, I plus plus open curly brace and close curly brace. So what does this do? Well, the first declaration is an interject called I, which we set to zero. So the loop starts with I equal to zero. The loop runs round and round until I is less than 100. If I hits 100 loop will stop running. Each time the loop goes around, we add one toe I by using the shorthand notation I plus plus, let's see what that looks like. Let's have a system out dot print line and let's feed ourselves back I and compile, then run and watch the bottom screen. We loop through 100 times from 0 to 99. So that's what a look does. It goes round and round until some condition is met and it stops executing. So now this is very useful if we have an array of stuff and we want to pass it back to ourselves. So string my strings is equal to open curly brace and you can say something like wood may grant. Then close it off. What we can do with this is, say, four string value that should have a space. Sorry, value my strings system dot out dot print line value and close off your brace. So what this loop is doing is saying every time you encounter a value or an element inside of my strings, print it out. And then when the loop goes round again, it grabs the next element in line. So it'll start on this one, the 1st 1 Go to the next one and finish with Grant. And if we compile and run that we first get the 100 loop and then word me, Grant, This is a nice shorthand way off getting all of the elements out off an array. There is another way off creating a loop and this is called a while loop. And what a while. Loop needs is a counter for itself. So in the same way as the Four loop had this, I counter what we have to do outside. Off the while loop is defined, our interview I equal to not. Then we create a while loop and we say while I is less than 100 do the following code. So let's have our system dot outdoor print line off I. Then we need to manually add one toe. I each time we go around I plus plus close off our wild statement. It's now compile that and run it, and there we have our second result. So a while statement is handy when you want to check for a certain condition. But you have to be very careful with wild statements. If you forget to do something. For example, the I plus plus you can compile your program, but when you run it, it's going to run forever because it is stuck in a loop and that loop will just go on and on and on. So be careful of that are going to reset my project and put in my I plus plus again, always make sure you have an exit condition from any off your loops 13. Classes and Objects in Java: welcome to probably the most important lecturing programming you will ever take. So pay attention to this one because it will be useful. Threw out to your programming career. We're looking at classes and objects, so let's start by creating a class just a side note. We already have a class, which is this public class, my thing, but we're going to ignore it for now and take this from the beginning so we can really understand why we need classes and why they're just so useful. Let's create a new file and let's right click. It's Save the file as and call it a car dot Java and dot Java will be added automatically for us now in Java. It expects your file names to be the same as your class names. So we're going to make a public class called Car open all curly braces inside of this class . We're going to give it a few properties, and if you think about a car, it has a property called perhaps int speed and a string color. It will also need to have what's called an initial Isar, and a class in most programming languages needs to have this inside of it. An initial izer is basically a method that kicks everything off in the class. We define an initial Isar by the word public and then the name off the class. There are no voids or statics here inside of the initial Isar. We're going to pass over some of the things that we might need, so we might pass over an integer speed and a string color. Then we open our curly brace, and what we're going to do is make this speed in the class equal to this world. So to do that, we say this dot speed is equal to speed, and this dot color is equal to color, and this passes over these items into our class variables. Then we close off our curly brace for the initial Isar. Let's make another method called public integer, because this will return an integer. Let's call it, get speed open and close your brackets. Open a curly brace and return this dot speed. Close your curly brace. Let's do the same. For color public, get color or rather, public string, get color and return this dot color pleasure. Curly brace and close the class curly brace So if we look at this from the 10,000 foot view , what this whole class does is define something called a car. It's kind of like a blueprint, and when we grab our blue print and we create something out of it, the blueprint requires us to provide a speed and the color so we can then apply that speed and color to the car, then later run. We can also get the speed out of the car, and we can get the color of it. So save that file and let's look at how we create a car out of this class. Back in my thing dot Java in our static void main. Let's create a car called Toyota, which is equal to a new car, and this new car expects a speed 50 and a color read. So now we've created what's called an object, and this object is called Toyota, and it's type is of car. It follows this car blueprint. We can create another car if we wish. Car Ferrari is equal to a new car with a top speed of 200 and color green, because it's kind of a different Ferrari. Now, if we compile this everything compiles fine. And we have two objects a Toyota and a Ferrari, and each of those is different, so we can print out our system dot out dot print line. The Toyota dot get color, and we can also copy that and print out the same for our Ferrari. Don't get color, compile and run, and we have red and green. So classes such as Car Dutch over are the blueprint for things that we will create. They are not things in and off themselves. When we do what's called inst enshi ating that is creating a new object from the class. Then and only then do we have a thing or an object. And every time we in Stan she ate that class, we can create a different object. So class is a very handy in terms of cutting down code and taking care off things that you need to define multiple times. You can create as many objects as you like out of a class, so that is the power of classes. Learn this lesson well, and if you've got the time, please go back and redo this lesson because this classes and objects idea is absolutely fundamental to all object oriented programming. Whether it's swift objective. C C Sharp, Java, it doesn't matter. You will use this idea time and time again. 14. Inheritance in Java: last time in this little Siri's, we learned how to create classes and objects, which I said was a fundamental part off all programming. So in our example, we have this class called Khar and what we're going to learn is inheritance, which again allows us to cut down the amount of code we have to write. What is inheritance? Well, it's a way that a new class can absorb information from an already existing class. So, for example, if I wanted to make another class called Big Car, I could allow it to inherit from this class. Let me show you exactly what I mean by that. Let's create a new file right click safe file as big car. Now let's create the class itself. Public class, big car. The way we define inheritance in Java is using the keyword extends and then the class that this extends from so car open. Our curly brace inset our public constructor big car, open curly brace and close it. Then what we can do is we can add another property to this so we can add, for example, a string sighs is equal to large. Then we can give ourselves an access method public string. Get sighs, and this will return this dot sighs and close off our brace. Close off the class brace. So what this is doing and make sure you save that is its grabbing everything it can from car. So it's grabbing all of these properties. It's giving them too big car, and then big car itself is adding a couple more bits and pieces to it. Now, for the sake of simplicity, I'm just gonna modify my car dot java so we don't have to pass over any arguments, and we remove all of these items in the constructor, and we simply make our speed equal to 80 and all color equal to whatever we like. Okay, once we've done that, let's check out big Kardak Java and open up our my thing dot Java. Then let's remove the Ferrari and simply have a new Toyota. Let's also construct a big car called a Caddy is equal to a new big Come compile that, and as long as it works, everything now works as it should, and what we can do is have a system dot out dot print line that allows us to get our caddy dot Get sighs, compile and run that. Whoops. We have a slight error. Let's check out big car dot Java. We have our this dot size, so I'm not sure what this is trying to do. We have a capital s in system, compile and run, and it tells us a caddy is large, but equally we also have a get color for the caddie, which is red. And that's because big car inherits from car, which gives big car all of these properties and methods accessible to it. So that is the beauty off inheritance in Java. We don't have to construct the wheel again or rebuild the wheel. If we have a class, for example, called Vehicle, we can derive cars, trucks and motorbikes from that class using inheritance. So my advice to you in Java is to use inheritance wherever it's possible and makes sense that's important. That last one. It has to make sense, So anyone going through your code later run will understand intuitively what you were trying to do. 15. Summary of the Basics of Java Programming: So that is your very basics in Java. Lessons complete. Now, by no means have I gone over everything there is in Java because if I had, you probably would have bean board by the course and put it down straight away. So I've just covered the absolute essentials that you will need when programming. And here's a quick reminder. You've learned about variables operators plus minus divide how to convert between variables , how to compare them. Then you looked at loops, arrays, methods, classes and objects, which, in my opinion, is the number one thing you should take away from this tutorial. And finally we looked at inheritance, which was another way to extend your classes. So that's what you've lent. Where can you go from here? Well, now you're set to go and do something like an APP development course in Android. I provide a couple of those and depending on which platform you're watching this, you confined them underneath the list of items that I'm teaching. You can also create Java based desktop applications or Web applications so well done. Congratulations on completing this course, and if you felt like you learn something, then please do leave a review