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



Download 3,91 Mb.
Pdf ko'rish
bet49/70
Sana02.04.2022
Hajmi3,91 Mb.
#524999
1   ...   45   46   47   48   49   50   51   52   ...   70
Bog'liq
Java for Fucking Idiots

"Alpha"
;
if
(StringHelpers.
startsWithA
(myString)) {
System.
out
.println(
"It starts with A."
);
}
In general, you don’t want to make a method static unless it’s some simple
helper methods like these. You’re in an object-oriented language, it’s a good
idea to use objects and their methods, not static methods on classes.
Note: some people would call these static methods “functions .” The
difference between methods and functions is mostly a pissing match
between programmers. Typically, I’m pretty sure methods are just functions
that are attached to objects. And since Java is highly object-oriented, we
typically call them methods.
Parameters and Arguments


Methods can have data passed to them when they’re called. We’ve already
seen this a few times, but I should probably cover this explicitly, too. Call it
a moral obligation…
class
Airplane {
void
fly() {
}
}
That method 
fly
has 0 parameters . There’s nothing inside the parentheses ()
of this method definition. You could simply call it like this:
Airplane airplane =
new
Airplane();
airplane.fly();
Let’s add a parameter so we can specify what altitude we fly at.
void
fly(
int
altitude) {
}
Now the method has 1 parameter: 
altitude
. When you call this method, you
can “pass” the altitude to the method, and the method can use it to fly to the
desired altitude.
airplane.fly(
15000
);
Make sense?? Remember when we could pass things to a constructor?
Same thing with methods!
Okay…so that’s a parameter. Something we can put in our method
definition so that we get data passed to it when it’s called.
But what’s an argument ?
Well, it’s the other side of the coin.
When you’re typing out your method and specify what can be passed to it,
you are specifying a method’s parameters . 


When you actually call the method and pass something to it, you pass an

Download 3,91 Mb.

Do'stlaringiz bilan baham:
1   ...   45   46   47   48   49   50   51   52   ...   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