You can write it in as many ways as you want. The words public, static and void can be interchanged during the method declaration and still the main() method will continue to work in the same way.
i.e., public static void main(String[] args) is the same as static public void main(String[] args)
However, if you miss either of these 3 keywords from the method signature, the compiler will still let you compile the method, but it just won't be the main method that can be used to start the program execution.
The two are different, and independent from one another. A variable can be public, static, both public and static, or neither.
public static void main
-Public to all - Static to access with Class Name - Final to change( constant and not alowed to change) Just use it along with class name. (As implied above, a 'public static final' variable in Java is what other languages would call a Constant. )
Java's main function denotes the entry point into the execution of your program.
public class welcome { public static void main (String args[]) { System.out.println("Welcome to Java programming"); } } There are also many "Hello World" tutorials you can find elsewhere on the internet
public class Hello{public static void main(String [] args){System.out.println("Hello");}}
The two are different, and independent from one another. A variable can be public, static, both public and static, or neither.
public static void main
public class Main{ public static void main(String[] args){ System.out.println("the factorial of 5 is: " + getFactorial(5)); } public static int getFactorial(int num){ return num + getFactorial(num-1); } }
-Public to all - Static to access with Class Name - Final to change( constant and not alowed to change) Just use it along with class name. (As implied above, a 'public static final' variable in Java is what other languages would call a Constant. )
Java's main function denotes the entry point into the execution of your program.
public class welcome { public static void main (String args[]) { System.out.println("Welcome to Java programming"); } } There are also many "Hello World" tutorials you can find elsewhere on the internet
class Demo { public static void main(String s[]) { System.out.println("hello java frm Demo"); } } class Demo1 { public static void main(String s[]) { System.out.println("hello java frm Demo1"); String z={" "}; Demo.main(); } }
public class S{public static void main(String[]a){String o="public class S{public static void main(String[]a){String o=%c%s%c;System.out.printf(o,34,o,34);}}";System.out.printf(o,34,o,34);}}
public class HaveAGoodDay { public static void main(String[] args) { for (final String arg : args){ System.out.print(arg +" "); } } } compile and run the program: java HaveAGoodDay have a good day. output: have a good day.
class TestApp { public static void main(String args[]) { char ch; for( ch = 'a' ; ch <= 'z' ; ch++ ) System.out.println(ch); } }
if some method is static, then you can not call that method through the oobject of that class. but the name of the class. let us see a example: class Test { int a; int b; static void show() { System.out.println("we are in show"); } } class Main { public static void main(String args[]) { Test t=new Test(); t.show();\\thiss is an erroraneous code. because, the method "show()" is static. Test.show();\\this is correct } Arnas Sinha