Why main method is marked as public?












5















I have a question that why main method is marked as public?



According to an answer on stackoverflow, It is declared as static





"The method is static because otherwise there would be ambiguity: which constructor should be called?"





But, can anyone can explain why it is declared public always?










share|improve this question























  • So it can be called from anywhere?

    – Vincent Ramdhanie
    Dec 18 '13 at 19:09






  • 2





    Because the Java standard says so ;)

    – Oliver Charlesworth
    Dec 18 '13 at 19:10











  • @OliCharlesworth What is the reason by the way?

    – user1494459
    Dec 18 '13 at 19:11











  • See the answer to stackoverflow.com/questions/10028589/…

    – Dror Bereznitsky
    Dec 18 '13 at 19:11











  • @drorb what if we do not make it public? A method is package-private if it has no access-modifier specified.

    – user1494459
    Dec 18 '13 at 19:17
















5















I have a question that why main method is marked as public?



According to an answer on stackoverflow, It is declared as static





"The method is static because otherwise there would be ambiguity: which constructor should be called?"





But, can anyone can explain why it is declared public always?










share|improve this question























  • So it can be called from anywhere?

    – Vincent Ramdhanie
    Dec 18 '13 at 19:09






  • 2





    Because the Java standard says so ;)

    – Oliver Charlesworth
    Dec 18 '13 at 19:10











  • @OliCharlesworth What is the reason by the way?

    – user1494459
    Dec 18 '13 at 19:11











  • See the answer to stackoverflow.com/questions/10028589/…

    – Dror Bereznitsky
    Dec 18 '13 at 19:11











  • @drorb what if we do not make it public? A method is package-private if it has no access-modifier specified.

    – user1494459
    Dec 18 '13 at 19:17














5












5








5


3






I have a question that why main method is marked as public?



According to an answer on stackoverflow, It is declared as static





"The method is static because otherwise there would be ambiguity: which constructor should be called?"





But, can anyone can explain why it is declared public always?










share|improve this question














I have a question that why main method is marked as public?



According to an answer on stackoverflow, It is declared as static





"The method is static because otherwise there would be ambiguity: which constructor should be called?"





But, can anyone can explain why it is declared public always?







java main public






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 18 '13 at 19:08







user1494459




















  • So it can be called from anywhere?

    – Vincent Ramdhanie
    Dec 18 '13 at 19:09






  • 2





    Because the Java standard says so ;)

    – Oliver Charlesworth
    Dec 18 '13 at 19:10











  • @OliCharlesworth What is the reason by the way?

    – user1494459
    Dec 18 '13 at 19:11











  • See the answer to stackoverflow.com/questions/10028589/…

    – Dror Bereznitsky
    Dec 18 '13 at 19:11











  • @drorb what if we do not make it public? A method is package-private if it has no access-modifier specified.

    – user1494459
    Dec 18 '13 at 19:17



















  • So it can be called from anywhere?

    – Vincent Ramdhanie
    Dec 18 '13 at 19:09






  • 2





    Because the Java standard says so ;)

    – Oliver Charlesworth
    Dec 18 '13 at 19:10











  • @OliCharlesworth What is the reason by the way?

    – user1494459
    Dec 18 '13 at 19:11











  • See the answer to stackoverflow.com/questions/10028589/…

    – Dror Bereznitsky
    Dec 18 '13 at 19:11











  • @drorb what if we do not make it public? A method is package-private if it has no access-modifier specified.

    – user1494459
    Dec 18 '13 at 19:17

















So it can be called from anywhere?

– Vincent Ramdhanie
Dec 18 '13 at 19:09





So it can be called from anywhere?

– Vincent Ramdhanie
Dec 18 '13 at 19:09




2




2





Because the Java standard says so ;)

– Oliver Charlesworth
Dec 18 '13 at 19:10





Because the Java standard says so ;)

– Oliver Charlesworth
Dec 18 '13 at 19:10













@OliCharlesworth What is the reason by the way?

– user1494459
Dec 18 '13 at 19:11





@OliCharlesworth What is the reason by the way?

– user1494459
Dec 18 '13 at 19:11













See the answer to stackoverflow.com/questions/10028589/…

– Dror Bereznitsky
Dec 18 '13 at 19:11





See the answer to stackoverflow.com/questions/10028589/…

– Dror Bereznitsky
Dec 18 '13 at 19:11













@drorb what if we do not make it public? A method is package-private if it has no access-modifier specified.

– user1494459
Dec 18 '13 at 19:17





@drorb what if we do not make it public? A method is package-private if it has no access-modifier specified.

– user1494459
Dec 18 '13 at 19:17












9 Answers
9






active

oldest

votes


















6














The initialization software that starts your program must be able to see main so that it can call it.






share|improve this answer





















  • 2





    Java visibility concept does not apply to JVM - As JVM can access any method irrespective to its access level defined. See my answer below for details.

    – Gyanendra Dwivedi
    Apr 21 '15 at 4:45



















12














Because the JLS, Section 12.1.4, says so:




The method main must be declared public, static, and void. It must specify a formal parameter (§8.4.1) whose declared type is array of String.




If it's not public, then it won't be found; you'll get



Error: Main method not found in class Main, please define the main method as:
public static void main(String args)





share|improve this answer

































    6














    I believe, the rational behind enforcing main as public is more to do with the language specification – rather than whether something could be achieved or not.



    Refer:
    http://docs.oracle.com/javase/specs/jls/se7/html/jls-12.html#jls-12.1.4




    The method main must be declared public, static, and void. It must
    specify a formal parameter (§8.4.1) whose declared type is array of
    String. Therefore, either of the following declarations is acceptable:




    Java uses JNI launch java application will never have any issue in calling a private main – but this is more like jail-brake (like another jail-brake, where reflection API let you access private method) and definitely not in spirit of java specification.





    If I remember till JDK 1.3 – it was not mandatory from developer’s perspective. i.e. even a private main was being accepted by JRE. Though, it was not inline with JLS 1.3.



    I tried searching JLS 1.3 for a reference, but could not get a link. But I found that it was reported as a bug by developers across world:



    Please refer: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4155575



    So, a fix was made in subsequent version to enforce rule stated by JLS.



    Now, the point is why JLS writer enforced this rule at first place – I really have no idea. The only thing I can think of is that – to keep it “obvious” and non-confusing for developers.






    share|improve this answer































      1














      Because that is what is known as the "entry point" and if it is private, your program will not be able to run.






      share|improve this answer































        0














        Public - main method is called by JVM to run the method which is outside the scope of project therefore the access specifier has to be public to permit call from anywhere outside the application.



        From coderanch






        share|improve this answer































          0














          When the code is executed, a JVM will be created and that will act as a container for the code we are trying to execute. Declaring this method as public allows the JVM to start the code execution. If method is private, JVM wont be able to call it.
          There are ways to call a private method as well (eg by using Reflection), but that is not a standard way to do things.






          share|improve this answer

































            0














            In Java a function or variable in class in unaccessible untill an Object is created from the class, but the 'main' function is supposed to run at startup(without Object initiation) by JVM. So the 'main' is declared public as well as static so that it can be accessed outside class & without even an Object is created.






            share|improve this answer































              -1














              Yes the standards say so that main method should be public in Java. But it's not only for Java. However even for C#, main must be public.



              So just think about it in real world scenarios.



              E.g. you want to enter your room, but you should enter your home main door first (given room is inside the house...and no other means to enter the house)



              Main door is the only publicly available access point.






              share|improve this answer































                -2














                Because the main method should be accessed by JVM without any restrictions from any where. I think you can find more info here: Why main method is public






                share|improve this answer
























                • The JVM executes the main method using native API and java visibility concept does not apply here. In fact till JDK 1.3 developer could actually write private main.

                  – Gyanendra Dwivedi
                  Apr 21 '15 at 4:42











                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f20666421%2fwhy-main-method-is-marked-as-public%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown
























                9 Answers
                9






                active

                oldest

                votes








                9 Answers
                9






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                6














                The initialization software that starts your program must be able to see main so that it can call it.






                share|improve this answer





















                • 2





                  Java visibility concept does not apply to JVM - As JVM can access any method irrespective to its access level defined. See my answer below for details.

                  – Gyanendra Dwivedi
                  Apr 21 '15 at 4:45
















                6














                The initialization software that starts your program must be able to see main so that it can call it.






                share|improve this answer





















                • 2





                  Java visibility concept does not apply to JVM - As JVM can access any method irrespective to its access level defined. See my answer below for details.

                  – Gyanendra Dwivedi
                  Apr 21 '15 at 4:45














                6












                6








                6







                The initialization software that starts your program must be able to see main so that it can call it.






                share|improve this answer















                The initialization software that starts your program must be able to see main so that it can call it.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 19 '18 at 23:22

























                answered Dec 18 '13 at 19:10









                Eric PostpischilEric Postpischil

                75.6k880162




                75.6k880162








                • 2





                  Java visibility concept does not apply to JVM - As JVM can access any method irrespective to its access level defined. See my answer below for details.

                  – Gyanendra Dwivedi
                  Apr 21 '15 at 4:45














                • 2





                  Java visibility concept does not apply to JVM - As JVM can access any method irrespective to its access level defined. See my answer below for details.

                  – Gyanendra Dwivedi
                  Apr 21 '15 at 4:45








                2




                2





                Java visibility concept does not apply to JVM - As JVM can access any method irrespective to its access level defined. See my answer below for details.

                – Gyanendra Dwivedi
                Apr 21 '15 at 4:45





                Java visibility concept does not apply to JVM - As JVM can access any method irrespective to its access level defined. See my answer below for details.

                – Gyanendra Dwivedi
                Apr 21 '15 at 4:45













                12














                Because the JLS, Section 12.1.4, says so:




                The method main must be declared public, static, and void. It must specify a formal parameter (§8.4.1) whose declared type is array of String.




                If it's not public, then it won't be found; you'll get



                Error: Main method not found in class Main, please define the main method as:
                public static void main(String args)





                share|improve this answer






























                  12














                  Because the JLS, Section 12.1.4, says so:




                  The method main must be declared public, static, and void. It must specify a formal parameter (§8.4.1) whose declared type is array of String.




                  If it's not public, then it won't be found; you'll get



                  Error: Main method not found in class Main, please define the main method as:
                  public static void main(String args)





                  share|improve this answer




























                    12












                    12








                    12







                    Because the JLS, Section 12.1.4, says so:




                    The method main must be declared public, static, and void. It must specify a formal parameter (§8.4.1) whose declared type is array of String.




                    If it's not public, then it won't be found; you'll get



                    Error: Main method not found in class Main, please define the main method as:
                    public static void main(String args)





                    share|improve this answer















                    Because the JLS, Section 12.1.4, says so:




                    The method main must be declared public, static, and void. It must specify a formal parameter (§8.4.1) whose declared type is array of String.




                    If it's not public, then it won't be found; you'll get



                    Error: Main method not found in class Main, please define the main method as:
                    public static void main(String args)






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Dec 18 '13 at 19:17

























                    answered Dec 18 '13 at 19:11









                    rgettmanrgettman

                    150k21205289




                    150k21205289























                        6














                        I believe, the rational behind enforcing main as public is more to do with the language specification – rather than whether something could be achieved or not.



                        Refer:
                        http://docs.oracle.com/javase/specs/jls/se7/html/jls-12.html#jls-12.1.4




                        The method main must be declared public, static, and void. It must
                        specify a formal parameter (§8.4.1) whose declared type is array of
                        String. Therefore, either of the following declarations is acceptable:




                        Java uses JNI launch java application will never have any issue in calling a private main – but this is more like jail-brake (like another jail-brake, where reflection API let you access private method) and definitely not in spirit of java specification.





                        If I remember till JDK 1.3 – it was not mandatory from developer’s perspective. i.e. even a private main was being accepted by JRE. Though, it was not inline with JLS 1.3.



                        I tried searching JLS 1.3 for a reference, but could not get a link. But I found that it was reported as a bug by developers across world:



                        Please refer: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4155575



                        So, a fix was made in subsequent version to enforce rule stated by JLS.



                        Now, the point is why JLS writer enforced this rule at first place – I really have no idea. The only thing I can think of is that – to keep it “obvious” and non-confusing for developers.






                        share|improve this answer




























                          6














                          I believe, the rational behind enforcing main as public is more to do with the language specification – rather than whether something could be achieved or not.



                          Refer:
                          http://docs.oracle.com/javase/specs/jls/se7/html/jls-12.html#jls-12.1.4




                          The method main must be declared public, static, and void. It must
                          specify a formal parameter (§8.4.1) whose declared type is array of
                          String. Therefore, either of the following declarations is acceptable:




                          Java uses JNI launch java application will never have any issue in calling a private main – but this is more like jail-brake (like another jail-brake, where reflection API let you access private method) and definitely not in spirit of java specification.





                          If I remember till JDK 1.3 – it was not mandatory from developer’s perspective. i.e. even a private main was being accepted by JRE. Though, it was not inline with JLS 1.3.



                          I tried searching JLS 1.3 for a reference, but could not get a link. But I found that it was reported as a bug by developers across world:



                          Please refer: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4155575



                          So, a fix was made in subsequent version to enforce rule stated by JLS.



                          Now, the point is why JLS writer enforced this rule at first place – I really have no idea. The only thing I can think of is that – to keep it “obvious” and non-confusing for developers.






                          share|improve this answer


























                            6












                            6








                            6







                            I believe, the rational behind enforcing main as public is more to do with the language specification – rather than whether something could be achieved or not.



                            Refer:
                            http://docs.oracle.com/javase/specs/jls/se7/html/jls-12.html#jls-12.1.4




                            The method main must be declared public, static, and void. It must
                            specify a formal parameter (§8.4.1) whose declared type is array of
                            String. Therefore, either of the following declarations is acceptable:




                            Java uses JNI launch java application will never have any issue in calling a private main – but this is more like jail-brake (like another jail-brake, where reflection API let you access private method) and definitely not in spirit of java specification.





                            If I remember till JDK 1.3 – it was not mandatory from developer’s perspective. i.e. even a private main was being accepted by JRE. Though, it was not inline with JLS 1.3.



                            I tried searching JLS 1.3 for a reference, but could not get a link. But I found that it was reported as a bug by developers across world:



                            Please refer: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4155575



                            So, a fix was made in subsequent version to enforce rule stated by JLS.



                            Now, the point is why JLS writer enforced this rule at first place – I really have no idea. The only thing I can think of is that – to keep it “obvious” and non-confusing for developers.






                            share|improve this answer













                            I believe, the rational behind enforcing main as public is more to do with the language specification – rather than whether something could be achieved or not.



                            Refer:
                            http://docs.oracle.com/javase/specs/jls/se7/html/jls-12.html#jls-12.1.4




                            The method main must be declared public, static, and void. It must
                            specify a formal parameter (§8.4.1) whose declared type is array of
                            String. Therefore, either of the following declarations is acceptable:




                            Java uses JNI launch java application will never have any issue in calling a private main – but this is more like jail-brake (like another jail-brake, where reflection API let you access private method) and definitely not in spirit of java specification.





                            If I remember till JDK 1.3 – it was not mandatory from developer’s perspective. i.e. even a private main was being accepted by JRE. Though, it was not inline with JLS 1.3.



                            I tried searching JLS 1.3 for a reference, but could not get a link. But I found that it was reported as a bug by developers across world:



                            Please refer: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4155575



                            So, a fix was made in subsequent version to enforce rule stated by JLS.



                            Now, the point is why JLS writer enforced this rule at first place – I really have no idea. The only thing I can think of is that – to keep it “obvious” and non-confusing for developers.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Dec 24 '14 at 16:21









                            Gyanendra DwivediGyanendra Dwivedi

                            4,04811643




                            4,04811643























                                1














                                Because that is what is known as the "entry point" and if it is private, your program will not be able to run.






                                share|improve this answer




























                                  1














                                  Because that is what is known as the "entry point" and if it is private, your program will not be able to run.






                                  share|improve this answer


























                                    1












                                    1








                                    1







                                    Because that is what is known as the "entry point" and if it is private, your program will not be able to run.






                                    share|improve this answer













                                    Because that is what is known as the "entry point" and if it is private, your program will not be able to run.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Dec 18 '13 at 19:11









                                    HonaninHonanin

                                    1111211




                                    1111211























                                        0














                                        Public - main method is called by JVM to run the method which is outside the scope of project therefore the access specifier has to be public to permit call from anywhere outside the application.



                                        From coderanch






                                        share|improve this answer




























                                          0














                                          Public - main method is called by JVM to run the method which is outside the scope of project therefore the access specifier has to be public to permit call from anywhere outside the application.



                                          From coderanch






                                          share|improve this answer


























                                            0












                                            0








                                            0







                                            Public - main method is called by JVM to run the method which is outside the scope of project therefore the access specifier has to be public to permit call from anywhere outside the application.



                                            From coderanch






                                            share|improve this answer













                                            Public - main method is called by JVM to run the method which is outside the scope of project therefore the access specifier has to be public to permit call from anywhere outside the application.



                                            From coderanch







                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered Dec 18 '13 at 19:11









                                            Anirban Nag 'tintinmj'Anirban Nag 'tintinmj'

                                            3,50431936




                                            3,50431936























                                                0














                                                When the code is executed, a JVM will be created and that will act as a container for the code we are trying to execute. Declaring this method as public allows the JVM to start the code execution. If method is private, JVM wont be able to call it.
                                                There are ways to call a private method as well (eg by using Reflection), but that is not a standard way to do things.






                                                share|improve this answer






























                                                  0














                                                  When the code is executed, a JVM will be created and that will act as a container for the code we are trying to execute. Declaring this method as public allows the JVM to start the code execution. If method is private, JVM wont be able to call it.
                                                  There are ways to call a private method as well (eg by using Reflection), but that is not a standard way to do things.






                                                  share|improve this answer




























                                                    0












                                                    0








                                                    0







                                                    When the code is executed, a JVM will be created and that will act as a container for the code we are trying to execute. Declaring this method as public allows the JVM to start the code execution. If method is private, JVM wont be able to call it.
                                                    There are ways to call a private method as well (eg by using Reflection), but that is not a standard way to do things.






                                                    share|improve this answer















                                                    When the code is executed, a JVM will be created and that will act as a container for the code we are trying to execute. Declaring this method as public allows the JVM to start the code execution. If method is private, JVM wont be able to call it.
                                                    There are ways to call a private method as well (eg by using Reflection), but that is not a standard way to do things.







                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Sep 8 '17 at 9:30

























                                                    answered Sep 8 '17 at 9:23









                                                    GaurangaGauranga

                                                    4703725




                                                    4703725























                                                        0














                                                        In Java a function or variable in class in unaccessible untill an Object is created from the class, but the 'main' function is supposed to run at startup(without Object initiation) by JVM. So the 'main' is declared public as well as static so that it can be accessed outside class & without even an Object is created.






                                                        share|improve this answer




























                                                          0














                                                          In Java a function or variable in class in unaccessible untill an Object is created from the class, but the 'main' function is supposed to run at startup(without Object initiation) by JVM. So the 'main' is declared public as well as static so that it can be accessed outside class & without even an Object is created.






                                                          share|improve this answer


























                                                            0












                                                            0








                                                            0







                                                            In Java a function or variable in class in unaccessible untill an Object is created from the class, but the 'main' function is supposed to run at startup(without Object initiation) by JVM. So the 'main' is declared public as well as static so that it can be accessed outside class & without even an Object is created.






                                                            share|improve this answer













                                                            In Java a function or variable in class in unaccessible untill an Object is created from the class, but the 'main' function is supposed to run at startup(without Object initiation) by JVM. So the 'main' is declared public as well as static so that it can be accessed outside class & without even an Object is created.







                                                            share|improve this answer












                                                            share|improve this answer



                                                            share|improve this answer










                                                            answered Apr 3 '18 at 4:49









                                                            KondalKondal

                                                            1,26521332




                                                            1,26521332























                                                                -1














                                                                Yes the standards say so that main method should be public in Java. But it's not only for Java. However even for C#, main must be public.



                                                                So just think about it in real world scenarios.



                                                                E.g. you want to enter your room, but you should enter your home main door first (given room is inside the house...and no other means to enter the house)



                                                                Main door is the only publicly available access point.






                                                                share|improve this answer




























                                                                  -1














                                                                  Yes the standards say so that main method should be public in Java. But it's not only for Java. However even for C#, main must be public.



                                                                  So just think about it in real world scenarios.



                                                                  E.g. you want to enter your room, but you should enter your home main door first (given room is inside the house...and no other means to enter the house)



                                                                  Main door is the only publicly available access point.






                                                                  share|improve this answer


























                                                                    -1












                                                                    -1








                                                                    -1







                                                                    Yes the standards say so that main method should be public in Java. But it's not only for Java. However even for C#, main must be public.



                                                                    So just think about it in real world scenarios.



                                                                    E.g. you want to enter your room, but you should enter your home main door first (given room is inside the house...and no other means to enter the house)



                                                                    Main door is the only publicly available access point.






                                                                    share|improve this answer













                                                                    Yes the standards say so that main method should be public in Java. But it's not only for Java. However even for C#, main must be public.



                                                                    So just think about it in real world scenarios.



                                                                    E.g. you want to enter your room, but you should enter your home main door first (given room is inside the house...and no other means to enter the house)



                                                                    Main door is the only publicly available access point.







                                                                    share|improve this answer












                                                                    share|improve this answer



                                                                    share|improve this answer










                                                                    answered Mar 12 '14 at 16:54









                                                                    bonCodigobonCodigo

                                                                    12.3k12972




                                                                    12.3k12972























                                                                        -2














                                                                        Because the main method should be accessed by JVM without any restrictions from any where. I think you can find more info here: Why main method is public






                                                                        share|improve this answer
























                                                                        • The JVM executes the main method using native API and java visibility concept does not apply here. In fact till JDK 1.3 developer could actually write private main.

                                                                          – Gyanendra Dwivedi
                                                                          Apr 21 '15 at 4:42
















                                                                        -2














                                                                        Because the main method should be accessed by JVM without any restrictions from any where. I think you can find more info here: Why main method is public






                                                                        share|improve this answer
























                                                                        • The JVM executes the main method using native API and java visibility concept does not apply here. In fact till JDK 1.3 developer could actually write private main.

                                                                          – Gyanendra Dwivedi
                                                                          Apr 21 '15 at 4:42














                                                                        -2












                                                                        -2








                                                                        -2







                                                                        Because the main method should be accessed by JVM without any restrictions from any where. I think you can find more info here: Why main method is public






                                                                        share|improve this answer













                                                                        Because the main method should be accessed by JVM without any restrictions from any where. I think you can find more info here: Why main method is public







                                                                        share|improve this answer












                                                                        share|improve this answer



                                                                        share|improve this answer










                                                                        answered May 2 '14 at 11:45









                                                                        Mdhar9eMdhar9e

                                                                        77631742




                                                                        77631742













                                                                        • The JVM executes the main method using native API and java visibility concept does not apply here. In fact till JDK 1.3 developer could actually write private main.

                                                                          – Gyanendra Dwivedi
                                                                          Apr 21 '15 at 4:42



















                                                                        • The JVM executes the main method using native API and java visibility concept does not apply here. In fact till JDK 1.3 developer could actually write private main.

                                                                          – Gyanendra Dwivedi
                                                                          Apr 21 '15 at 4:42

















                                                                        The JVM executes the main method using native API and java visibility concept does not apply here. In fact till JDK 1.3 developer could actually write private main.

                                                                        – Gyanendra Dwivedi
                                                                        Apr 21 '15 at 4:42





                                                                        The JVM executes the main method using native API and java visibility concept does not apply here. In fact till JDK 1.3 developer could actually write private main.

                                                                        – Gyanendra Dwivedi
                                                                        Apr 21 '15 at 4:42


















                                                                        draft saved

                                                                        draft discarded




















































                                                                        Thanks for contributing an answer to Stack Overflow!


                                                                        • Please be sure to answer the question. Provide details and share your research!

                                                                        But avoid



                                                                        • Asking for help, clarification, or responding to other answers.

                                                                        • Making statements based on opinion; back them up with references or personal experience.


                                                                        To learn more, see our tips on writing great answers.




                                                                        draft saved


                                                                        draft discarded














                                                                        StackExchange.ready(
                                                                        function () {
                                                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f20666421%2fwhy-main-method-is-marked-as-public%23new-answer', 'question_page');
                                                                        }
                                                                        );

                                                                        Post as a guest















                                                                        Required, but never shown





















































                                                                        Required, but never shown














                                                                        Required, but never shown












                                                                        Required, but never shown







                                                                        Required, but never shown

































                                                                        Required, but never shown














                                                                        Required, but never shown












                                                                        Required, but never shown







                                                                        Required, but never shown







                                                                        Popular posts from this blog

                                                                        鏡平學校

                                                                        ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

                                                                        Why https connections are so slow when debugging (stepping over) in Java?