File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes About String usage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "About String usage " Watch "About String usage " New topic
Author

About String usage

Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215

Hi folks,

I was working on a application which gets a XML file as input which i am going to parse using SAX parser. In my code i have defined lot of variables (around 60 to 70 String objects) in the fashion shown below



as you can see all these objects are final which i am going to use it for String equality check condition. I am getting worried about the amount of memory these String objects consume. Is there a better way of doing the same thing?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


I am getting worried about the amount of memory these String objects consume.

Why? Are you seeing performance issues with your applications? Do you have a very constrained deployment environment?


Is there a better way of doing the same thing?

I'm guessing these variables match the elements you need to parse? If this is the case, no. You need the have the element name in order to match it.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215


Why? Are you seeing performance issues with your applications? Do you have a very constrained deployment environment?


Yes, it takes some time to finish parsing the XML file.
To be more clear i am generating my application GUI based on the XML file and after parsing through the file then only i am able to get the GUI which requires some time.


I'm guessing these variables match the elements you need to parse? If this is the case, no. You need the have the element name in order to match it.


Yes i am using those variables for that purpose while parsing.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Parsing XML files can be slow. Its unlikely it is your use of these String variables that is the cause is though. It is also unlikely that memory is the constraint. If it were, you might start to see OutOfMemoryErrors. My guess is the bottleneck is the CPU.

There is a general rule for Swing applications, do not do lengthy non-GUI work on the event-dispatch thread. Do you need to use or show your entire XML model when you start your application, or can you use SwingUtilities to improve the responsiveness of the GUI?
Mintoo kumar
Ranch Hand

Joined: Aug 21, 2007
Posts: 61
It's better use SAX parser API ,where every method which is required to parse XML file has given. That will be helpful.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Originally posted by mintoo kumar:
It's better use SAX parser API ,where every method which is required to parse XML file has given. That will be helpful.


Balasubramanian Chandrasekaran is using a SAX parser.
Mintoo kumar
Ranch Hand

Joined: Aug 21, 2007
Posts: 61
my focus was like

origina post code:
--------------------------------------------------------------------------------

public static final String STARTING_TAG = "start";public static final String ELEMENT_START_TAG = "element";...............public static final String ENDING_TAG = "end";

--------------------------------------------------------------------------------

rather using these elements use the methods and all the facility avliable in SAX parser API.

Hope i made the point correctly.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Not sure I follow. My assumption is Balasubramanian Chandrasekaran is using these values to work out what to do with an element when the Handler's startElement method is fired. What SAX API methods do you mean?
Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215

Paul you are correct, I use those String object for equality check.

My scenario is:
1. I will check whether i got my application starting tag by checking the parsed value to my STARTING_TAG object if that matches i will be doing relevant operations like constructing a new JFrame which will get all the components.
2. Then i will again check the equality condition on parsed value with my ELEMENT_START_TAG and then i will check what is that type of element and construct the relevant component onto the JFrame which i created previously.

....... Likewise it goes.

And can you please explain in detail.What you mean by

Do you need to use or show your entire XML model when you start your application, or can you use SwingUtilities to improve the responsiveness of the GUI?


Regarding Mintoo Kumar reply,

rather using these elements use the methods and all the facility avliable in SAX parser API.

I don't get what you are trying to convey?


After Displaying my JFrame i am calling


Whether this will guarantee Garbage Collection on my String objects??
[ May 13, 2008: Message edited by: Balasubramanian Chandrasekaran ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About String usage