Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

A basic question of main in java

  1. Nov 14, 2004 #1
    As a very beginner to java a very basic question is in mind.in every java program we write the first line after mentioning the name of the class as


    public static void main(String[] args)


    so i want to know the importance of this line and each component in this line because i am not getting to it.
    i will be very thankful for urs help.
  2. jcsd
  3. Nov 14, 2004 #2
    Main is the function from which program execution stars.void implies that the function doesnt return a value.The rest you can put off until later.public(after learning classes)statis(types of variables)
  4. Nov 15, 2004 #3
    Since you're beginning, you may not understand the significance of the "public static," but the String[] args may be useful to know. Those are some arugments to control how your program works.

    Say you have a class "Circle." that looks something like this:

    Upon calling your program, you'd need to tell the program what color you wanted. You would, for example, call "Circle blue," and it would draw a blue circle.
  5. Nov 16, 2004 #4
    It is method main() that makes a Java class runnable. You cannot run other Java classes that don't contain this method. The compiler will give a NoSuchMethodException.
    A different case is with applets, where you don't have to declare main(). Execution starts with method init(), if any, or with paint().
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook