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



Download 3,91 Mb.
Pdf ko'rish
bet52/70
Sana02.04.2022
Hajmi3,91 Mb.
#524999
1   ...   48   49   50   51   52   53   54   55   ...   70
Bog'liq
Java for Fucking Idiots

char
firstLetter =
'A'
;


Just use a String.
String firstLetter =
"A"
;
Why bother using a primitive when you can get the real deal? Needless to
say, if you need a string of characters, you’d use a String, too.
String myName =
"Steve"
;
Did…did you just say a String of characters?
Yep, that’s what a String is, at least under the hood. Somewhere inside how
a String is made in Java there exists a char[]. In fact I just looked up the
source code for String. Lookie!
public final class
String

{
//The value is used for character storage.

private final char
value
[];

}
Picture a bunch of characters lined up, with a piece of string tying them
together. Not all that firmly; you could snip the string if you wanted to. But
they’re a unit!
Yay, Strings!
Numbers
And numbers? Just because a value looks numerical doesn’t mean it should
be an integer. Don’t get me wrong, lots of times you do need numbers to be
ints
or 
doubles
(fuck floats). But not always!
For example, phone numbers…
long
jennysNumber =
5558675309L
;
You ain’t gonna be adding phone numbers together! Make it a string!
String jennysNumber =
"5558675309"
;


Making a String
“You just put some stuff inside two double quotes, I get it.”
Well…I should tell you that theoretically you could do this. Don’t.
String jennysNumber =
new
String(
"5558675309"
);
Yep, Strings are objects. They have constructors.
This constructor is absolutely useless, though. Seriously, more useless than
nipples on a man.
Java lets us use shorthand to simply put the value inside double quotes and
lets that be the end of it.
There are other ways you might need to create a String, though. For
example, maybe you have an 
int
but just absolutely need it to be a String.
int
foundThisInADatabase =
34897320
;
String strRepresentation = String.
valueOf
(foundThisInADatabase);
You can use the static 
String.valueOf
method to convert the 
int
to a String.
Same goes for pretty much any other type of variable. Neato!!
String Comparisons
Remember the comparison operator? It’s two equals signs. Here, I’ll remind
you.

Download 3,91 Mb.

Do'stlaringiz bilan baham:
1   ...   48   49   50   51   52   53   54   55   ...   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