Parameters and Return Types in Java
In Java programming, class function parameters and return data types are important elements or structures of a user-declared function method. These user-defined class function parameters indicate how the function method accepts input or output in the current program, and how it generates output based on the input. Here, you can learn how to properly declare and Analyze user-declared class parameters and return data types in Java function programs, understand modular small program source blocks (Function Programming), and create program code or logic that can be used in multiple programs.

Parameter Element in Java Programs.
Parameters declared in Java programs are user-defined variables used to send parameter value information to a function method in the program. Function parameters provide Java programmers with input acceptance features from a user-declared function method in the program, allowing the user-declared function method to perform the desired programming operation based on the program-defined values.
Two types of parameters in Java programming.
- Formal Parameters – Formal parameters are those parameters in a function program that are created at the declaration time of a user-declared method in the function program.
- Actual Parameters (Arguments) – Actual function parameters are those values or user-declared variable value references in a function program that are provided or used when calling a function method.
Declaring Parameters in a Method in Java.
Function method parameters in any Java program are declared as user-defined custom function and variable names within brackets () at the time of function method declaration. Here, each program parameter method in the declared function method is identified by its defined data type and variable, either actual or formal.
Parameters Declaration Syntax.
<return type> <method name>(<parameter1 type> <parameter1 name>, <parameter2 type> <parameter2 name>, …) {
// function method body
}
Example of a function parameter method in Java.
public class main
{
// here we declare a total Method with parameters ‘value1’ and ‘value2’
public static int total(int value1, int value2) {
return value1 + value2;
}
public static void main(String[] args) {
// here it Calling the total function method and passing the value between actual parameters (3, 7)
int output = total(3, 7);
System.out.println(“\n The total is – ” + output);
}
}
Explaining function parameter method.
- Formal Parameters – Here, int value1 and int value2 are the actual function method arguments or data types in the declaration of the total method in the function.
- Actual Parameters (Arguments) – Similarly, when the total method is called in the main function method, 3 and 7 are the actual arguments provided.
Return Data Types in Java Functions.
Return data types in Java function programs indicate what type of value a user-defined function method returns to the caller. In Java programming, the return data type of a function method can be int, String, boolean, double, etc., or it may not return any value at the end of the program output; in this case, its default return data type is void.
Return Type – This is the value in the current program that a user-declared function method returns. This is its declared function parameter data type. It is created before the name of a user-declared function method. Here, if a method with a void data type does not return a value, its default return type is void output.
Return data Type Syntax.
<return type> <method name>(<parameter list>) {
// Function Method Body
return <value>;
}
Example of a Return Type data method.
public class Main
{
/ Here we declare a function method with a return data type of ‘int’
public static int division(int p, int q) {
return p / q; // Here it returns the division of ‘p’ and ‘q’ data type
}
public static void main(String[] args) {
/ Here it calls the user-defined division method and stores the output
int output = division(15, 3);
System.out.println(“The division is – ” + output);
}
}
Return Type data method Explanation.
- Return Type – Here the int data type indicates that the division function method returns an integer value.
- Return Statement – Here the return statement returns p / q; the division method returns ‘p’ and ‘q’.
Void Function Return Data Type.
If a user-declared function method in a Java program does not return a value, the Java programmer can declare that function method with a void return data type. The void Java keyword indicates that the declared function method will not return a value. Methods with a void return data type in Java cannot have a return statement that returns a value, where a return statement can be defined to exit the function method immediately.
Example of a Java void Method.
public class Main
{
/ here we declare the printinfo method with a void return type (no return function value)
public static void printinfo(String info) {
System.out.println(info); // Here it prints the info message
}
public static void main(String[] args) {
/ Here it calls the printinfo function method
printinfo(“Welcome to, Vcahelpsu”);
}
}
Java void Method Explanation.
Here the programmer declares the return data type of the printinfo function method as void, because this function does not return any value, it simply prints a text message info to the console screen.
Multiple Java parameters and different data types.
In a user-created Java program, a method can have multiple variable parameters as argument values, and the declared parameters can be defined as multiple data types. Function methods in Java programs are allowed to accept any user-declared combination of primitive data types, reference types (e.g., String), and object data types as parameters.
Example of multiple and group data type parameters in Java.
public class main
{
// here we declare a employeeinfo Method that accepts multiple variable parameters from different data types
public static void employeeInfo(String emp_name, int age, String address, String email, int contact) {
System.out.println(“Employee Name – ” + emp_name);
System.out.println(“Employee Age – ” + age);
System.out.println(“Address – ” + address);
System.out.println(“Email – ” + email);
System.out.println(“Contact – ” + contact);
}
public static void main(String[] args) {
// here it is calling the employeeInfo method with different user-declared data types of arguments
employeeInfo(“Bhavishi Deora”, 21, “Delhi”, “Bhavishi@gmail.com”, 941100);
}
}
Explanation of multiple and group data type parameters.
- In this example, the employeeInfo method accepts a String, int, or data type as variable parameters.
- Where user-declared program parameters are passed when this method is called in the main method of the program.
