« first day (2407 days earlier)      last day (2517 days later) » 

12:47 AM
morn
 
user7627726
@Tavo In california, Good afternoon, it's 5:48
 
for real? again?
'Apr 21 at 8:27, by kiheru
I thought it had been established that it's always morning at the java channel'
 
user7627726
Room dedicated to the Java programming language, yummy food, and cats. And no, Android is NOT Java (does not use the Java VM, runtime environment and base SDKs differ, etc). And no, Javascript is NOT Java either Nothing about always morning in here
 
user7627726
It's not always morning, but it is always friday, hence the its-always-friday tag in the room description
 
user7627726
@Tavo Your here a lot aren't you. Every time I'm here, you are too, even though were in different time zones XD :D :P
 
12:54 AM
like most people, I rarely switch off my computer
 
1:34 AM
gosh, I'm already in a Friday mood. I really don't feel like working today :/
 
 
1 hour later…
2:44 AM
o/
 
\o
 
off to bed @Michael?
 
Oak won't spam "Type /help to see my command" messages anymore.
And yes. xD
 
lol. Niters!
 
Night.
 
 
1 hour later…
4:00 AM
"A successful man is one who can lay a firm foundation with the bricks that others throw at him." -Sidney Greenberg (source)
 
 
1 hour later…
5:28 AM
morning
 
user7627726
\cat
 
user7627726
/cat
 
awesome cats! Hello Java
 
5:46 AM
@Julo0sS hi
 
6:28 AM
@Tavo Bad Tavo!
 
6:40 AM
Hey hi there @ItachiUchiha :P finally we are together at the same time in this room
 
@Julo0sS o/
 
had a closer look on the screenSwitcher thing, and didnt find anything relevant concerning this strange debian/windows issue... :/
 
Now, I have Ubuntu back on my device so I can have a look at it later
 
only tested on my debian8 so idk if it will do the same. Btw, i tried directly from netbeans, i didnt try to use the java file generated by windows netbeans directly on debian without going through netbeans
 
6:56 AM
It doesn't matter as the source will create the same class files irrespective of the underlying OS.
Apart from the OS issue do you have anything design wise to discuss?
 
no, the current sample should do the job, so thats fine :)
 
7:21 AM
@ItachiUchiha in the end I got bored and started working :P
 
user7627726
As always, hello Tavo
 
user7627726
/cat
 
user7627726
/help
 
Commands=====================
/8ball     Simulates a magic 8-ball.
/about     Displays information about this bot.
/afk       Allows users to mark themselves as "away".
/cat       Displays a random cat picture. :3
/define    Displays word definitions from the dictionary.
/help      Displays this help message.
/http      Displays information about HTTP status codes and methods.
/javadoc   Displays class documentation from the Javadocs.
/learn     Teaches the bot a new command.
/react     Displays a reaction gif.
 
user7627726
7:31 AM
/afk
 
@theProgrammer101 Cya later
 
user7627726
/roll
 
@theProgrammer101 Welcome back!
@theProgrammer101 2
 
user7627726
/summon
 
@theProgrammer101 Please specify the room ID.
 
user7627726
7:32 AM
/shrug
 
¯\_(ツ)_/¯
 
user7627726
/HAMMERTIME
 
hammertime!
 
user7627726
/c#
 
That didn't make much sense. Did you mean Java?
 
user7627726
7:33 AM
/wiki
 
@theProgrammer101 Please specify the term you'd like to display.
 
user7627726
wave
 
user7627726
/bye
 
user7627726
/wave
 
7:34 AM
\o
 
o/
 
8:10 AM
o/
 
\o
 
8:24 AM
Bonjour All
 
aye :D
 
:D
 
9:01 AM
He's there... :P
 
\o
 
9:19 AM
keep learning @CrashBandicoot ? :)
 
@Julo0sS Yep :)
 
Makes Sense?
 
I've got a question
Yep xD
Kind of
 
shoot
 
Can only iterate over an array or an instance of java.lang.Iterable
line 42
 
9:24 AM
list & index are empty, right?
 
yes
Well, Book is not empty
 
anything that implements Iterable
Iterable is an interface. Hence, you can't have an instance of it
 
How do I fix that?
 
fix what?
 
I'm asked to use that exact for loop
 
9:27 AM
you are going to have to be a bit more specific than that
what is it that you need to accomplish? What is not working as you expect it to work?
 
"Add some code that will iterate around the index collection and print the details of each book"
 
aha
I understand
your problem is that a Map does not implement Iterable
 
do you know what a Map is?
 
something to find a treasure chest!
 
9:31 AM
@Julo0sS correct but useless in the context
 
An interface with a Key & Value pair
 
@CrashBandicoot nice googling there :)
 
:?
I don't recall#
:)
 
so if a Map is a collection of key-value pairs
there might be something Iterable there
I'll give you a hint. Every key-value pair is an Entry
 
Hmm okay
I don't know the answer
 
9:36 AM
then dig a bit deeper in the Map interface: docs.oracle.com/javase/8/docs/api/java/util/Map.html
alternatively, if you can't be really bothered to learn, just google it. I'm sure it's been answered a few times
 
@Tavo NOooooo. Don't introduce someone to Google so soon.
 
@ItachiUchiha he already used it to find out what a Map is...
and I'll be gone in 20 mins, so...
 
Fair enough!
Go and enjoy your weekend while we die here working our asses off :'(
 
Okay, so there can't be any duplicates of Keys
and One Key links to One Value
 
all of that is true, and it's good you are learning
@ItachiUchiha you are not if you are meddling here :P
 
9:39 AM
Good catch ;)
 
But what can be Iterable in a HashMap?
 
@CrashBandicoot I gave you a hint
 
>>>Entry<<<
 
Every Key-Value pair is an Entry
 
there are several ways of achieving that @CrashBandicoot
 
9:40 AM
^ the hint
 
@ItachiUchiha lol
 
you can do this the old fashioned way with an EntrySet or the cool way with streams api :D
 
@motaa I think that's too complex for me xD
 
these one liners aren't complex
but you should know how they work
@CrashBandicoot your code about the arraylist is complete
 
he needs to know how a Map works first
 
9:43 AM
@Tavo I totally agree
 
introducing streams here is too much
 
what you are missing though is your ArrayList is empty
 
I get that
So, basically, to get a Value, you have to use the Key
I'm guessing you have to iterate over the Keys
In order to get the Values
 
you could
and it's a way of doing it, for sure
it will work. Go and implement it
we can discuss other ways once you've done that
 
so would it be: for(String st : index)
{
sysout(st.toString());
}
 
9:45 AM
what's st?
 
name of String
 
never mind, I'm blind
no, it's not like that
 
when you do 'for(String s:index)' you are saying 'for every element in index, which should be a String...'
 
Would I use an enhanced for loop?
 
9:47 AM
@CrashBandicoot at line 33 you can write list = Arrays.toList( myBooks );
 
but the elements in index are not Strings
 
so your list of books will be filled with the Books your previously created
 
@CrashBandicoot you can
 
What are they then?
is it Object?
 
everything is an Object, but it's more specific than that
I gave you a hint
 
9:51 AM
I'm not sure
Would it be Book?
 
MAP
\Entry1 -> <"Harry Potter", Book1>
\Entry2 -> <"StormBreaker", Book2>
\Entry3 -> <"Hunger Games", Book3>
\...
this is what it looks like inside (roughly)
 
So you would iterate over the title?
 
that is the option you said before, iterating over the keys
and that would work
now you need to figure out how to find something that will give you something to iterate over the keys
but it's not enough that you read the text. You need to understand it and the methods listed below
Map is a complex structure. But it's very useful. You'll find people use it a lot
 
That's confusing: Figuring out how to find something that will give me something to iterate over the keys.
 
ok. Your problem is that you need to iterate over the map. But you can't, because Map does not implement Iterable. Right?
 
9:57 AM
Yes
 
you said you could do it iterating over the keys, right?
 
so you need something that lets you iterate over the keys, right?
 
ok. The answer is in the link I sent you above
but I'll give you one more hint
 
9:59 AM
Okay
 
which interfaces that extend Collection also extend Iterable?
 
I don't know
 
there's your problem
 
What's the answer?
 
btw, Collection extends Iterable. My mistake
I'll give you one. You can figure out the one you need from there: List
 
10:01 AM
Okay
 
anyway, it's time to go home
good luck!
 
Thanks!
It's gonna be tough
Bye
Yeah, I'm gonna need some help :(
 
Map doesn't extend Collection
 
But List, Set etc does
So, they are inherently Iterable
 
10:15 AM
Yes
So, how do I iterate around the index collection and print the details of each book...
Basically, I can't do that with a HashMap?
So I have to use a list
 
No
The name of the Book is the key of the Map, right?
 
Yes
the 'title'
 
yup
Map gives you methods to fetch the set of all the keys.
 
The reason it return a Set and not a List is because they are unique.
/javadoc Map#keyset
 
10:17 AM
@ItachiUchiha Set keySet()‌​: Returns a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping ...
from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.
 
When you execute this method it will return a set with all the titles of the book.
Set<String> titles = mapOfBooks.keySet();
for (String tile : titles) {
   //do something
}
 
Makes Sense
But I've been asked to create a HashMap
 
HashMap is just an implementation of the Map interface
 
TreeMap, EnumMap are other to name a few
 
10:20 AM
Yes
 
So, all the methods present in Map interface will be available in all its implementations.
 
Understood
So, is Set an implementation of the Map interface?
 
Nope
 
/shrug
 
10:22 AM
¯\_(ツ)_/¯
 
Ok, so how would the HashMap code look?
Because it says:
First, create a HashMap called index that uses the title of each book as a key and the object as the value.
 
@CrashBandicoot pls look closer at the javadocs
 
I've read through it, and it makes sense in places
 
especially these lines:

All Known Subinterfaces:
Bindings, ConcurrentMap<K,V>, ConcurrentNavigableMap<K,V>, LogicalMessageContext, MessageContext, NavigableMap<K,V>, SOAPMessageContext, SortedMap<K,V>

All Known Implementing Classes:
AbstractMap, Attributes, AuthProvider, ConcurrentHashMap, ConcurrentSkipListMap, EnumMap, HashMap, Hashtable, IdentityHashMap, LinkedHashMap, PrinterStateReasons, Properties, Provider, RenderingHints, SimpleBindings, TabularDataSupport, TreeMap, UIDefaults, WeakHashMap
 
I understand these are the implementations of the Map interface
But I still don't know what to code :(
/shrug
 
10:24 AM
¯\_(ツ)_/¯
 
@CrashBandicoot does your signature of your map has to be like this? HashMap <String, Object> index = new HashMap<String, Object>();
 
Yes
That's exactly how it looks
 
and do you know how to fill your map?
 
That's the problem
An enhanced for loop would work
It's just what goes inside it
 
10:28 AM
you are using a hashmap which is an implementation of the map interface
then click on: HashMap under all implementing classes
 
right
now K and V are the parameters you have to set
 
the object type
 
Key and Value
 
10:30 AM
now as K (key) you set String
 
Correct
 
which is the book title
as V you set an Objectz
 
that Object will be your Book
 
10:31 AM
since Book natively inherits from Object
now on the HashMap documentation scroll down to Method Summary
 
there is a method called put()
that method allows you to put something to your map
 
now the cool thing is
you already have an array of all your Books
 
10:34 AM
so we first use this array (myBooks) to fill your HashMap
 
in line 41
your write a loop which iterates over your array
 
for (Book book : myBooks)
{

System.out.println(book.toString());

}
 
don't call it title because its misleading :D
 
*Changed it
 
10:36 AM
you remove the system.out
 
because you don't want to output it on the console... you want to fill your HashMap with books
 
Oh yeah
Ofc
 
in your loop you add index.put(???,???);
now what might these ??? be?
 
title, Book?
 
10:39 AM
right
now how do you access the title?
 
myBooks.title?
 
no since title is a private field
to access that private field you must implement a getTitle() method
 
getTitle?
 
yes
but you don't take myBooks
you use book since that the actual book you want to access in your array
 
Why do you use book instead of myBooks?
 
10:42 AM
myBooks is an Array full of Books
first it would not compile since myBooks is an Array and does not have a method getTitle()
 
I see
 
and even if it would what title should it return out of all these?
 
It needs to be specific
Makes Sense
 
right and that is what book is for
 
For the Value?
 
10:44 AM
during every iteration step on myBooks, book contains a book
well as value you set Object
so you can literally put any value up there
but in your case you will use book
 
I see
It all makes sense now
 
since you will associate a book with a title
so you what will you put not as index.put( ???, ??? );?
 
Sorry?
index.put(book.getTitle(), book);
 
bingo!
 
Does that mean I should delete the arrayList?
 
10:47 AM
no you can fill your arrayliist too
 
Ahh okay
 
but lets stay on the hashmap for now
 
If I was to add another book to the HashMap
Would I just do index.add?
 
no index.put
on the ArrayList you would use list.add
now you want to output all the content from your HashMap?
 
Yes
Wouldn't it just be system.out.println(book);
 
10:49 AM
take a look at the methods of HashMap again
no since you would be outputting the books from the Array
and yoour goal is to output them from your hashmap
 
values()?
 
because?
 
Returns a Collection view of the values contained in this map.
 
and why is Collection good in this case?
 
Because HashMap is a Collection class?
 
10:53 AM
no
or do you see any implemented Collection interface?
 
the HashMap?
 
yes
 
index.values() returns a Collection which implements Iterable
 
Makes Sense!
That's it then
 
10:58 AM
so the cool thing now is: you can iterate of a Collection which means you can iterate of the return value of index.values()!!
 
/crashbandicoot
 
Makes Sense!
 
@motaa Thanks you so much!
 
now we go for a For Loop
anyways what type will the Collection contain?
 

« first day (2407 days earlier)      last day (2517 days later) »