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



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

boolean
isPositive(
int
number) {
if
(number >
0
) {
return true
;
}
}
What if the number is less than or equal to 0? You need to explicitly give
your method something to return in all scenarios! Java isn’t smart enough to
infer that anything else would be false , for example.
You’d have to do something like this:
boolean
isPositive(
int
number) {
if
(number >
0
) {
return true
;
}
else
{
return false
;
}
}
Or, you could provide a “catch-all” return value at the bottom of your
method, which in this example acts the same way:
boolean
isPositive(
int
number) {
if
(number >
0
) {
return true
;
}
return false
;
}
Static methods


Typically, you call methods on objects . The idea is that the methods will
interact with the properties on that object; change the value, retrieve the
value, initialize a value, all that shit.
But you can create methods that don’t need to be called on an object. Just
the class. Those methods are static .
Here’s a few examples
class
StringHelpers {
public static boolean
startsWithA(String str) {
return
str.charAt(
0
) ==
'A'
;
}
public static boolean
isNullOrEmpty(String str) {
return
str ==
null
|| str.isEmpty();
}
}
We don’t need to create a 
new StringHelpers()
object, then use a dot “.” to
call the method on that object. We can straight up just use the StringHelpers
class itself.
String myString =

Download 3,91 Mb.

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