A basic question of main in java

  • Thread starter heman
  • Start date
346
0
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.
 
174
0
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)
 
23
0
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.
 
436
1
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().
 

Related Threads for: A basic question of main in java

  • Last Post
Replies
1
Views
7K
  • Last Post
Replies
21
Views
3K
  • Last Post
Replies
4
Views
1K
  • Last Post
Replies
1
Views
3K
  • Last Post
Replies
6
Views
1K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
22
Views
4K
  • Last Post
Replies
4
Views
16K
Top