How Do You Create a Callable Function in Java outside of the “main” Section?

Problem scenario
You have a public static void main (String[] args) portion of your Java program. You want to have a subroutine such as a function outside of this section. How do you code this?

In Java methods are components of an object that perform an action on the object themselves. We therefore use the term "method" here and not "function". Here is an example of a method inside a class that runs from the public static void main(String[] args) section of code:

public class ContClass {
  static void contMethod() {
    System.out.println("I just got executed!");

  public static void main(String[] args) {

Call the above file Run these commands:

java ContClass

Leave a comment

Your email address will not be published. Required fields are marked *