tag:blogger.com,1999:blog-8712770457197348465.post5659396501065294711..comments2016-12-09T06:41:24.236-08:00Comments on Javarevisited: Why main method is public static in JavaJavin Paulhttps://plus.google.com/114528699166048052030noreply@blogger.comBlogger27125tag:blogger.com,1999:blog-8712770457197348465.post-31529903692219789872016-03-09T22:31:54.538-08:002016-03-09T22:31:54.538-08:00How JVM understands execution completed of void me...How JVM understands execution completed of void methods , since void doesn&#39;t return anything ??hackermanidhttp://www.blogger.com/profile/05044250522960219048noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-5873807748797381352015-06-15T20:41:06.378-07:002015-06-15T20:41:06.378-07:00@Anonymous, this is interesting question beause ma...@Anonymous, this is interesting question beause main in C returns int but main is void in Java. I guess only reason could be becasue only JVM calls this method and Java relies on excepiton than error code so it doesn&#39;t care what main returns. Since there is no way programmer can query JVM to find out what main returns is another reason it made void. Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-30941593283378232602015-06-14T21:54:07.118-07:002015-06-14T21:54:07.118-07:00why main has to be void?why main has to be void?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-45775590405209376392014-07-16T10:10:23.095-07:002014-07-16T10:10:23.095-07:00If public modifier is removed (made default or mad...If public modifier is removed (made default or made private)then JVM reports following: -<br />Main method not public.<br /><br />If arguments are modified like (String[]args, int i)...to test overloading....then it reports following: -<br />Exception in thread &quot;main&quot; java.lang.NoSuchMethodError: main<br /><br />This leads to a conclusion that this is a STANDARD FORMAT, JVM looks for, Omkarhttp://www.blogger.com/profile/00453537025986887886noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-18568903307109298382014-06-10T01:55:41.624-07:002014-06-10T01:55:41.624-07:00hello sir you tesch us that main method must be pu...hello sir you tesch us that main method must be public because public method can access easily outside the class i agree with you but non specifire methods are also like a public but this code is not run<br />static void main(String s[]) why it is also accessable outside the classMoaz Aminhttp://www.blogger.com/profile/02412655938104813522noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-76191758528982069332014-04-01T04:01:15.349-07:002014-04-01T04:01:15.349-07:00This is how you can invoke NON-STATIC method from ...This is how you can invoke NON-STATIC method from main<br /><br />public class TestMain {<br /><br /> public static void main(String[] args) {<br /> TestMain test = new TestMain();<br /> test.invokeMethodFromMain();<br /> }<br /> <br /> private void invokeMethodFromMain(){<br /> System.out.println(&quot;inovked NON-STATIC method from main method&quot;);<br /> }<br />}<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-84099165704121156392013-08-26T02:57:41.987-07:002013-08-26T02:57:41.987-07:00similarly i want that my functions in one class ca...similarly i want that my functions in one class can be called by any other class that i define, without creating object of class whose function i want to be called how do i accomplish this<br />keep in mind no friend function is allowed<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-43069582463686175582013-08-26T02:53:28.340-07:002013-08-26T02:53:28.340-07:00for exmaple my main fuction is not static how can ...for exmaple my main fuction is not static how can i call main function i.e can i call main function after creating an object of class in which it is defined and calling it keeping in view that main function is not defined &quot;Static&quot; Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-38540671084781776932013-08-21T01:32:56.937-07:002013-08-21T01:32:56.937-07:00does any one knows how to call a non static method...does any one knows how to call a non static method from main method in Java? I am getting &quot;cannot make a static reference to the non-static method&quot; error while calling a non static method, declared in same class. please helpAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-10979603872900733762013-08-13T09:16:51.100-07:002013-08-13T09:16:51.100-07:00This is really helpful for a beginner. Thanks This is really helpful for a beginner. Thanks Docket Smarthttp://www.blogger.com/profile/13325529728393718556noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-56362903514885203782013-03-13T10:14:15.325-07:002013-03-13T10:14:15.325-07:00why other static methods are executed after main()...why other static methods are executed after main() method is executed even when main() method is also static?Sasmita Nayakhttp://www.blogger.com/profile/15135498618939773475noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-37411188261108412912012-11-26T23:35:00.747-08:002012-11-26T23:35:00.747-08:00can you please tell why it si mandatory to pass St...can you please tell why it si mandatory to pass String args[] as a argument to main ()?neha shirlekarhttp://www.blogger.com/profile/01494349759403207573noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-34679700432306534832012-11-05T20:14:43.777-08:002012-11-05T20:14:43.777-08:00Here is my list of frequently asked question on ma...Here is my list of frequently asked question on main in Java<br />1. Can we overload main method in Java?<br />2. Can we make main method final in Java ?<br />3. can we override main in Java ?<br />4. How to call a non static method from main in Java ?<br />5. can we make main method synchronized ?<br /><br />These are good questions for any beginner to know more about Main method in Java.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-66424119707755891702012-08-14T06:00:38.086-07:002012-08-14T06:00:38.086-07:00In order to access the Class must be public. All J...In order to access the Class must be public. All JVM are written using JVM specification and I have never heard of any JVM changing signature of Main method, if you have better reason than please share.Javin Paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-16223693158920734532012-08-14T05:51:03.947-07:002012-08-14T05:51:03.947-07:00JVM does not find for the Main Method its the JNI....JVM does not find for the Main Method its the JNI. Secondly your logic that why main is public has no reason. Since the class is never instantiated it doesn&#39;t matter is its public or not.<br /><br />Main method is entry point for any Core Java program, &quot;Any&quot;...no<br /><br />should be &quot;public, static and void in Java&quot;, no you can write your own JVM and instead have some Asterhttp://www.blogger.com/profile/10484022201928989054noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-8043403632154550622012-05-20T23:37:52.100-07:002012-05-20T23:37:52.100-07:00here are few more questions like why main is stati...here are few more questions like why main is static:<br /><br />Why run method in Java doesn&#39;t return any thing ?<br />Why start method is used to start thread instead of run ?<br /><br />By the way you can run Java class even without main method, just put your code inside static initializer block and it will be run when class will be loaded.Peternoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-75044641507642422172012-03-27T20:51:13.646-07:002012-03-27T20:51:13.646-07:00Can main method throw Exception in Java?
indeed ma...Can main method throw Exception in Java?<br />indeed main method can throw Exception both checked and unchecked.<br /><br />Can main method be overloaded in java?<br />Yes main method in java can be overloaded but JVM will only invoke main method with standard signature.<br /><br />Can main method be overridden in java?<br />Yes main method in java can be overridden and the class you passed to Dimistrinoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-63599990908870320862012-03-27T01:28:47.054-07:002012-03-27T01:28:47.054-07:00Can we throw exception from main method in Java ? ...Can we throw exception from main method in Java ? I am asking both checked and unchecked Exception. Also when do we get error &quot;no main class found your program will terminate&quot;Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-85295390642857727582012-02-15T07:00:04.565-08:002012-02-15T07:00:04.565-08:00Can we declare main method private? this was the q...Can we declare main method private? this was the question asked to me. What will happen if we make main method private in Java, i said we can not access it from outside of Class since its private and also can not run Java program, was that correct answer ?Radhikanoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-6947096798648477362012-01-17T21:28:31.905-08:002012-01-17T21:28:31.905-08:00Java Main method can also throw any Exception or E...Java Main method can also throw any Exception or Error in its throws clause, following main method in java is perfectly legal:<br />public static void main(String args[]) throws AssertionErrorAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-47751684856116430062012-01-14T06:47:39.451-08:002012-01-14T06:47:39.451-08:00even though main method should not return values,i...even though main method should not return values,it can use empty return statement.<br />ex return; allowed<br />but return somevalue; not allowediTfinGer Odehttp://www.blogger.com/profile/12763994939103603985noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-9363358595293182412012-01-11T00:32:07.194-08:002012-01-11T00:32:07.194-08:00do you know how to pass arguments to main method i...do you know how to pass arguments to main method in Java and how to get those arguments inside java program ?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-36113967542054088622011-12-30T07:16:48.887-08:002011-12-30T07:16:48.887-08:00Nice explanation of &#39;public static void main(S...Nice explanation of &#39;public static void main(Strin args[])&#39;. here is my post on the same &#39;<a href="http://www.code2learn.com/2011/11/public-static-void-mainstring-args.html" rel="nofollow">public static void main(String args[]): Explained</a><br /><br />here is point too on main:<br /><br />The main method can be overloaded.farhan khwajahttp://www.blogger.com/profile/13928134991864169687noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-31474641171037151672011-12-25T20:09:50.823-08:002011-12-25T20:09:50.823-08:00@Neeraj
We have servlet &amp; other as managed jav...@Neeraj<br />We have servlet &amp; other as managed java objects. The java runtime environment provides many facilities like memory allocation &amp; garbage collection etc. Our main application is executed by the JRE process. The process can return the status to the OS as zero or some other integer to return its status. Your application can return the value or JVM itself. Thus it might have make Ashutosh Agarwalhttp://www.blogger.com/profile/09478149757598449240noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-88928454186595203022011-12-21T18:57:11.311-08:002011-12-21T18:57:11.311-08:00Following are valid main method signature:
public...Following are valid main method signature:<br /><br />public static void main(String[] argument)<br />public static void main(String argument[])<br />public static void main(String... args)<br />public static synchronized void main(String... args)<br />public static strictfp void main(String... args)<br />public static final void main(String... args)Anonymousnoreply@blogger.com