Constant Variables

3 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€83.63
List Price:  €117.08
You save:  €33.45
£72.43
List Price:  £101.41
You save:  £28.97
CA$135.33
List Price:  CA$189.47
You save:  CA$54.14
A$141.70
List Price:  A$198.39
You save:  A$56.68
S$126.40
List Price:  S$176.96
You save:  S$50.56
HK$780.47
List Price:  HK$1,092.70
You save:  HK$312.22
CHF 76.77
List Price:  CHF 107.48
You save:  CHF 30.71
NOK kr957.80
List Price:  NOK kr1,340.96
You save:  NOK kr383.15
DKK kr624.45
List Price:  DKK kr874.26
You save:  DKK kr249.80
NZ$164.82
List Price:  NZ$230.76
You save:  NZ$65.93
د.إ367.21
List Price:  د.إ514.11
You save:  د.إ146.90
৳12,225.55
List Price:  ৳17,116.26
You save:  ৳4,890.71
₹9,196.14
List Price:  ₹12,874.97
You save:  ₹3,678.82
RM392.71
List Price:  RM549.81
You save:  RM157.10
₦138,711.12
List Price:  ₦194,201.12
You save:  ₦55,490
₨27,987.63
List Price:  ₨39,183.81
You save:  ₨11,196.17
฿3,117.78
List Price:  ฿4,365.02
You save:  ฿1,247.24
₺4,342.05
List Price:  ₺6,079.05
You save:  ₺1,736.99
B$520.08
List Price:  B$728.14
You save:  B$208.05
R1,575.26
List Price:  R2,205.43
You save:  R630.17
Лв163.56
List Price:  Лв228.99
You save:  Лв65.43
₩143,205.96
List Price:  ₩200,494.07
You save:  ₩57,288.11
₪308.31
List Price:  ₪431.65
You save:  ₪123.33
₱5,899.68
List Price:  ₱8,259.80
You save:  ₱2,360.11
¥15,330.04
List Price:  ¥21,462.67
You save:  ¥6,132.63
MX$1,714.99
List Price:  MX$2,401.05
You save:  MX$686.06
QR363.75
List Price:  QR509.27
You save:  QR145.51
P1,309.07
List Price:  P1,832.75
You save:  P523.68
KSh12,893.71
List Price:  KSh18,051.71
You save:  KSh5,158
E£4,688.30
List Price:  E£6,563.81
You save:  E£1,875.51
ብር15,556.62
List Price:  ብር21,779.90
You save:  ብር6,223.27
Kz91,204.17
List Price:  Kz127,689.49
You save:  Kz36,485.32
CLP$86,573.05
List Price:  CLP$121,205.73
You save:  CLP$34,632.68
CN¥694.44
List Price:  CN¥972.24
You save:  CN¥277.80
RD$6,294.69
List Price:  RD$8,812.82
You save:  RD$2,518.13
DA12,909.30
List Price:  DA18,073.54
You save:  DA5,164.23
FJ$219.03
List Price:  FJ$306.66
You save:  FJ$87.62
Q767.55
List Price:  Q1,074.61
You save:  Q307.05
GY$20,930.98
List Price:  GY$29,304.21
You save:  GY$8,373.23
ISK kr12,110.78
List Price:  ISK kr16,955.58
You save:  ISK kr4,844.80
DH904.57
List Price:  DH1,266.43
You save:  DH361.86
L1,681.92
List Price:  L2,354.76
You save:  L672.83
ден5,150.17
List Price:  ден7,210.45
You save:  ден2,060.27
MOP$804.02
List Price:  MOP$1,125.66
You save:  MOP$321.64
N$1,590.78
List Price:  N$2,227.16
You save:  N$636.37
C$3,681.50
List Price:  C$5,154.25
You save:  C$1,472.74
रु14,703.41
List Price:  रु20,585.37
You save:  रु5,881.95
S/334.75
List Price:  S/468.66
You save:  S/133.91
K428.25
List Price:  K599.57
You save:  K171.31
SAR375.02
List Price:  SAR525.04
You save:  SAR150.02
ZK1,988.36
List Price:  ZK2,783.78
You save:  ZK795.42
L426.18
List Price:  L596.67
You save:  L170.49
Kč2,032.47
List Price:  Kč2,845.54
You save:  Kč813.07
Ft31,912.53
List Price:  Ft44,678.81
You save:  Ft12,766.28
SEK kr885.01
List Price:  SEK kr1,239.05
You save:  SEK kr354.04
ARS$144,435.55
List Price:  ARS$202,215.55
You save:  ARS$57,780
Bs691.31
List Price:  Bs967.87
You save:  Bs276.55
COP$365,835.88
List Price:  COP$512,184.87
You save:  COP$146,348.99
₡49,655.42
List Price:  ₡69,519.58
You save:  ₡19,864.15
L2,640.21
List Price:  L3,696.41
You save:  L1,056.19
₲671,837.20
List Price:  ₲940,598.96
You save:  ₲268,761.75
$U3,743.56
List Price:  $U5,241.13
You save:  $U1,497.57
zł351.82
List Price:  zł492.57
You save:  zł140.74
Already have an account? Log In

Transcript

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.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.