Home

Forums

Web development

 

 

 

 
     
 
dna88 Web development and Technology Forum
 
Profile   Register   Memberlist   Usergroups   FAQ   Search  Log in
Questions ?? (Alarm example)

 
Post new topic   Reply to topic    dna88 Forum Index -> Programming in Java, C, C#, VB, .NET Discussion Forum
Author Message
hunter d
Just In
Just In


Joined: 27 Oct 2004
Posts: 2

Post Post subject: Questions ?? (Alarm example) Reply with quote

hi,

Code:

13 public Alarm(long delta) {
14 //alarm goes off ’delta ’ (milliseconds) from now.
15 Date now = new Date() ;
16 alarmTime = new Date(now.getTime()+delta) ;
17 linkMe() ;
18 }


The questions is
In line 15 every time we create an object to get the time in line 16.
Can we do that in one step without create the object (now) ??
If not, after we use it, it will be removed by garbage collecter or it will be kept in the memory without doing anything?
Wed Oct 27, 04 9:30 am
Back to top
hunter d View user's profile Send private message
dinangkur
Super Moderator
Super Moderator


Joined: 24 Mar 2004
Posts: 491
Location: Dhaka, Bangladesh

Post Post subject: Reply with quote

Hi,

Main philosophy behind OOP is using object when needed it and destroy it when it is done. As in C++ grabage collection is needed to done through programming. In java it is down by Java itself, so you don't need to think about to clear the memory.

-DK
_________________
...we too are stardust...
Wed Oct 27, 04 9:46 pm
Back to top
dinangkur View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
hunter d
Just In
Just In


Joined: 27 Oct 2004
Posts: 2

Post Post subject: Reply with quote

hi again,

well you didnt answer my question very well , there two point didnt answer them :

1- Can we do that in one step without create the object (now) ??

2- If not, after we use it, it will be removed by garbage collecter or it will be kept in the memory without doing anything?
Thu Oct 28, 04 5:30 pm
Back to top
hunter d View user's profile Send private message
illusionist
Beginner User
Beginner User


Joined: 15 Jul 2004
Posts: 25

Post Post subject: Reply with quote

looks like some Java code to me than some pseudocode.In that case ur answers will be:

1.Yes.In that case line 15 would not exist and line 16 would have been:

Code:
alarmTime = new Date((new Date()).getTime()+delta) ;


2.If you would have created the object instance "now" then after line 18 "now" is no longer referenced.Garbage collector runs periodically, frees dynamically allocated memory that is no longer referenced. So "now" will be destroyed whenever garbage collector finds it not referenced.
Fri Oct 29, 04 1:01 pm
Back to top
illusionist View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    dna88 Forum Index -> Programming in Java, C, C#, VB, .NET Discussion Forum All times are GMT - 7 Hours
Page 1 of 1

 

Partners and Resources

Bangladesh hosting company

Bangladesh web design

Driven by phpBB © phpBB Group