π 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);
}
}
π 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)