View Full Version : a basic question of main in java
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.
poolwin2001
Nov14-04, 10:44 AM
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)
The Idiot
Nov15-04, 01:48 PM
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:
public class Circle
{
public static void main(String[] args)
{
drawCircle(args[0]);
}
void drawCircle(String a){...} //would contain code for drawing a circle of a certain color.
}
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.
ramollari
Nov16-04, 11:49 AM
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().
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.