This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Programming Techniques Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Programming Techniques" Watch "Programming Techniques" New topic
Author

Programming Techniques

Rajesh Kumar
Greenhorn

Joined: Nov 16, 2001
Posts: 28
Hi Friends
I am new to Java
My java class file size is 15 k now.
Is there anyway to reduce the size of class file.
I heard that the efficient way of doing programming is doing program which generates less size of class name.
is there anybody knows how to do the programming which will creates the less size class name ?
please give me some programming techniques.
Thanks in advance
Yours
Rajesh
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

Unless you really have a need, don't spend time worrying about the sizes of your classes. Worry about writing code that makes sense.


Please ignore post, I have no idea what I am talking about.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Well tinkering with the size of a classfile is really just optimization, much the same as trying to improve performance. So I thought that I would share with you some thoughts on the topic.
From "Effective Java" by Joshua Bloch (quotes that he took from elsewhere) Item 37 (page 162)

More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity.
-William A. Wulf


We should forget about small efficiencies, say about 97% of the time; premature optimization is the root of all evil.
-Donald E. Knuth


We follow two rules in the matter of optimization:
Rule 1. Don't do it.
Rule 2 (for experts only) Don't do it yet-that is, not until you have a perfectly clear and unoptimized solution.
-M.A.Jackson


Strive to write good programs rather than fast ones.
Strive to avoid design decisions that limit performance.
-Joshua Bloch

So the advice is to forget about the footprint of your class and the speed of the code until the code is bug-free. Then get a refactoring book and start worrying about such things.

[This message has been edited by Cindy Glass (edited December 19, 2001).]


"JavaRanch, where the deer and the Certified play" - David O'Meara
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I have to disagree with Cindy on this. Sorry Cindy. Of course, you are a better source for knowledge on JAVA than I am. But I look at this situation from a different point of view.
Forget about the language. Optimization is something that programmers have ignored since memory and CPU speeds began to grow. "Oh, we are only utilizing 16 of the 64 bits of a CPU running at 1.3 GigHz. Who cares if it is optimized. It will still run fast." Bah I say!!
Can you imagine going back to a full blown app and try to optimize it then?? How much code would you realize that you had to re-write?
I think that optimization and speed should be at least in the top 5 programming stages. (Yes, even in the JAVA world)
Just think how much better Windows could be if Microsoft worried about such things.
Just my opinion.


GenRocket - Experts at Building Test Data
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521

And a valid opinion it is too.
Note that I was just quoting Joshua.
While he has a very valid point, I must admit that we have code reviews that look at performance and efficiencies - even on an original write.
However admitting that makes for much fewer fireworks .
That said, I am not sure that just decreasing the size of a classfile is going to make an application more efficient. A typical method of doing this is to split that large class into smaller classes. While that is probably a good idea from an OO point of view, it could be LESS efficient, it sort of depends on the code.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4442
    
    5

The thing with performance tuning is that focus is often misplaced. Use a profiler to identify the bottlenecks in your application. That takes a lot of the guesswork and "gut feel" out of the process. Then decide which bottleneck, if any, is worth optimizing.
Is it really worth having 4 reviewers spend 15 minutes (for a total of 1 hour of costly development time) arguing over whether a for loop is more efficient that a while loop? This example may be extreme but the point is, optimize only when it is worth the effort.
Good programs are those that are: clear, simple, well-structured. Get the form right and speed will follow. For the majority of the work we do, this is as optimal as we should strive for.
My $0.02
Junilu

Junilu - [How to Ask Questions] [How to Answer Questions]
Reuben Cleetus
Ranch Hand

Joined: Jul 13, 2001
Posts: 50
I suppose what can be best said for Optimization, is that it is something that ought not to take precedence over the primary goals in Software Engineering -- create an app that satisfies user requirements, AND which is easy to maintain.
Readability and maintainability are therefore a very high priority. I think programmers in general should err on the side of readability, unless speed is absolutely mission-critical. I cannot think of any such application that I have been involved in, and frankly, I don't think there are many cases when speed absolutely is THE most important issue.
Surely device drivers and other low-level system programming can justifiably promote speed very high up on the list of priorities, but elsewhere, it should be balanced with maintainability.
Regards,
Reuben Cleetus.
Jason Kretzer
Ranch Hand

Joined: May 31, 2001
Posts: 280
Just an addition to what said above. In my opinion, readability is the most important aspect of coding, besides meeting the specs. To anyone who is new reading this--there is almost nothing easier to maintain than well commented code. Self-commenting code along with well placed block and inline comments can save much and many headaches.

------------------
Jason R. Kretzer
Software Engineer
http://alia.iwarp.com


Jason R. Kretzer<br />Software Engineer<br />System Administrator<br /><a href="http://alia.iwarp.com" target="_blank" rel="nofollow">http://alia.iwarp.com</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Programming Techniques
 
Similar Threads
java socket programming
Parsingof XML taking time
Question on how to run an application....
Why Java at all?
Deploymen Descriptor (web.xml) file