Methods are used to perform specific tasks and can be reused throughout your code.
Source Code
public class MethodExample {
static void printMessage(String message) {
System.out.println(message);
}
public static void main(String[] args) {
printMessage("Hello, Java!");
}
}