mainmethod. When you run a Java application, the Java interpreter looks for a
mainmethod in the class and runs it. You should declare the main method the
mainmethod as follows:
public static void main(String args)There are a couple of differences between this method declaration and the other method declarations in the Newton class . Here are the differences:
public, the Java interpreter will allow methods from any class to call it. You can think, for now, that the default is to allow a method to be called only by other methods in the same class.
voidindicates that the method has no return value.
mainmethod takes an array of strings as an argument. You will learn more about this argument when we discuss command-line parameters.
In our Newton's method code, the
main method contains all the interesting code, and we are
going to look at the body of the code next.