DEV Community

Arun Kumar
Arun Kumar

Posted on

πŸ”Ή Java Command-Line Arguments

πŸ‘‰ What are Command-Line Arguments?
Command-line arguments are values passed to a Java program at runtime. They are received through the parameter String[] args in the main method.

βœ… Allow runtime input (like filenames, numbers, options).

πŸ“– Example:

public class Practice {
public static void main(String[] args) {
if (args.length > 0) {
System.out.println("Command-line arguments:");
for (int i = 0; i < args.length; i++) {
System.out.println("Argument " + i + ": " + args[i]);
}
} else {
System.out.println("No command-line arguments found!");
}
}
}

πŸ”Ή Components of a Method Signature

πŸ‘‰ What is a Method Signature?
A method signature in Java defines the unique identity of a method. It includes:

πŸ”Ή Method name

πŸ”Ή Parameter list (number, type, and order of parameters)

❌ Note: Return type and access modifiers are not part of the method signature.

πŸ“– Example:

public static int calculateSum(int a, int b)

➑️ Signature is: calculateSum(int, int)

πŸ“Œ Why Important?

It helps the compiler distinguish methods (method overloading).

Makes your code readable and structured.

πŸ”Ή Static Methods in Java

πŸ‘‰ What is a Static Method?
A static method belongs to the class itself, not to an instance (object).

πŸ“Œ Key Features:

βœ… Can be called directly using the class name.

βœ… No need to create an object.

βœ… Useful for utility/helper methods.
public class Practice {
// Static method
public static double square(double num) {
return num * num;
}

public static void main(String[] args) {
    // Calling static method using class name
    double result = Practice.square(7.5);
    System.out.println("Square of 7.5 is: " + result);
}
Enter fullscreen mode Exit fullscreen mode

}
πŸš€ Command-Line Arguments help us pass data to a program at runtime.

πŸš€ Method Signatures define the identity of a method (name + parameters).

πŸš€ Static Methods allow code execution without object creation.

Important clarify this doubt on trainer Tommorow πŸ‘
This double return method
πŸ‘‰πŸ‘‰πŸ‘‰πŸ‘‰πŸ‘‰public static int findMax(int x, int y) {
if (x > y) {
return x;
} else {
return y;
}
}

Top comments (0)