Java: manually-unrolled loop is still faster than the original loop. Why?

Consider the following two snippets of code on an array of length 2: boolean isOK(int i) { for (int j = 0; j < filters.length; ++j) { if (!filters[j].isOK(i)) { return false; } } return true; } and boolean isOK(int i) { return filters[0].isOK(i) && filters[1].isOK(i); } I would assume that the performance of these … Read more

How do I present text vertically in a JLabel ? (Java 1.6)

I’m looking to have text display vertically, first letter at the bottom, last letter at the top, within a JLabel. Is this possible? Answer I found this page: http://www.java2s.com/Tutorial/Java/0240__Swing/VerticalLabelUI.htm when I needed to do that. I don’t know if you want the letters ‘standing’ on each other or all rotated on their side. /* * … Read more

Should validators in spring access the database?

I’m not really sure if it’s a good design decision to make the validators validate commands based on the state of the database. For example if I need to validate a User bean besides checking if the email and username are empty etc. I also need to reject values if they are already used. Should … Read more

Code complexity analysis tools beyond cyclomatic complexity [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed 2 years ago. Improve this question While cyclomatic complexity is a worthwhile metric, I tend to find it to be a poor tool for identifying … Read more

How much memory does a Java object use when all its members are null?

Is it correct to assume a Java object only takes up the 8 bytes for the object reference as long as all it’s members are set to null or does the definition of members already use up space in the instance for some reason? In other words, if I have a large collection of objects … Read more

Shortest path (fewest nodes) for unweighted graph

I’m trying build a method which returns the shortest path from one node to another in an unweighted graph. I considered the use of Dijkstra’s but this seems a bit overkill since I only want one pair. Instead I have implemented a breadth-first search, but the trouble is that my returning list contains some of … Read more