There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
In classic Eiffel, Meyer took a completely different approach. You have to call a “creation expression” as the first instruction, and that corresponds to a constructor. That constructor creates the app. As Fred says, that is how Gosling et al decided to implement Java.fred rosenberger wrote: . . . the designers of the language probably COULD have done something else, . . .
Campbell Ritchie wrote:
In classic Eiffel, Meyer took a completely different approach. You have to call a “creation expression” as the first instruction, and that corresponds to a constructor. That constructor creates the app. As Fred says, that is how Gosling et al decided to implement Java.fred rosenberger wrote: . . . the designers of the language probably COULD have done something else, . . .
~ Mansukh
Ivan Jozsef Balazs wrote:
If main were not static, it would be compulsory to create an instance of the class. Not that an empty constructor needs so much resources,
but why make it compulsory if there is no reason? Why make the things more complicate than necessary?
So it is a non-question to me.
PrashanthKumar Vuthuru wrote:you'd think Java would execute each and every main method it finds
You can think of main() as the door that leads into your program, once in, the computer won't try to come in again, it's already in the program! I hope this helps you a bit.
James Peterson wrote:ok let me explain why you need to give static for main method. As the main() method is starting point of program execution you cannot create object for the class in which main() is declared.
when you run a program using java exe then main mehtod is called using class name. Look following way you will compile and run any java programme.
javac Programname.java
java Programname --------> here JVM call main as Programname.main()
PrashanthKumar Vuthuru wrote:hi James Peterson
Apart From That Is There Any Reason??? please Could You Tell?
Jeff Verdegan wrote:Or we can think of it as just another step that's called as a result of other steps...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
That's the way C did it.
Just to play devil's advocate for a bit,
PrashanthKumar Vuthuru wrote:Putting the questions like this nothing will happen we will learn new things they may think differently regarding the question who posted.It Is Benfit for all not only for me???
Ivan Jozsef Balazs wrote:
Just to play devil's advocate for a bit,
It is a convention how Java handles launching a program.
There are other frameworks like servlets where another approach is taken with a reason. There you have to provide a no-arg constructor, so that the container can instantiate the class and perform init before putting it into use.
I will open the floodgates of his own worst nightmare! All in a tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
|