main
method. When you run a Java application, the Java interpreter looks
for a main
method in the class and runs it. You should
declare the main method the main
method 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
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.
void
void
indicates that the method has no return
value.
String args[]
main
method 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.
![]() |