File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Which is the best practice?

 
Jean Fore
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone suggets wjich is the best practice for a small program like this?

Practice 1:

public class Temperature {
public static void main(String args[])
{
double fahrenheit = 62.5;
double celsius = f2c(fahrenheit);
System.out.println(fahrenheit + "F = "+celsius +"C");
}
static double f2c(double fahr)
{
return (fahr=32)*5/9;
}
}

Practice 2 :
public class Temperature {
public static void main(String args[])
{
double fahrenheit = 62.5;
Temperature inst = new Temperature();
double celsius = inst.f2c(fahrenheit);
System.out.println(fahrenheit + "F = "+celsius +"C");
}
double f2c(double fahr)
{
return (fahr=32)*5/9;
}
}

Thanks
Jean
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a program this tiny, it obviously doesn't really matter. But you don't want to get into the habit of making everything a static method. As you write more code, you should use statics less and less.
 
Jean Fore
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much for the immediate response. All I wanted to know was how good is the practice of using 'static' methods often!! Thanks a lot.
-Jean.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic