• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

There is no main method in class: Times - How do I resolve it?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am trying to get following program work, it compiles fine, but when I try to run it on console, it gives me a message:

There is no main method in class: Times

Here is the code for your reference:

 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The signature of the main method, called at the start of an application is very specific... It must be...



Henry
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch Munjal!
Yes, As Henry said, the JVM is picky. While the compiler dosen't care (to a degree of course) how you declare the main method, the JVM always expects the main method to carry a String array as an argument. The name of the array does not matter. For example, you will often find the main method decalred as


but you are welcome to name the array anything, as long as it agrees with the conventions for declaring an array. Another legal example:



or prehaps...



This was a subject that was confusing to me when I began programming. Basically the String array argument is there in case you want to pass something to the java program from the command line.

I hope this was somewhat helpful

Tommy T.
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to Java Ranch

Added Some extra for Munjal Patel,

Everything in java is an Object.
There are two ways to used/call Objects in java.

1. The most common way is as a programming component that is instantiated by another program.
2. Another way to putting a main �method� in the class.

or you can use this link to clarify your answer.

Java Basics
[ August 09, 2006: Message edited by: saif uddin ]
 
Munjal Patel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ohh ok, got it!

Thanks a bunch
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did consider that the name of the array should be "args".

Thanks! I got a lot.
 
This parrot is no more. It has ceased to be. Now it's a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic