• Post Reply Bookmark Topic Watch Topic
  • New Topic

what are the prime difference between System class and Runtime class?  RSS feed

 
jacob deiter
Ranch Hand
Posts: 588
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what are the prime difference between System class and Runtime class ?

I googled it ,but it confused me ,so anybody please explain the difference ?

when I should go for System class and Runtime Class
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the obvious answer is you use each to do what they are designed to do. Your question is kind of like asking "When do I use a forklift, and when do I a tugboat?" you use a forklift to do forklift things, and a tugboat to do tugboat things.

did you look at the api for each class? Look at what methods each has to get an idea when to use each.
 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The documentation isn't very helpful, but System refers to the computer you are using and Runtime to the running of the JVM you are using. That is a very basic generalisation. you should use whichever provides the methods you need. Beware of methods like runfinalizersOnExit and execute and anything called stop. There are problems relating to those methods.
Also System has mostly static members and Runtime mostly instance members. You can't get an instance of System, but you can get an instance of Runtime from a factory method.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should ask what the commonalities between System and Runtime are. That list is quite short; it contains just 6 methods:
- exit
- gc
- load
- loadLibrary
- runFinalization
- runFinalizersOnExit

And for all these methods, System simply redirects the call to the object returned by Runtime.getRuntime().
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!