Should I be using static or instance methods?

For starters, the difference between static and instance variables is that, only ONE static variable exists for all the instances of the class, whereas an instance variable exists for EVERY instance of the class.

Now, when you are talking about methods, in most cases you need to make a method static when you are trying to call it from another static method (such as main).

In general this practice is wrong for OOP, and chances are you should rethink the way the program is structured.

If you could provide more details about the code you use to call these methods, I would be able to help you with more details on how to fix this.

EDIT: In light of the new info you provided:

1) I believe that bmrMain,BMRMain and Calculations can all be merged into one class. The constructor of the new class should be adjusted to read input (as well as getters and setters for each variable for added flexibility - optional)

2) Regarding the calculation of the bmr part, there are many ways to tackle this, so I will go ahead and suggest the one that is best in my opinion. Add a Button with a text "Click to calculate" or something similar, and implement an ActionListener. The action Listener will in turn call (whenever the button is clicked) the method that calculates everything, and finally it will change the text on the JLabel.

sample code for the action Listener:

JButton button = new JButton("Text Button");
button.addActionListener(new ActionListener()
  public void actionPerformed(ActionEvent e)
    //Call the methods for the calculation
    // bmr and tdee are temporary variables to store the results from the methods
    //handle them properly, or remove them if not needed (I just wrote a sample)
    int bmr = calcBMR(...); //pass the correct variables as arguments here
    int tdee;
    if(userHasPickedTDEE) {  tdee = calcTDEE(...); }  //and here


These 2 steps will take care of your "static" problem.

I recommend that you do some research on event-driven programming

And here is some extra and more in-depth reading on Action Listeners

If you need further help, or clarifications let me know :)


In general, yes it is a good practice to separate classes in order to keep the code manageable. But in this case I think it is a bit superfluous to create a new class just for 2 methods. Nevertheless if you would like to keep the current structure, the way to fix the "static" is: 1) remove static from the 2 calculation methods. 2)line 332 should be

Calculations c = new Calculations();
bmrValue = c.calcBMR(userAge, userGender, userHeight, userWeight);


Well, these questions can easily be transferred to a thread of their own. But here is a useful link from a quick google search I just did, that will help demistify the static keyword:

Static keyword in Java


I use static whenever my class is just used to call those methods (i.e. my main method calls the static methods to set variables in the main class, etc). I believe that is the "utility" class that KDM mentioned. A small example of when I use static or utility classes:

class Utility {
  public static int add(int a, int b) {
    // You would, of course, put something besides simple addition here
    return a + b;

class Main {
  public static void main(String[] args) {
    int a = 2, b = 3;
    int sum = Utility.add(a, b);

On the other hand, if you have a class that is closer to an actual object, with properties of its own, stay away from static. If you use static, then each instance of the class which you want to be separate objects will end up with same values.

Based on the name and functionality of your class, it appears you have a utility class. Static should be fine, but it may not be necessary. Hypothetically, though, if you wanted to use this class with multiple "people" class instances for which to calculate the BMR (where each instance is unique), then I would put calcBMR() in a person class and make it non-static so that each person has their own calcBMR().

Edit: Maybe this will help too:

Instance -> Instantiate: new Calculations().instanceMethod();

Static -> Class itself, the class's "state": Calculations.staticMethod();


I need to call some functions generated by some libs. I will need to call fucntion1, function2, ..., function10 one by one. Instead of writing them all out on the code, is there any clever way to code ...

this is the snippet that produces an error saying : ')' expected ';' expected not a statement cannot find symbol symbol : variable ActionEvent The snippet : private void jMenuItem5ActionPerformed(...

I know that a child cannot reduce the visibility of a non-static method and I understand why it is so. I've read however that "static method can be hidden through its redeclaration". I however do not ...

I am using swing to build a GUI with 4 JPanels inside a JPanel using the BorderLayout manager: A row of labels A column of JButtons A display area (it is a class that extends JPanel and has nothing ...