| Author |
y aint here class <classname>=new <classname> used and instead only class <classname> used
|
Vishal Hegde
Ranch Hand
Joined: Aug 01, 2009
Posts: 970
|
|
why aint here Runtime rt=newRuntime used
and i have heard that refernce variables in method cannot have default value
so
what is being assigned at Runtime rt=Runtime.getRuntime()
and how come predefined methods like
rt.totalMemory()
rt.freeMemory()
used if rt reference value isnt assigned anything that is if its not declared as
Runtime rt=new Runtime();
|
http://www.lifesbizzare.blogspot.com || OCJP:81%
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16684
|
|
Vishal Hegde wrote:why aint here Runtime rt=newRuntime used
and i have heard that refernce variables in method cannot have default value
so
what is being assigned at Runtime rt=Runtime.getRuntime()
That is how the Runtime class is designed. There aren't any public contructors that can be used to construct a Runtime instance. Instead, it uses a factory method, which returns the singleton instance that has been contructed by the class.
Vishal Hegde wrote:and how come predefined methods like
rt.totalMemory()
rt.freeMemory()
used if rt reference value isnt assigned anything that is if its not declared as
Runtime rt=new Runtime();
Just because you didn't directly use the new operator, doesn't mean that the instance hasn't been created -- it was. It was instantiated and returned when you called the getRuntime() method.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3670
|
|
Vishal Hegde wrote:what is being assigned at Runtime rt=Runtime.getRuntime()
used if rt reference value isnt assigned anything that is if its not declared as
Runtime rt=new Runtime();
getRuntime() is a static method which returns the Runtime object associated with the current Java application, so the "rt" reference refers to an instance of the Runtime class.
and how come predefined methods like
rt.totalMemory()
rt.freeMemory()
You still can invoke any instance method(s) using "rt" reference.
|
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
|
 |
Vishal Hegde
Ranch Hand
Joined: Aug 01, 2009
Posts: 970
|
|
Henry Wong wrote:
Instead, it uses a factory method, which returns the singleton instance that has been contructed by the class
what is a factory method and whats singleton instance
|
 |
Saifuddin Merchant
Ranch Hand
Joined: Feb 08, 2009
Posts: 576
|
|
Vishal Hegde wrote:
Henry Wong wrote:
Instead, it uses a factory method, which returns the singleton instance that has been contructed by the class
what is a factory method and whats singleton instance
What did you find out when you searched for those terms? You did search for those terms right?
|
Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32636
|
|
|
Please Use Real words, not "y".
|
 |
 |
|
|
subject: y aint here class <classname>=new <classname> used and instead only class <classname> used
|
|
|