YouSub
Untitled

en English

Untitled English subtitles

0 downloads · 34 lines · added Dec 15, 2015

Report a problem
What's wrong?
Advertisement

English transcript

Okay, so before I start talking about these variable declarations, the first
thing I want to point out is that none of these are particularly good name for
a variable.
And none of them are particularly good names, because it's easy to confuse
names like number, int, and integer with the data type that comes before.
That said, two of these declarations won't even work.
Let's look at the first one.
So, we have here the word integer,
which is in the position where the variable type should be.
Now, in this lesson we've taught you about two types, string and int.
So the computer will recognize int as an I N T lowercase.
But it's not going to recognize the word integer.
Your types must be exactly spelled and capitalized as we showed you them.
So this one is incorrect.
Okay, so looking at this next one the word int is correct here,
since we just talked about that.
This is a valid data type, but
the problem here is that you can't name a variable the same name as a data type.
There's certain special words in Java that have a meaning for the computer,
beyond just what they say such as int.
These special words are known as keywords, and
in Android Studio they're colored blue.
Now you can't name your variables the same as any of these keywords.
Okay, so this one also has an issue, okay so this third one,
it looks like our data type is declared correctly.
Now technically this would work,
you've gotta type here that the computer will recognize, and you've got a name,
that is something that fits all the variable rules.
That said, the name integer is a pretty vague name.
And it could easily confuse someone else if they're just reading your code.
So because it's technically not wrong, I'm not going to mark it.
But you should consider a better variable name,
such as numberForCalculation.
Which is a little bit more specific as to what its use is.

Need subtitles from another video?