jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Few General Questions 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
Reply locked New topic
Author

Few General Questions

Nelson Sam
Ranch Hand

Joined: Jun 12, 2010
Posts: 30
Since I am a beginner in Java.I get lots of doubts .Here are few things which confuses me.

1.Java provides While and Do while statements.As we know do while executes atleast once.I wanted to know when to use while and do while statements in real time environment.

2.In Java we can give inputs using constructors or from keyboards.But using command line arguments we can pass the input while runtime.Is there any real time application of it?Or it is just for the programmers.

3.When does garbage collection takes place? Runtime or compile time
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11153
    
  16

Nelson Sam wrote:Since I am a beginner in Java.I get lots of doubts .Here are few things which confuses me.

1.Java provides While and Do while statements.As we know do while executes atleast once.I wanted to know when to use while and do while statements in real time environment.

you answered that question yourself. You use the do-while when you know you want the code to execute at least once. You use a while when you may or may not want it to execute at least once. A login script may use a do-while, because you know you want the user to try at least once to get their name/pw entered.

a monitoring script may use a while - i.e. while (there are files to process) { do this }. It's possible there are no files when it starts, so it shouldn't do anything.

Nelson Sam wrote:2.In Java we can give inputs using constructors or from keyboards.But using command line arguments we can pass the input while runtime.Is there any real time application of it?Or it is just for the programmers.

using the command line gives the program input...using constructors gives input to objects in your program. So it's possible you could use the command line to get input, which is then fed to a constructor of an object.

With GUI's, the command line input is seen less. But often the program is controlled by what is passed in, even if the common end-user never sees it. A sys admin may tweak settings that the user never sees.

And a minor note..."command line arguments" generally refer to what command you use to start the program, i.e. "java MyClass debug hilogging". if you then enter more input while the program is running, those are not considered 'command line arguments'.

Nelson Sam wrote:3.When does garbage collection takes place? Runtime or compile time


Basically, garbage collection runs when your program starts using up too much memory. During compile time, you don't actually create any object, you just create the blueprints. Only at runtime are objects created, therefore, only at runtime would you start using too much memory.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Nelson Sam
Ranch Hand

Joined: Jun 12, 2010
Posts: 30
Thanks fred rosenberger for such a detailed explation.
I am learning a lot here.
Thank you all
Nelson Sam
Ranch Hand

Joined: Jun 12, 2010
Posts: 30
One more question.I dont want to create a new thread for this small doubt.

I want to know whether object and reference variable mean same.

Date mydate=new Date();

Is mydate an object or reference variable :
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37943
    
  22
Nelson Sam wrote:One more question.I dont want to create a new thread for this small doubt.
But you ought to. You already have a thread title which tells us little of what the thread is about, and you are making it worse with a new question.

I shall pull rank and make you use use one thread per question by closing this thread.
 
 
subject: Few General Questions
 
Similar Threads
do-while loop in real time
setEditable and blinking cursor
Smart Inspect questions
Why Scala?
what's the reason for poor performance