The Artima Developer Community
Sponsored Link

Java Buzz Forum
Can You Run Java Program Without Main Method?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Javin Paul

Posts: 1090
Nickname: javinpaul
Registered: Jan, 2012

Javin Paul is Java Programmer working on Finance domain.
Can You Run Java Program Without Main Method? Posted: Feb 21, 2014 9:42 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: Can You Run Java Program Without Main Method?
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Latest Java Buzz Posts
Latest Java Buzz Posts by Javin Paul
Latest Posts From Java67

Advertisement
First thing Java programmers learns is that they need a main method to run, but when they goes to any Interview or college viva, and asked can you run a Java program without main method, they surprised like hell. Well, there are actually different types of execution model available in Java, for example Applets which run on browser doesn't have main method, instead they have life-cycle methods like init(), start() and stop(), which controls their execution. Since Applet is a Java program, you can answer this question in Yes. Similarly, we have Servlet, which runs in a Servlet container, comes as bundled in web server like Tomcat, or Jetty. Servlet also works on callback mechanism, it has methods like init(), service() and destroy(). Container calls init() if Servlet is first time loaded into memory, calls service() if there is a request to process and calls destroy() before removing it from memory. Since Servlet is also a Java program, we can say that it runs without main method. Third one on this category is MIDlet, which runs on mobile devices e.g. Nokia, Samsung and others. MIDlet has life-cycle methods like startApp(), pauseApp() and destroyApp(), to start, pause and shut-down mobile applications. Ironical J2ME has app in their core method, but it was made popular by Android and iPhone. Since MIDlets are also Java program, you can say they run without main method. Now, if Interviewer persist you with something like this, Can you run a Java program without main method in Core Java, not on managed environment like the case of Applet, Servlet and MIDlet. Answer is NO, Why? I will explain that in next paragraph. By the way, this is one of the many questions related to main method in Java, you can see the full list of interview question on main method here.
Read more ยป

Read: Can You Run Java Program Without Main Method?

Topic: Two Ways to Get the Most Out of Daily Stand-up Meetings Previous Topic   Next Topic Topic: Creating Maven Source and Javadoc Artifacts

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use