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 What is the differance ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is the differance ?" Watch "What is the differance ?" New topic
Author

What is the differance ?

arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Hello,
I have a basic questions in the following code snippent what is the best way of declaring the mp object..which will take less memory..
regards,
Arun


[ April 26, 2002: Message edited by: Dirk Schreckmann ]
Mark Herschberg
Sheriff

Joined: Dec 04, 2000
Posts: 6037
They will take the same memory. The only difference is when the object is created, during the construction of the class, or when the method is called, the latter being a case of delayed initialization.
--Mark
arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Thanks for you reply...
Which one you prefer?
Arun
[ April 27, 2002: Message edited by: arun mahajan ]
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
The reason for delaying initialization is to allow the delaying the creation of memory intensive objects until the last minute. If this fellow is going to be HUGE then you might want to delay - and then null out that variable as soon as possible.
Otherwise it is probably better to create the object at the place the variable is declared. If the initialization is too far removed from the variable declaration you run the risk that the reader will have forgotten the "type" of the variable by the time you get around to putting something in it.
Saving programmer time is a big issue also.


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the differance ?
 
Similar Threads
Why this object gets null in actionPerformed
Can you help me to write better code ?
why this component access is multiplying?
How to set this component?
How to listen toolbar buttons?