Java tutorial for complete beginners with interesting examples - Easy-to-follow Java programming

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

I'm new to Java (and more or less to programming as well) and this video has a great pace for me. I also like the idea of fighting fantasy in it. Thanks.

👍︎︎ 4 👤︎︎ u/wasteyourtime17 📅︎︎ Jan 08 2016 🗫︎ replies
Captions
you [Music] you hello my name is Daniel pastor and welcome to the Java programming course let's see first about this course via cover first of all we will see some concepts of the Java and then how to store data in variables and types and how to read data from the user and how to print data to the user and then how to do simple calculations the programs are just like reading books so you read from top to down from left to right and if this is not OK for your program then you can make conditions that controls which parts will be running and which part will not be running and if you want to repeat the part then you can use loops and we will see how to use some tips and tricks in them that means how to debug the program and what the bug means how to use the code templates which are abbreviations of these statements that we will use we will reveal the secrets of basic algorithms so how to sum up elements in the series how to count elements that are appropriate to condition how to determine minimum and maximum of the series and how to search inside and then the arrays they are multiple elements together and Vivier see how we can use one dimensional and how we can use two-dimensional arrays they are just like the spreadsheets and then the functions and structured programming functions are very similar to the Jeanne's we can assign tasks to Jeanne's and then invoke and they will do what we want them to do and based on the ginnis with a herd of genes we can create a whole program and they are very useful for constructing the program and structuring the program since the Java is an object-oriented programming language we will see what classes objects are and how to use the inheritance for creating new classes out of the original ones and what the polymorphism is we will see how to handle dates and times there are two methods one old and one new the new one introduced in the Java 8 so we will see both of them and then how to sort elements and why it is useful and what the benefits of the sorting are there is an interesting part of the Java this is the generics and we will see what the secrets of the type parameters are we will see what the collections framework is they are classes that are useful for storing objects in different ways we will see what the list the set and map are and then if something goes wrong than the Java will create and throw exceptions and we have to catch it and return back to normal state how to do this and what this is in the background of the file handling derived streams what the streams are how to use them and what the properties are properties are for using the any files and if a variable can contain only a specific set of values then we can use in ants an example is the days and they choose the events day so if we have only these values then it is worth using enums for that and last but not least when we would like to do something maybe someone else has created a solution for we don't have to reinvent the wheel so we will see how to use other people's work in our programs during the course we will write a lot of exercises because programming is just like martial arts you cannot learn it from books you can learn it by exercises so we will have smaller exercises that demonstrate the different aspects of the programming language and we will write a simple computer game which is a role-playing game in which you are the hero the idea is based on the fight in fantasy the fighting fantasy game books are created by Steve Jackson and Ian Livingstone and via the normal books I read from the chapter one to the last chapter in the fighting fantasy books you can decide in each chapter where to go what to do an important thing in these game books are the dice we will use dice to create the different attributes of the character and we are using dice to fight with monsters just like any other fantasy words the word of the fighting fantasy is very colorful it contains a lot of different monsters in our program we will simulate the fighting with these monsters until death let's review what we will do in this video first of all some basic concepts about the Java and then we will install our working and learning environment the NetBeans and then we will write the hello world project this is a very first program you write when you start learning a programming language and then I introduce the variables and types which is a concept for storing data and then we learn how to read in and write data for the user and how to do simple calculations if you learn the conditions and based on these conditions one part of the program will run and the other part of the program will not run and last but not least we start the UI the hero program we will write the first part of it as you might know the Java is a very popular programming language if you read statistics on the Internet all agree that the Java is in the top three most popular programming language and some of them say that Java is the most popular programming language and you might hear the expression three billion devices run Java and Java is a platform independent programming language that means you can write your code once and you can run it anywhere and there are a lot of well-paying jobs this might be very interesting for you because there is a great demand for Java developers and you can have a very good and well-paying job if you learn Java and it's widely usable if we consider the Java platform as a tree the tree is based on the basic computer skills that is folders operating systems running programs on the basic computer skills there is the programming in Java after learning programming Java you can learn basic Java tools and after that you have three options you can be an mobile application developer you can be a desktop application developer or you might go to a huge company and develop enterprise applications inside the mobile applications a very big part is the Android 60% of the market is the Android there is another technology Java ME it was quite popular before the Android but now it's less important nowadays the second option is the desktop application development you can develop games you might know the Minecraft it's a quite popular game nowadays and it is completely written in Java or you can develop software tools for example NetBeans and Eclipse are written in Java we will use NetBeans to learn Java programming and if you are a researcher it might be interesting for you that there are a lot of applications that are developed by the Java in the research field the third option is that you go to a huge company as a developer and it might be interesting that 90% of the fortune 500 companies use Java if you go to a huge company you might develop ecommerce applications or banking applications or huge back-end services in this course we will cover the first two topics the programming in Java and basic Java tools as I said the Java is a platform-independent programming language what does it mean let's suppose that you as English speaker person you travel to Europe and as you might know Europe is a multicultural continent there are a lot of languages so let's suppose that if you look at a pretty girl you want to tell her that she is a pretty girl she won't understand you so what can you do in this situation you can translate your message with a device you use your mobile phone and you use your translator on your mobile phone so you type in what you want to tell the girl and it translates to in this case Italian and the girl understands you this is the compilation when your message will be transformed to another version that is understandable for the other party in the computer field you are the user who wants to do something and the computer won't understand you unless you translate your message to the computer this is the compiling what other options exist in this case the other option is to interpret the message the situation is the same and you hire someone who speaks English and Italian so you tell her your message and she interprets your message and the girl will understand so as you might see this is a slower method of communicating with someone in the computer field if you would like to tell the computer something then you can use another program that translates your message on the fly and this is the interpretation okay let's see the Java style Java is a platform-independent programming language what does this mean let's consider the situation you are traveling through Europe and you want to talk to everything pretty girl you introduced so her and her in this case you might use your mobile phone to compile your message to a common language in this case we will use the Esperanto language which was intended to be used as a common language throughout the world without any success so in this case we compile our message to Esperanto and we hire some other persons who will understand this Esperanto and the native languages and we show the interpreters this message and she will translate the message for the pretty girl and pretty girls will understand the message so in this case in the java terminology the output of the translator the output of your mobile phone is called the bytecode and the interpreters that interpret your message your translated message are called virtual machines if you start dealing programming you might hear a lot of abbreviations expressions just like gr e IDE GDK gvm NetBeans and Eclipse what are they and what do you need for starting programming in the core of the Java is the Java Virtual Machine in our analogy that was the girl who was hired to translate our compiled message from Esperanto to the native language this Java Virtual Machine is the part of the Java Runtime environment the GRE this software is needed for you if you would like to show your program to your mom to your spouse or to your kid you have to install this software to their computers if you want to make Java programs you need the Java development kit in our analogy this was the mobile phone with the translator the Java development kit contains the Java Runtime environment this you have to install it to your computer but using this part is not so comfortable it's more comfortable if you use integrated development environments for example NetBeans and Eclipse they are very popular and because the NetBeans is easier to use for beginners in this course we will use the NetBeans okay let's see how to install the NetBeans and the JDK first start a browser and in a Google search let's search for GDK NetBeans 8/8 is the version and the first one is the NetBeans plus GDK bundle this is what we will need and in the download page first accept the License Agreement and then these links will be clickable there are different operating systems and different bit numbers x86 is the 32-bit version and x64 is the 64-bit version which one do you need I suppose that you know which operating system you are using I use currently Windows so the question for me is which version I should download and install how to figure out let's right-click on the computer and in the properties you will see the system type 32-bit operating system that means for me only the 32-bit version will be appropriate if you see here 64-bit operating system you might choose whichever you want but I suggest the 64 version so I download the bundle ok so download is finished let's click on the installation kit and let's start it and then the installation kit will configure itself and the program bill start the installation procedure is a simple one I suggest you to install the j-unit system it will be usable for class testing and it will ask us which directory we should install the jdk this default is appropriate so click on next and then it asks where to install the NetBeans IDE and the JDK is configured next and then after everything is set up we can click on the install button okay so after finish the NetBeans installer asked us if we would like to contribute to the NetBeans project by providing the anonymous usage data you can leave it like this or you can switch it off if you want to I switch it off so I think it is finished so the NetBeans IDE is on the desktop let's start it okay so after installing the NetBeans ID let's run the program you will see a window very much like this the start page is not necessary for us anymore so click on this check box and switch it off and close it and after that we will have a window split into two parts this left part will contain our projects one project is simply a program we can have a lot of programs next to each other so we will create now a new program that is we create a new project so click on the file new project and in the appearing dialog select the java and java application and click on next and here let's type the hello word since we will write our very first application an application that print out the hell over text this is a very common first program in every environment so make sure that this create new class will remain switch on and then click on finish ok as can see here in the projects window there will be a hello world application and this will contain everything that is necessary for compiling our project and the NetBeans will open up the source file and this will contain the code that we would like to run in the source code there are gray areas these are commands they are for us not for the computer they do not simply nothing they are just three marks for us to know what happened here and there is a package declaration here this package declaration shows which package this source code is in a package is simply a container for our source code files we might have hundreds or thousands class files source files so if we package up to smaller parts then we might have a better view and then I'd bins created as a class everything in Java will be contained in a class and there is a main function I will explain the class and the function later we have to know that our program has to be written into the main function so let's remove this comment here and let's type in system dot out dot println and in the quotation marks let's write hello world [Music] this is our very first program and let's run it let's click on this green triangle this will run our project it will compile and save automatically infinitely click it and after a while a new sub window will appear and this will be the output of our very first program so congratulations so the very first concept we have to get to know is the concept of variables imagine a wardrobe if you open up your wardrobe you find your valuable things in the different places the variables are very similar to these places you can put your important things to these places so simply a variable is a place to put your important thing what is an important thing for a program is the data and you can have different type of data you can have a number you can have a character you can have a text and you can put them into variables but as you don't put your shirt into the place of t-shirts and vice versa and you don't put your underwear in the place of t-shirts you won't put your text into the place of numbers and you don't put your numbers into the place of texts so in the case of variables we define another concept this is type the type represents what kind of data you want to store what kind of variables and types are there in Java if we consider all the types we can divide it into two parts one is primitive type very simple data and the classes which is a little bit more complex data let's examine the primitive types first if you take the primitive types there are the numbers so all the numbers can be here and there are characters in boolean so a character can mean a letter assign a space so everything which is one one character and the boolean can contain true or false numbers are not one single type but numbers are different so there are integral numbers just like 1 2 3 1000 and so on and there are real numbers one point 2 to point 3 and among the integral types there are many times and one is smaller can contain fewer numbers and there are bigger types so the smallest one is the bite it can contain only tiny numbers short is bigger in this bigger than the short and the long is the biggest and among the real types there are two the float float is the smaller type and the double is the bigger type most of the cases we will use the int and the double okay let's make an exercise it is called value replacing exercise the exercise is about replacing the value of two variables let's take this simple code inside the main function we create an int variable the name will be first and the type is int and the value is 7 so we would like to store the 7 in the variable first and the type is int and we create a second variable the name is second the type is int and the value is 19 and after some code this is a comment we will print out the result system.out.println and first will be a text and then we will print out the value of the first in this case this is 7 and then we will print out the second and the value of second so in the quotation mark this will be printed character by character and outside the rotation marks this will be the name of the variable and the value will be printed out okay and the exercise is about to replace the value of two variables without writing any more numbers and without changing the existing lines only write new parts here but before solving this one let's see how it works let's create a second project the name will be replace and make sure that the NetBeans will create the main class click on finish so first of all let's create a variable the type is int and the name will be first and we can assign a value to to the variable in this case 7 so type name and value and let's create a second variable type is int name is second and the value of y will be 19 okay what can we do with these variables first task is to print out to the screen so first we print out a string first and then we print out the value of the first outside the quotation mark and then we begin a further quotation mark this will be second equals and then outside the quotation mark we will print out the value of the second variable and the semicolon at the end okay let's see what it does so let's start and it will print out as we can see the thing inside the quotation mark will be printed out character by character and then the other first this black one will be replaced by the value and then the second character by character and then the second will be substituted with the value of the second make another exercise let's consider two glasses one with red wine and one with white wine and the task is to replace the content how to do that without mixing up the vines the idea is to have a third glass so you will pour the white wine to the third glass and the second glass will be empty so you can pour the red vine to the empty glass the second one and you can pour back the white wine to the first glass and now the task is solved how can we use this experience okay so let's create a third variable just like the third glass and we put the content of the second into the third one and then the second will be empty and we put the content of the first to the second variable and then the first is empty so we can put the value of the third into the first one remark for the emptiness of the variables I consider them to be empty just like the glasses but in reality they won't become empty when you assign their values to another variable after the assign both variable will contain exactly the same value [Music] let's see how it works and they are replaced so congratulations the next exercise will be the temperature exercise we will write a program that reads in an integer value which is a Celsius value and we will calculate and print it in Fahrenheit grade the formula is here in the bottom right corner what we don't know to solve this problem first we don't know how to read in a number from the user and the second one is how to make calculations okay let's see how it works okay so let's create the solution of the temperature exercise so first of all let's create a new project Java category Java project next and let's create temperature project make sure that it will create the main class so first of all we will print out something for the user that please give in the Celsius value and how to read in a number for reading in a number we have to create a tool this is written by the Java developers and this is called scanner Java dot util dot scanner I will name it to SC and we create a new java.util.scanner you don't have to understand this line this is a magic line we have to write this into the program if you want to read in a number and just one remark here you write here Java dot util device and we programmers are lazy so we don't want to write thinks twice so I would be happy if I could remove this Java dot util but in this case the Java compiler doesn't recognize the scanner this is because the previous Java dot util was the name of the package the scanner is in we have here hello verdant and temperature packages and the scanners package is the java tto and we can reach tools from any other packages in the java environment but you have to specify the whole package name with the class name but we are lazy so we don't want to to write that here how to solve the problem which appears here with an import line this import line is a new line here import Java dot util dot scanner and that means that every time I mention the scanner it will understand that this is the Java dot util dot scanner ok so we created a scanner with this magic line and this magic line will be used to read in a number so first of all we create a variable this will be Celsius and the value will be SC dot next double that means we read in a double value and we put this double value into the Celsius variable and after that we have to calculate the Fahrenheit value by using our formula so to store the result of the calculation we create the Fahrenheit variable and we use the formula 9/5 times cell zero plus 32 I will explain this point out later and after calculating the Fahrenheit system.out.println Fahrenheit is for height okay so let's run this program it asks as the Celsius value so for example 20 degrees Celsius is 68 in Fahrenheit so it works so let's go back to this point oh if we write only nine nine is an integer and 9.0 is a double so in this case we are using always double values sadducees double Fahrenheit is double so we add double values into the formula okay and one more remark what if we are using integers here okay let's see what happens if we are using integers and we were given the same value Celsius 20 okay let's rerun the project 20 so it's different it was 68 and now it's 52 why is there a difference between the two the explanation for that is that the calculation is different when you use doubles or integers especially the division so if there is a division then if you use doubles then the result is double so in this case 1.8 and if you use int then it will be round it down to 1 so if you calculate the result of this expression then 20 will be multiplied by 1 this is 20 and plus 32 is 52 and in the other case if you use double values so 9.0 and 5.0 then the result of this sub expression will be 1.8 and this will be multiplied by the Celsius value which will be 46 and you add 32 so this will be 68 okay so always remember if you use integers in the division then the result will be rounded down the next exercise will be in connection with the temperatures as well in this program we will read in a temperature value again in Celsius and we will print out if the water is boiling or not at the specified temperature so what we don't know is how to run a part of the program based on the temperature value okay so for solving the boiling exercise we will create a new project like before boiling exercise okay so first of all we have to read in a number which is a temperature value so it's very similar to the previous exercise so first of all we print out something for the user give in the temp picture and then we again create a scanner with this magic line and we again import the scanner so a new import line is appearing and in this case let's use integers I abbreviate the temperature stamp and we will read in an integer number this can raise a tool and it provides us a lot of possibilities not only nextdouble but we have next int next short next byte and we have functions for every times the dimension so in this case we will use the next in and after reading in the temperature we have to decide what to print out if the temperature exceeds 100 degrees Celsius then the water is boiling and if it's below 100 Celsius then it is not boiling so the key word for that is the if and inside the if we will write a condition the condition is something that has a true or false value that can be decided if it's true or false so in this case if the temperature exceeds the 100 exceeds means equals or greater than 100 and [Music] this condition goes to parentheses and after that in curly brackets the program statements the program commands that will be executed when the condition is true so in this case this is very simple we just print out that the water is boiling okay and what should we print out when the water is not boiling because in this case if you run the program run the project so in this case if the temperature exceeds the 100 degrees Celsius then this writes that the water is boiling and what if not let's rerun the program and type in 88 and it prints out nothing this is not always good sometimes it would be better if we print out something when the condition is not true so in this case we can use the else key bird and curly brackets and inside the curly brackets of the else you can write statement to print out something else the water is not boiling so let's rerun the project so when the temperature exceeds 100 then it prints out the water is boiling and if I rerun the project and it doesn't exceed the 100 then it prints out the water is not boiling our next exercise will be the boiling and freezing exercise this will be very similar to the previous exercise but in this case we will have three options not only boiling and not boiling but boiling freezing and normal state what we don't know since we have more than two options we have to join the ifs and create three options out of these two okay so for the boiling and freezing exercise we will copy the boiling exercise so right click on the project boiling and select the copy and here provide the name boiling and freezing this will be the name of the exercise and click on copy so a new project is created boiling and freezing with the same content so we have two boiling to Java one in the boiling project and one in the boiling and freezing project this is easy to mix up so it's better if we rename the boiling to Java this can be done by right click on the name of the Java file and refactor and rename or you can use the ctrl + R rename boiling and freezing and click on refactor so this will rename the file and this will rename the class itself but the content remain the same ok so back to the exercise it's very similar to the boiling exercise but when the water is not boiling so the water is boiling is done but if the water is not boiling then we have to divide it into two parts then it is freezing and when it is in normal state so instead of just printing water is not boiling we will split up this option by and if so if the temperature is below zero or it equals to zero then that means the water is freezing the water is freezing and the other option can be done by an S and in this option we are writing that the water is in normal state okay so we have an if with an else and in in the as branch there is an other if else so if we have a lot of branches then this can be a very huge structure so a little bit simplification in those cases when the earth contains only one instruction then you can remove these curly brackets and this if a statement as a whole is one instruction so let's remove these curly brackets these yellows and let's remove some some tabs so I will remove this tab and this tab this tab this and this so in this case the logic is the same but it's easier to read so we have a branch with temperature exceeds 100 we have a branch which less than or equal to zero and we have a branch that is everything else ok let's try it out so one branch is when the temperature exceeds 100 then the water is boiling we didn't touch it so it works the same let's rerun it if it's below zero then the water is freezing and if it's an enormous state for example 56 then the water is in normal state what did we do in the boiling and freezing exercise with these ifs and receives and asses let's imagine a sausage the sausage represents all the values from minus infinity to plus infinity and with the first if we cut one part of this area just like if we cut the first part of the sausage this was the first if and in the ass branch we handled the rest of the sausage the rest of the area and in the last part we cut it into two parts the if of the is the second part of the sausage and the last else will be the rest of the sausage and the sausage is eaten some I think in the boiling and freezing exercise that we have three separate branches each with an if and without an else so and if when the temperature exceeds 100 and another branch which is separated from the first if when the temperature is below zero or equal to zero and then a third branch which is executed when the temperature is between 0 and 100 but this expression is not understood by the Java because this is not a not a complete condition complete condition is this one and complete condition is this part it simply doesn't understand it understands if we write two separate but complete condition and join with something in this case we join with and so if the temperature is greater than zero and the temperature is below 100 then the water is in normal state between the exercise this end operator and this might be strange for you this end means that if we have two conditions the resulting condition is true then both of the conditions are true we have two more logic operators one is or that means if one of the conditions is true or both of the conditions are true then the resulting condition will be true and we have the negate which makes through out of the force and makes forth out of the true the next exercise is the fighting exercise which is the first part of the you are the hero program the goal of this exercise is to sum up everything we learnt in this video we will write a program in which you can fight with a monster so in the program first we read in the attributes of you and the monster and then we will play one round of the fight what will be the fighting rules there will be some attributes for you and the monster the Attic points determines how strong you are in attacking the other party defense points how good you are in defending yourself the damage how many damage you can cause to the other party and the life points how healthy you are if it goes to zero then you are dead one round of the fight first of all we choose movie OBD attacker this is a simple coin toss if heads one of the party attacks the other if tails then the other party attacks and then we roll two dice and add to the attackers attack points and we compare it with its enemies defense points if the attackers result is bigger than the defender then the attack is successful and therefore the enemy's life points will be decreased by the damage otherwise the attack is not successful so what we don't know is how to generate random numbers if we know how to generate random numbers then we are ready to fight ok let's create the solution of the fighting exercise first of all we create a Java project java and java application and then the name will be fighting in the first part of the program with your read in all the attributes of you and the monster because we are reading numbers and we create a scanner this is the tool for reading in numbers and as always we import the scanner then we read in the attack points of the monster the variable name will be monster attack and be read in from the user then reading the defense points the first part of the monster monster defense will be the variable name reading from the user then the damage of the monster this will be monster damage and finally the life points of the monster we are be read from the user and then your attributes we are be read in after reading all of the attributes we start the fighting round the first thing that we have to decide is who will be the attacker for this we will do a coin toss in the programs for that we will use a random number generator and this random number generator will generate as a number in this case if we would have to decide which party starts we need not a number but a boolean value so if true is generated than one of the party will attack if force is generated then the other party attacks so let's create the random number generator this is the random number generator and this is very similar to the scanner this is a tool we have to create it with new and we have to import the Java dot util dot random and with this random number generator we create a boolean value this boolean value will determine which party will attack we will use the next boolean we create the next boolean value randomly and after that if the attacker is true then that means that you will attack you attack and what you need is to roll two dice therefore we generate another random value in this case a random number so generator the next int if you write here a six that means this function will return a random value between 0 and 5 inclusively 6 cannot be generated so if we have this number from 0 to 5 then we add 1 to this 0 to 5 number and then we get 1 to 6 this is a normal die so I add 1 to the value so this is one die and we need two dice so we generate another number from from 0 to 5 and we add one more so this is two dice and according to rules the attack value will be calculated by by your attack points plus the two dice but before we go on let's print the values that was rolled the role values and your attack value and then we decide if your attack was successful or not if the attack value is greater than the monsters defense that means your attack was successful and therefore you damage the monster so the monsters life will be decreased by your damage so we print out the remaining life of the monster if the condition is not true then your attack was not successful let's print it out unfortunately okay so if you were the attacker then this is your attack otherwise the monster attacks let's print it out okay and so let's run the program and let's type in some values the attack points of the monster will be five defense points ten damage of the monster three life points of the monster will be forty your attack points then your defense points twenty five you are damaged six and your life points forty and after that you will attacked the rolled values was six so therefore your attack value was sixteen which is greater than the defense points of the monster therefore the attack was successful and therefore you damaged the monster and the monsters remaining Life Points was 34 you successfully hit the monster but it is still alive to kill it we still need to learn a lot so let's see what's in the next video one of them is to choose one from many the sister switch statement and for repeating things just like fighting rounds we learn the while the two vile and the for loop and we will learn two things to control the loops break and continue and finally in the next video we will learn how to put one loop in the other and we will continue developing our game you
Info
Channel: Duckademy IT courses
Views: 888,253
Rating: 4.8525281 out of 5
Keywords: tutorial, java programming, java basics, java for beginners, Java (Programming Language), java tutorial, java programming tutorial, install netbeans, exercises, introduction to java, java tutorial for beginners, random number generator, examples, complete beginners, absolute beginners, step by step, getting started with Java, easy to follow, what is java, java programming for beginners, java programming tutorial for beginners, 2018, java, NetBeans, netbeans tutorial, java netbeans
Id: JPOzWljLYuU
Channel Id: undefined
Length: 62min 34sec (3754 seconds)
Published: Mon Dec 14 2015
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.