Jai Gates wrote:I don't know whether to put a try-catch block in a loop or vice versa....
You choose the one that makes the most sense.
It would help to have a list of operations and their resource overhead.
Nope. Not something that should be a factor in deciding how to write your code.
Learn good and efficient algorithms as you go along, yes. But worrying about the efficiency of individual operations, or worse, writing contorted code because you think it will be "more efficient", will definitely steer you wrong.
Jai Gates wrote:Does anyone know of a good resource/s that could tell me the efficiency of individual operation in Java
No, and you don't need it. The "efficiency" at the very low level is something you can't control and that will be handled differently by different JVM implementations and versions. If you want your program to run efficiently, use good design and appropriate algorithms and data structures.
I don't know whether to put a try-catch block in a loop or vice versa....
You won't make that choice for "efficiency" reasons. You'll make it for design and functionality reasons. If you want your entire loop to stop when one exception occurs, put the loop inside the try. If you want to be able to recover from an exception on a given iteration and continue looping, put the try inside the loop.
Write code that says what you mean. Don't try to be "clever" in the name of "efficiency."
Since I'm such a beginner I might just get this thing to work albeit inefficiently so I can get the thing in on time. ..but it bothers me.
Good performance will come from things like using Sets to find an intersection of collections, rather than an O(N^2) nested for loop over two Lists. You won't see a difference from things like the relative location of your loops and try statements. For good performance, write dumb code!
posted 5 years ago
For good performance, write dumb code!
Advice I can follow xD thanks for article. will read.