Var and Val

Concept Courses 
A free video tutorial from Concept Courses 
Development | Business | Design
4.4 instructor rating • 21 courses • 206,738 students

Lecture description

In this Kotlin Course lecture, you will learn how to do basic math functions with Kotlin as well as the difference between Val and Var.

Learn more from the full course

The Total Kotlin Course : Learn Kotlin Today

Develop Real World Applications with Kotlin, the Number One Programming Language for Modern Multi-platform Applications

03:39:25 of on-demand video • Updated August 2017

  • At the end of this course you will have a strong understanding on using Kotlin alongside Java.
  • After completion, you should have a good decision on if Kotlin is right for you.
English [Auto] Are going to do some very late math. So in the print line we're going to print outs of math so two plus two very easy. We're going to get four or we can also do things like multiplication or we can do two times and we can do that time is with shifts and 8 Evette again reach 6. It can also combine things with parentheses so we can do two plus two and see and we'll get two plus two equals four times three which is 12. Now we get 12 and also do things like multiplication and do 12 divided by six. We'll get to it. We can also do things like modulus Verno modulus is it's Apprentice's we'll do a five. So we'll get the answer from this then I'll explain in a little a little more of a way of an example another time. So we have to make good thinking too. Why is that. How wicked that too is we do too. I'm told by by five but also a way that I've got I do it is how many times is five go into 12 and that's two secret 10 and then you take the number 12 and you minus that that's how you get to. Now what if we wanted to combine things where if you don't want to have this in our print line. What if we have things like times two plus nine Ennius 12 times where it's doing. It gets to a big giant Lamhe numbers and asserts gaing turns a lot sets. What variables come into play. Variables are very much like boxes. Hold things and make a variable. We can have something like Val if we can have question one is well of modulus five for a that's to try and make two so you will do the print line first and then we'll verify with the variable we've got four from this. So again Question 1. This is a balance. So this is a variable that's pretty much a box set contains this. So if I put vesture one here these parentheses is pretty much the same thing as 12 edulis 5 and we'll get the same results or Ryan or and then we can have things like a question equals 10 items 5 for example if the so you can see that in these bowels which are variables our boxes are pretty much boxes that contain a value. What happens when we want to change those values so we can do one which is 12 modules 5 which equals two and we could do question option one last two right. Now equal legal for what this is doing this is doing and one equals my question and one is our 12 modeless 5 which is 5 and they were just putting two plus two there were changing. Question 1 What equals to. The problem is a now is a value it cannot be changed vowels cannot be changed at all it cannot be added and they cannot be changed but there is something that can be changed. How is a bar a variable. Or we can see now we don't have that red squiggly line. See where we put back to Vau. We hover over this Balogh cannot be re-assign And this idea this editor is very smart it knows when you have a value and you're trying to change it. So whenever you have a problem where it has a read squealy line on and press the red label and you see make very mutable but mutable means is that you can change it. So of R is mutable so far equals shootable Bow Bells. Inable so mutable equals. It can change immutable means it cannot change. So when you have a math problem and you. You specifically wanted to change so you want to add things to what you want to change it always put over a VAR But if you have something like your name. You don't want that change used. You don't ever want that change you don't want to change it to Ryan or or some other name. You don't want the ability to change your name to Dilling For example you want to as Ted and you want to keep it as Ted and not change it. That's why we have the Val.