0
0
Javaprogramming~10 mins

Procedural vs OOP approach in Java - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Concept Flow - Procedural vs OOP approach
Start
Procedural Approach
Functions operate on data
Data and functions separate
Less reusable, harder to maintain
End
Start
OOP Approach
Objects combine data + behavior
Use classes to create objects
More reusable, easier to maintain
End
Shows two flows: procedural code runs functions on data separately; OOP bundles data and behavior into objects for reuse and clarity.
Execution Sample
Java
int add(int a, int b) {
  return a + b;
}

class Calculator {
  int add(int a, int b) { return a + b; }
}
Shows a simple add function in procedural style and an add method inside a Calculator class in OOP style.
Execution Table
StepApproachActionData StateOutput
1ProceduralCall add(2, 3)No object, just inputs a=2, b=3Returns 5
2ProceduralCall add(5, 7)No object, inputs a=5, b=7Returns 12
3OOPCreate Calculator objectCalculator instance createdNo output
4OOPCall calc.add(2, 3)Calculator object with method addReturns 5
5OOPCall calc.add(5, 7)Calculator object with method addReturns 12
6EndNo more callsN/AExecution stops
💡 Execution stops after demonstrating calls in both approaches
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5Final
aN/A25N/A25N/A
bN/A37N/A37N/A
Calculator objectNoneNoneNoneCreatedExistsExistsExists
Key Moments - 2 Insights
Why do we create an object in OOP but not in procedural?
In the execution_table rows 3-5, the Calculator object is created to hold data and methods together, unlike procedural where functions are separate.
Is the add function in procedural and OOP the same?
Yes, both add two numbers and return the sum, but in OOP it is a method inside an object (rows 1,4).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, what happens?
AA Calculator object is created
BThe add function is called
CThe program ends
DVariables a and b are assigned
💡 Hint
Check the 'Action' and 'Data State' columns at step 3 in execution_table
At which step does the procedural add function return 12?
AStep 1
BStep 4
CStep 2
DStep 5
💡 Hint
Look at the 'Output' column for procedural calls in execution_table
If we did not create the Calculator object, what would change in the OOP steps?
AWe could still call calc.add()
BThere would be no object to call methods on
CThe add method would become a global function
DThe program would run faster
💡 Hint
Refer to variable_tracker and execution_table steps 3-5 about object existence
Concept Snapshot
Procedural: Functions and data are separate.
OOP: Objects combine data and behavior.
Use classes to create objects.
OOP improves reuse and maintenance.
Procedural is simpler but less flexible.
Full Transcript
This visual compares procedural and object-oriented programming approaches. Procedural code uses separate functions to operate on data, shown by calling add(2,3) and add(5,7) without objects. OOP bundles data and behavior inside objects, demonstrated by creating a Calculator object and calling its add method. Variables a and b hold inputs, and the Calculator object holds methods. Key moments include understanding why objects are created in OOP and how add works similarly in both. The quiz tests understanding of object creation, function calls, and the role of objects in OOP.