Hello, in this video we are going to take a look at constant variables. A constant variable is very important. It is used in many programming languages. And you might even be able to guess what it is it basically means your variable remains a constant value. As a result, you need to actually assign the value right at the start. So you can just so if I just create an unknown flow, and I call this let's say I call it pi, for example, equals 3.149.
That's enough precision, like so. And maybe I do System dot out dot print ln, obviously using any capacity that you would like to add in here, maybe I do. Okay, so I'll save that run it, we'll get into this number printed out. Obviously, you know, minus d f, because f just indicates the flow. Okay, that's cool. But pi is a constant, you know, in mathematics in the real world, it is an actually a constant.
It's the circumference of any circle divided by the diameter of the circle, you will always get pi. Pi has an infinite number of decimals, but we're not really going to go into that. But it's a constant. And what that means is stuff like this, you don't want it to change, whatever that you know, a real world constant like pie, or something that you made up for your particular application. And something like this might occur, you might accidentally, you know, especially when there's multiple developers on the program, you might have 34 to look at that. Is system dot out.
Dot print ln, now, do pi if I run it, it's Change it to four. But we can alleviate that by putting the keyword final at the start. And in some of the languages if the actual keyword is constant, so in Java, it is quite new. And that means is a constant. So this line is find if you find this long in here, so we know what the error is, or we know why is throwing an error. Let's look at the exact error.
So he's saying the final local variable pi cannot be assigned, it must be blank and not using a compound assignment. So what it means is, is is constant value. So you could do that and that removes it, that's fine, but we want to constant. So if you were to just get rid of this, run it and there we go, we have a constant value that cannot be changed a nova caveat. If I were to do this, it would give an error and the reason it gives an error because it hasn't been initialized. So you need to know initialize it as well at the start.
So that's it A constant variable, immensely useful, and thanks for watching. If you have any questions, feel free to reach out. We'll also have the GitHub link which all with all the source code from every video in this series, and I look forward to seeing you in the next awesome tutorial.