3

Let's consider the following java program:

class Helper{
 public static int add(int a,int b){
  ....
 }
}

public class Calculator {
  public static void main(String[] args){
     System.out.println(Helper.add(5,10));
  }   
}

I mean if I use java but I don't create any instances of classes and in all classes I use only static methods and fields does it mean that I use procedural paradigm of programming but not object oriented?

Pavel_K
  • 10,748
  • 13
  • 73
  • 186
  • 4
    I like this question. I'm not sure what the answer really should be, but my first initial though was "yeah, sure". Then I came to think about different scenarios, where the static methods you call, would create their own objects under the surface. But it depends on the intent and definition of the question, I guess. – jumps4fun Mar 03 '16 at 10:13
  • How would you define the procedural paradigm in a way that doesn't contain OOP already? AFAIK procedural programming simply says that you'll have variables for storing data and procedures that operate on them. Which is what OOP is, except OOP also mandates that the two are bound firmly together. – biziclop Mar 03 '16 at 10:42

2 Answers2

3

Yes - I suppose that one could call that procedural programming. I imagine you will have static variables containing values which will be altered by the methods (this is what is meant by a side effect) so this style is not 'functional' programming which requires no side effects.

It seems like a strange thing to do - if you have a task that requires procedural programming use a procedural language.

It seems to me you are trying to use a chainsaw to hammer a nail in when there are perfectly good hammers around.

Elemental
  • 7,365
  • 2
  • 28
  • 33
1

You would be executing functions returning values without any effect on variables/objects outside said functions (aka "side effects"). That in short would be functional programming. See this for the difference with procedural, or that for more about functional programming.

Edit: the above assumes you do not use static fields.

Community
  • 1
  • 1
John K
  • 1,285
  • 6
  • 18
  • 1
    As the OP mentions using static 'fields' I think that he probably DOES intend to use side-effects; thus this is not functional programming imho, – Elemental Mar 03 '16 at 10:33