This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am not sure if this is in the right place, so if not, please move the thread. I'll try and keep this brief.
I am currently taking a computer science course and we're using Java as the language for the course. So far, I am really liking learning Java but I am having some difficulties with the class (my programming background is mostly C and x86 assembler). My professor is excellent, but one problem I have is his emphasis on not wanting us to repeat what he's already done in class, or repeating examples. This means that the homework (which counts for no points) takes the concepts we've discussed, and asks us to accomplish tasks using these concepts which go a bit beyond the basics. The problem I seem to be having is that these more complicated assignments don't give me much time to practice with the basic concepts before moving on to more complicated stuff. Since the homework counts for no points, all of the grading comes from exams and quizzes which is even more complicated than the homework and I feel that in order to REALLY learn and understand Java, I need more practice than one assignment per week.
With that in mind, I was wondering if anyone knows of some good resources such as example assignments, that could help me with the things I am having problems with such as generics, Java Collections Framework, and array-based lists. I've tried looking around a bit on my own, but since these are topics I am struggling with, it's tough for me to determine whether an example is good or not. Or, if anyone wants to give me an assignment that uses these concepts in a way that's basic, but not elementary, I would be most grateful
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joined: Feb 28, 2012
Hi all. Thank you all very much for the followups and suggestions. In looking through some books, I've found some exercises that I can use. Please note that these exercises are completely unrelated to any homework and the homework we do get in class, is for practice only and does not count for points.
The first assignment I picked for myself is at the starting comments of the below code which also meets the requirements (as far as I know)
I've verified that this is working as intended using the below Main.java:
Largest Number is:900
Smallest number is:4
So, my first question is for all intents and purposes, does the above look fine? Have I committed any egregious offenses?
The next assignment I am going to take on relates to the above:
Modify the MyList class that you wrote for Programming Challenge 1 so the type param-eter T should accept any type that implements the Comparable interface. Test the class in a program that creates one instance of MyList to store Integers, and another instance to store Strings.
To approach this, I have referred to the section of my book which covers, "constraining a type parameter to a type that implements an interface," which seems like what I need to do here. Unfortunately, I can't seem to figure out how to do that =/
Would it be
As I understand it, when working with generics, extends also means "implements." So in this case, we are saying that type passed to T must implement the comparable interface. Yes? If so, does the above line of code meet that requirement?
Joined: Oct 13, 2005
Yes, that means you want it to implement Comparable. But Comparable isn’t Comparable; it is Comparable<T>. You you often want <T extends Comparable<? super T>> (more details here).
Joined: Feb 28, 2012
Campbell Ritchie wrote:Yes, that means you want it to implement Comparable. But Comparable isn’t Comparable; it is Comparable<T>. You you often want <T extends Comparable<? super T>> (more details here).
Thank you very much for that. It was very helpful.
On another note, sort of a shameless bump but does anyone have any additional suggestions as to where I can get more practice with this?
Joined: Oct 13, 2005
Have you searched this forum? This sort of question comes up every few weeks.