Skip to main content

Parametrized Method Example in Java

2 min read Updated May 29, 2026
Share:
On this page (10sections)

Introduction

Parametrized Method is a classic Java console program that demonstrates the concept with complete source code and sample output. These programs cover your first Java class, constructors, methods and simple OOP building blocks.

This tutorial walks through the program line by line, explains how the logic works, and highlights best practices you can apply in your own code.

Definition

A method (or message) in object-oriented programming (OOP) is a procedure associated with an object class. An object is made up of behaviour and data. Data is represented as properties of the object and behavior as methods. Methods are also the interface an object presents to the outside world. A parameterised method holds variables.

Syntax

access_specifier return_type method_name(data_type variable_name, data_type variable_name){
	//Statements
}

Parametrized Method Example Program

public class ParametrizedMethod{
	public static void main(String[] args) {
		int num1 = 11;
		int num2 = 6;
		int num3 = minValue(num1, num2);
		System.out.println("Minimum Value while comparison of num 1 and num2 is = " + num3);
	}
	public static int minValue(int i, int j) {
		int min;
		if (i > j){
			min = j;
		}
		else{
			min = i;
		}
		return min; 
	}
}

Sample Output

Minimum Value while comparison of num1 and num2 is = 6

When to use

Use this parametrized method example when learning or revising core Java syntax.

How it works

  1. Execution begins in the main method — the JVM calls this method when you run the class.

  2. int num1 = 11; updates a variable used in the calculation or output.

  3. int num2 = 6; updates a variable used in the calculation or output.

  4. int num3 = minValue(num1, num2); updates a variable used in the calculation or output.

  5. A println / print call writes text to the console — part of the sample output below.

  6. The if statement runs the nested code only when the condition is true.

  7. min = j; updates a variable used in the calculation or output.

  8. Compare your console output with the sample output for Parametrized Method to confirm the program behaves correctly.

Best Practices

  • Name classes in PascalCase and follow one public class per file when starting out.
  • Keep main short — delegate work to other methods as programs grow.

Common Mistakes

  • Copying code without understanding each line — practice by changing one statement at a time.
  • Mismatching the public class name and the .java filename.
  • Forgetting semicolons at the end of statements.

Frequently Asked Questions

What does the Parametrized Method program demonstrate?
It shows how to implement parametrized method in Java with a complete runnable example and expected console output.
How do I run this Java program?
Save the code in a `.java` file matching the public class name, compile with `javac`, then run with `java ClassName`.
When would I use this pattern?
Use this pattern whenever you need the same logic in homework, practice or small utility tools.

Related Tutorials

Search tutorials