Solved

My Java apps run slow

Posted on 2004-09-30
6
352 Views
Last Modified: 2010-08-05
Hi Experts

I've been using Java for under a year now and have noticed that most of my Java applications with GUI's (using Swing) run rather slow compared to programs i've written in other languages.

E.g.

A while back I wrote a very simple application in Microsoft's Visual Basic, this application was a simple text editor (a bit like windows notepad but with less functionality), anyway, this app allowed the user to open a text file from the disk by using a common windows open dialog.

Now, recently I wrote a similar application in Java (using JFileChooser as the file open dialog). I noticed that my Java text editor ran very slowly. The Java application was deployed in a JAR executable.

Here are the things I noticed:

When opening the Java text editor by double clicking the jar it took a few seconds to open the application (ie. load the main GUI). I thought this could be because i had compressed the jar file and that when i open the file it may take a while decompressing, so i created another jar executable file with no compression. I noticed a very slight improvment on speed performance.

However comparing the speeds at which the Java app loaded to the VB app, the VB app loaded faster.

Now when i click file -> open (on my VB text editor), the open dialog appears much faster than when i try file -> open on my java app. The JFileChooser loads a bit slower (i used JMenu, JMenuBar, JMenuItem etc for the menu).

Ive noticed this speed problem with most of my java apps and cant find out what's the cause?

Any ideas? Does it have something to do with the JVM? Is this common?
0
Comment
Question by:Mr_A_Smith
  • 4
  • 2
6 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 20 total points
ID: 12195001
>>
I've been using Java for under a year now and have noticed that most of my Java applications with GUI's (using Swing) run rather slow compared to programs i've written in other languages.
>>

They usually do ;-)
0
 
LVL 21

Accepted Solution

by:
MogalManic earned 30 total points
ID: 12196877
The designers of the SWING API sacrificed efficiency for portablity.  Instead of using the native API for building widgets and form elements, all of the functionality is written in Java.  This gives you the ability to write the code once and it will work EXACLTY the same in Windows, Mac, MOTIF...

VB on the otherhand only runs on Windows, so it uses DLL's and Windows API functions to build its GUI.  This means it will run almost as fast as any C appliation.

Eclipse (http://www.eclipse.org) is a Java application that does NOT use Swing.  It uses a native library for its GUI and distributes a different native implementation for each OS.  If an OS does not have a particular widget, it will be implemented in Java.  If it does have the widget, the API will call the native API to build and interact with the widget.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12197832
Is Eclipse a hungry animal nonetheless MogalManic? - ive never used it
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 21

Expert Comment

by:MogalManic
ID: 12198369
What do you mean by "hungy"?  Does it use lots of memory? no

I develop on a machine that has 512M and have never run out of memory. (Except when my program has memory bugs)

Another Java IDE I use at work, IntellaJ, DOES use lots of memory though.  It all depends how the applicaiton is written and how things are stored in memory.  It seams that for IntellaJ, alot of things are cached and that uses memory quickly.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12198429
Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12203333
8-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question