• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reflection as a noob to programming

 
Ben Calvin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted to ask your opinion on this. You being, exactly that, you, the person reading this.

I've, for the most part, been able to read a chapter and convert the ideas into code and have a functioning program. But this last one threw me off. I am doing array searches, specifically binary, and found the class example provided by the book was exactly what I needed and the demo using the class is the same. This program is using a binary search to validate a specific number.

Now, I am not asking if copying is ok or using the code as my own is ok. I am talking about, with the simple programs being done at my level, is there really anything different that could be done? Or is there some enlightenment that I haven't achieved to see this?
 
Manuel Petermann
Ranch Hand
Posts: 177
Hibernate Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what book you are talking about but mostly the programms in books are short sollutions possible.
They often do not handle errors or check arguments.
I have even seen code using double values for monetary values.
This is sort of ok if you don't want to confuse the reader with too much information about thinks they might not know about, but it leads to the delusion that it is good practice to do so.
 
Winston Gutkowski
Bartender
Pie
Posts: 10422
63
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Calvin wrote:Now, I am not asking if copying is ok or using the code as my own is ok. I am talking about, with the simple programs being done at my level, is there really anything different that could be done? Or is there some enlightenment that I haven't achieved to see this?

Well, as far as array searches go, binary chops are usually about as fast as it gets; however, they're not the fastest kind of search there is.

Arrays are usually shown to you first, because they're the most basic structure for containing lots of things; but you'll soon get introduced to the Java collections API, which has all sorts of classes for holding multiple objects - and, for searching at least, the fastest of those is a HashMap (an order of magnitude better than a binary search if you do things properly).

However, my advice: Take things one step at a time, and make sure you understand what the book is telling you before you go on to the next bit. There'll be plenty of time for learning about collections when the time is right; but right now it'll probably just be "overload".

BTW: You need to be very careful when you use a word like "reflection", because it has a very specific meaning in Java - and one that you're definitely not quite ready for yet, I suspect. I've been programming in Java for 12 years, and I still avoid it whenever possible.

Winston
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
Ben Calvin wrote:Now, I am not asking if copying is ok or using the code as my own is ok. I am talking about, with the simple programs being done at my level, is there really anything different that could be done? Or is there some enlightenment that I haven't achieved to see this?

Well, as far as array searches go, binary chops are usually about as fast as it gets; however, they're not the fastest kind of search there is.

Arrays are usually shown to you first, because they're the most basic structure for containing lots of things; but you'll soon get introduced to the Java collections API, which has all sorts of classes for holding multiple objects - and, for searching at least, the fastest of those is a HashMap (an order of magnitude better than a binary search if you do things properly).

However, my advice: Take things one step at a time, and make sure you understand what the book is telling you before you go on to the next bit. There'll be plenty of time for learning about collections when the time is right; but right now it'll probably just be "overload".

BTW: You need to be very careful when you use a word like "reflection", because it has a very specific meaning in Java - and one that you're definitely not quite ready for yet, I suspect. I've been programming in Java for 12 years, and I still avoid it whenever possible.

Winston


Yeah I was about to say I don't think he's going to want to use reflection.... I haven't really even seen any examples using reflection, from what I read reflection is used when you want to get into the JVM and allow it to do things otherwise impossible...?


As to the OP not too sure what you're asking. If you feel you can do more, then go and learn more. Read the book, or goto the Oracle trail which I recommend over a book anyways... If you are asking are there other ways to complete the task you need? Yes, normally there is many many many ways to skin a sheep.
 
Ben Calvin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys. You answered the questions I had looming in my head. I guess I just haven't achieved that ah ha moment, the oh I get it moment.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic