Java for Fucking Idiots: Learn the Basics of Java Programming Without any experience!



Download 3,91 Mb.
Pdf ko'rish
bet11/70
Sana02.04.2022
Hajmi3,91 Mb.
#524999
1   ...   7   8   9   10   11   12   13   14   ...   70
Bog'liq
Java for Fucking Idiots

int
myFavoriteNumber =
7
;
Later if we use the 
myFavoriteNumber
variable it would be equal to 7.
So, variables are human-readable things that are given values. The short-
term memory of your computer says “OK, I’ll store that value for you. Use
that variable name again when you want to know that value, or change it.”
A person types “Please remove me from this distribution list” into
Microsoft Outlook. The program would represent that data as a variable.
Another person opens the Calculator on their computer and presses the
number 3. That’s another variable. A different kind of variable, but one
nonetheless.
Your Veterinarian’s computer system checks if you have used them before;
this yes/no, or true/false value can be represented by a variable, too.


Variables are eeeeeeverywhere . Create them, store them for later, change
them, send them to your friends, get attached to them, cry over them.
They’re wonderful.
Why do we need variables?
We cannot know the future, and neither can our programs (yet). Our code
might need to respond to the user’s entered account name, the time of day,
the amount of items that are in inventory, the information scanned in a
barcode, the breed of dog in a cute picture, the GPS coordinates of your
phone, you name it.
Things that we do not know now , but our program can find out while
running (“at runtime”), are good candidates for variables.
OK, now let’s make some.
Making variables
You can declare a variable, basically telling the compiler “hey, this is
something I’m going to use later, OK?” like this:
int
numberOfStarsToAwardThisBook;
Variable declared. Hooray! However, it doesn’t have a value.
We can fix this later with a new line of code that initializes the value:
numberOfStarsToAwardThisBook =
5
;
Alternatively, we could have just done it from the start (declaring and
initializing):
int
numberOfStarsToAwardThisBook =
5
;
Naturally, Amazon does not have code that makes every review 5 stars built
into their software. We would likely show the user a screen to make a
selection, then set this variable equal to the # of stars they selected
afterwards.


Data types
What was the “int” part for?
int is short for integer. Integers are whole numbers. This is honestly
elementary math but as I’ve said before… minimal assumptions.
These are whole numbers: 4, 8, 15, 23, 42, -15, -214
These are not whole numbers: ½, ¾, 0.86, -84.97, 0.01
You can put the word 
int
before a variable to specify that it is a whole
number. That’s the type of variable it is.
Java is absolutely paranoid about these “types” and if you don’t specify
one, the compiler is going to be very upset with you. In fact, every variable
in Java must have a declared type.
Here are some the different kinds of variables that you can make.
Note: All data types that have to do with numbers support positive or
negative values.

Download 3,91 Mb.

Do'stlaringiz bilan baham:
1   ...   7   8   9   10   11   12   13   14   ...   70




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish