Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Emily Diaz   on Jul 14 In Java Category.

  
Question Answered By: Cheri Garcia   on Jul 14

The java  interpreter is designed to run  Java "applications". Apart from
applications, which are usually executed outside of a browser
environment, you have applets, which are integrated into web pages, and
other special Java programs such as JavaBeans, servlets and handlers.
The java interpreter upon execution first looks for an executable main()
method, that provides the "point-of-entry" into your application.
In a C/C++ application, you would usually omit the argc, argv params if
your program  is not going to accept any command  line arguments. However
the PSVM(String[] args) line  is what tells it to expect a Java
stand-alone application. (You would be omitting this line in applets and
other non-application programs) Since the main  function has to be of the
form
public static  void main(String[] args)
any deviation from this syntax would cause Java to assume that you are
using a custom method  called main, which is obviously not a point of
entry into the program.
Your second program compiles because Java thinks you are creating your
own custom main method for use somewhere else. It is only when the java
interpreter tries to "run" your program, it looks for the main() method,
and not finding an exact match, triggers the exception.
In the end, all you have to remember is that Java is not C or C++,
although it may look syntactically the same, and what goes for one
language usually does not for another. Hope this helped to some extent.

Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on command line parameters Or get search suggestion and latest updates.


Tagged: