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


donezo. Enhanced for loop Java makes for



Download 3,91 Mb.
Pdf ko'rish
bet39/70
Sana02.04.2022
Hajmi3,91 Mb.
#524999
1   ...   35   36   37   38   39   40   41   42   ...   70
Bog'liq
Java for Fucking Idiots

donezo.
Enhanced for loop
Java makes for loops even easier. In the simple case where you’re simply
going through some sort of data collection, you can do this:
Meme[] memes;
for
(Meme currentMeme : memes) {
//do shit with the meme
}
You don’t even need to create and initialize an index variable.
No need to get the item at that position in the array.
No need to increase the index at the end of the loop.
None of that shit.
It’s the perfect way to loop through some items in a list. Always use one of
these unless you have a reason not to.
As another example, you could replace our earlier example like so:


char
[] myArray = {
'A'
,
'B'
,
'C'
,
'D'
};
for
(
int
i =
0
; i < myArray.
length
; i++) {
System.
out
.println(myArray[i]);
}
char
[] myArray = {
'A'
,
'B'
,
'C'
,
'D'
};
for
(
char
character : myArray) {
System.
out
.println(character);
}


CHAPTER 9:
INSTANTIATION
 
“Ow! What the heck was that!?
[Instantiation]! That was part one of your ceremony.
Ceremony for what?
We’re going to put you to rest!” – Spongebob Squarepants
WE’RE BACK BABY! OBJECTS ARE BACK ON THE MENU!!!
IT’S TIME TO MAKE AN OBJECT OUT OF A CLASS. READY??
Creating an object
Book myBook = new Book();
“I DID IT! I DID IT, DAD! I MADE AN OBJECT!” - you
Alright, you made an object. Yes, you did. But slow down my child. There’s
a ton of complexity in that simple line of code. Let’s do it bit by it.
I’ll label each part of that line.
Book
1
 myBook
2
 = new
3
 Book()
4
 ;
Feel free to flex your brain and guess what each word is doing before
reading on. Now…
1. Book 
1
This first part says our variable is going to be a Book. Just like we’d make
an int, or a double, or a char, we’re saying that we’re making a variable of a


specific type. In this case, it’s a Book.
2. myBook
This bit is saying the name of our variable is myBook. We can name it
whatever we want. We could have called it “foo,” or “bar,” but I absolutely
loathe variables with those stupid fucking names.
“So the name of the object we just made is myBook?”
Ehhhhhhhhh…. for now, yes, you can say this is the name of our object.
Some sticklers would say “ackshually that’s an object reference variable,
not the object itself, let me explain why you’re wrong-”
But for now, you’re fine to say the object is called 
myBook
.
3. new
This is the absolute 
magical
keyword in that line of code. You are saying I

Download 3,91 Mb.

Do'stlaringiz bilan baham:
1   ...   35   36   37   38   39   40   41   42   ...   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