File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Reflection as a noob to programming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reflection as a noob to programming" Watch "Reflection as a noob to programming" New topic
Author

Reflection as a noob to programming

Ben Calvin
Greenhorn

Joined: Feb 07, 2013
Posts: 12
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

Joined: Jul 19, 2011
Posts: 175

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.


Please correct my English.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7529
    
  18

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

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

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

Joined: Feb 07, 2013
Posts: 12
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Reflection as a noob to programming
 
Similar Threads
java beginner
16bit binary to decimal problem
A drop pf help might quench my thirst!!
Edit specific line in a file
Storing variables in an array