Main() method in java - pre defined or user defined?

  • Thread starter anyonebutangel
  • Start date
  • Tags
    Java Method
In summary, the Java main() method is defined by the user, but its signature must follow a set pattern. The body of the method is not predefined and must be written by the programmer for each program.
  • #1
anyonebutangel
40
5
TL;DR Summary
should main() method in java be considered pre defined method or user defined?
although we cannot change the syntax of the main() method but programmer does create main() everytime in the program.so i want to ask if it should be pre defined method.
 
Technology news on Phys.org
  • #2
anyonebutangel said:
Summary:: should main() method in java be considered pre defined method or user defined?

although we cannot change the syntax of the main() method but programmer does create main() everytime in the program.so i want to ask if it should be pre defined method.
The Java main() method is defined by the user, but its signature (i.e., its argument and return type) have to follow a set pattern.
 
  • #3
Mark44 said:
The Java main() method is defined by the user, but its signature (i.e., its argument and return type) have to follow a set pattern.
So should it be pre defined?
 
  • #4
anyonebutangel said:
So should it be pre defined?
The body of the main() method is not predefined -- it has to be written by the programmer for each program.
 
  • #5
ok got it now
 

1. What is the purpose of the Main() method in Java?

The Main() method in Java is the entry point for a Java program. It is the first method that is executed when a Java program is run, and it is responsible for calling other methods and executing the program's logic.

2. Is the Main() method pre-defined in Java?

Yes, the Main() method is pre-defined in Java. It is a static method that is part of the Java language and does not need to be explicitly created by the user.

3. Can the Main() method be user-defined?

Yes, the Main() method can also be user-defined. However, it must have the correct signature (public, static, and void) and be located in the main class of the program.

4. What is the return type of the Main() method?

The Main() method has a void return type, which means it does not return any value. It is simply responsible for executing the program's logic and does not need to return a result.

5. Can the Main() method have parameters?

Yes, the Main() method can have parameters. These parameters are passed as command-line arguments when the program is run. However, the main method can also be written without any parameters if they are not needed for the program's logic.

Similar threads

  • Programming and Computer Science
Replies
3
Views
777
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
3
Views
4K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
625
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
3
Views
3K
Back
Top