**when we write a program in java main() will be executed first why?**

Recommended Answers

All 2 Replies

When you create a Java program you usually create a whole load of methods. How does Java know where to start executing your program? So Java was designed to always look for a method
public static void main(String[] args)
and call that to start your program

ps Welcome to DaniWeb
JC

also, that is not always the case. tons of web-apps are written in Java, and they don't start with (don't even have) a main method.
the main method is for desktop and stand alone applications the entry point for your application. it's a bit the same as asking: "when someone enters a house, they go through the door. why?"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.