Java optimizations [closed] - java

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
There are a number of Java programming practices that I commonly see in use that can be optimized to provide significant speedups.
Example: For lot's of + operations on Strings, use StringBuilder instead.
What are some simple, useful optimizations one can make to potentially improve your program's performance by a significant amount?
EDIT: I'm not looking for trivial premature optimizations. This is not my intention in asking this question. Instead I would like to learn common constructs/mistakes that do constitute a significant performance hit.

Spend at least an order of magnitude more time thinking hard about the most efficient algorithms and data structures for the problem as you do thinking about how to micro-optimize specific operators, control-flow constructs, etc.
See (1)

Related

Website to practice Java coding assignments for interview [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I am looking for a website where I could practice Java coding assignments that you often get on job interviews. I mean those tasks where you need to calculate primitive numbers, implement some sorting, or do something with an Array, List or a Map. I'm quite experienced java developer, but such tasks can sometimes be tricky :)
Do you know any free websites that could help?
Thanks.
Go to interviewstreet. Companies often use it as first technical screen

Why have Apache commons-math based it's Fraction on int type? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
Why have Apache commons-math3 based it's Fraction on int type???
Are there any reasons to use int instead of long? Do we have some performance gains here? Aren't longs process at the same speed as ints on modern CPUs?
I think we got only unneeded limitations from this decision.
Please correct me if I am mistaking.
If you want arbitrary precision, use BigFraction. Many platforms -- especially e.g. Android -- have tight memory constraints and may not be as efficient for 64-bit computations. Additionally, any performance improvements to long may not have been available when Fraction was originally written, and for API compatibility, it may not be changeable.

Why is java better at handling recursion ? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I heard one of my colleagues saying that Java handles recursion more efficiently than c or C++, I was just curious what why is it able to do so? I mean what is "under the hood" process that makes this happen.
All efforts appreciated.
The usual issue around recursion (not 100% sure this is what your colleague was referring to) is whether 'it' (the compiler, the JIT, the runtime, whatever) can (and does) implement 'tail call optimization'. The goal is that instead of having the code make 'real' calls (introducing a new frame onto the call stack) that recurse (either into the same function or through the same 'cycle' of functions), you can get the same effect without doing so.
The wikipedia page is pretty decent on describing it.
http://en.wikipedia.org/wiki/Tail_call
If it's correct it's because the JIT compilation is able to optimize a recursion better than the C compiler. http://en.wikipedia.org/wiki/Just-in-time_compilation

Pros and Cons of using regex in Java [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Can someone list comprehensive list the pros and cons of using regular expressions in Java programing?
Pro: when regular expressions do what you need.
Con: when they don't.
Other than that, the question as stated is mostly ideological.
Pros:
They are an effective way to match against input.
They are easily configurable and can be separated from code.
Cons:
They be hard to read.
They are not performant. If performance is a concern do not use them.
Pro: It works and it's simple.
Con: There are none.
Why ask? Perhaps you have something more specific you'd like to know?

Java fork join algorithm analysis [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am doing a study (as part of a course requirement) on the new Fork-Join framework in Java 7 and analyze the performance improvement compared to the conventional threading mechanism. What are the kinds of divide and conquer algorithms that are guaranteed to run faster with the new fork join framework. Can you suggest any non-trivial algorithm I can work on to analyze the performance difference.
You can try N body problem: http://en.wikipedia.org/wiki/N-body_problem
or
You can try parallel sort
Maybe linear algebra problems would be a good fit: LU or QR decomposition, forward-back substitution, an eigenvalue solution method like Jacobi iteration, etc.
Finite element solution of problems in solid mechanics, heat transfer, and fluid mechanics are significant sources of these kinds of problems.

Categories

Resources