Know the java-feature from scratch-you don't know the main function

Source: Internet
Author: User

In this chapter we will discuss the main function.

For this function everyone is not unfamiliar, and all are accustomed to. But there are some things that are worth summarizing.

1. Normal Main

Package Com.ray.test;public class Maintest {public static void main (string[] args) {}}

Nothing special. is an empty method of main


2. The main without static

Package Com.ray.test;public class Maintest {public void main (string[] args) {}}

Compile as passed, just can't run. A run will report Nosuchmethod anomalies.


3. Main with no references

Package Com.ray.test;public class Maintest {public static void main () {}}

Compiled as passed. Just can't run. A run will report Nosuchmethod anomalies.


4. The main of the string is the number of references

Package Com.ray.test;public class Maintest {public static void main (String args) {}}

Compiled as passed. Just can't run, a run will report Nosuchmethod exception


5. Have final main

Package Com.ray.test;public class Maintest {public static final void main (String args) {}}
Compile as passed, just can't run. A run will report Nosuchmethod anomalies.


6. Main with return value

Package Com.ray.test;public class Maintest {public static int main (String args) {return 0;}}
Compile the same pass, just can't run, a run to report Nosuchmethod exception


7. Explanation

Now here's an explanation of the above main, and in fact all of the above main, we've all been misled.

All of the main functions above are not what we call a main function that can be executed. It's just a normal function called Main.

We can build a common main function that we know in the following


Or the technical point is that we overload (note: Not rewrite) main this function, but our JVM only recognize his format of the main function, otherwise. class file cannot be executed


Summary: This chapter mainly introduces you do not know the main function, in fact, here is the title party, hehe.


This chapter is here, thank you.

-----------------------------------

Folder


Know the java-feature from scratch-you don't know the main function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.