Dail
Dail

Reputation: 4606

How to speed up Java applications?

I need to use Java for a desktop application. I heard that there are many tools that compile java natively, is this true? does these tools compile java program into machine code?

THank you!

Upvotes: 0

Views: 6656

Answers (4)

Mike Thomsen
Mike Thomsen

Reputation: 37506

I need to use Java for a desktop application. I heard that there are many tools that compile java natively, is this true? does these tools compile java program into machine code?

Such programs do exist, but may come with tradeoffs when using some of the more dynamic capabilities of the Java platform like you may lose the ability to load new classes at runtime. The JVM may have a slow start up, but it's plenty fast enough once it gets going.

That said, one solution that I didn't see anyone mention here is to replace code written in Swing with SWT. The SWT toolkit uses native code underneath.

Upvotes: 0

Joop Eggen
Joop Eggen

Reputation: 109547

I agree with the others that compiling to machine code does not make much sense: mind that C free/malloc have same or higher costs than Java new/garbage collection.

The NetBeans IDE comes with a built-in Profiler; so you could profile your application in that IDE to find bottlenecks.

Upvotes: 2

Johannes Weiss
Johannes Weiss

Reputation: 54011

Since the (Sun/Oracle) Java VM has a good JIT (just-in-time) compiler, you don't have to compile your Java program to machine code yourself. The compiler will do that on the fly when it's necessary.

So: Speed up your Java programs just as every other program:

  • reduce algorithmic complexity
  • exploit parallelism
  • compute at the right moment
  • find and remove bottlenecks
  • ...

Since Java is a garbage collected language, there is one important point to more speed: reduce allocations! Reducing allocations will help you at least twice: The allocation itself isn't done and the garbage collector will have to do less work (which will save time).

Upvotes: 7

Rafael Sanches
Rafael Sanches

Reputation: 1823

are you coding the app or it's someone's else?

It looks you're trying to run an java app that is slow. Try increasing the memory when running it. You can change the shell script specifying these params: java -Xms64m -Xmx512m

Upvotes: 1

Related Questions