In java, do I always need a Main class? -


i know i'll need main method, can main method in different class other main class?

not java applications require main method.

java can used create web applications, instance, don't require main methods run.

the answer question depends on mean. mean class name 'main'? then, no, there no requirement @ all.

the requirement java has, signature of method correct. main method must:

  • be public
  • be main
  • be static
  • have returntype void
  • accept array of strings (only) parameter

it's easier add in public class in file, not mandatory. name of class in, entirely you, though many choose name 'main' or 'open', more find it.

if want able run application, simple double-clicking .jar file, you'll need point class contains main method (to use: application might contain lot of main classes, used internal testing, 1 can used start actual application) in manifest file: manifest files

prior java 7, possible run desktop application without main method, (ab)using instantiation block, removed of java 7, because not instantiation block intended for.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -