Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes There is no main method in class: Times - How do I resolve it? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "There is no main method in class: Times - How do I resolve it?" Watch "There is no main method in class: Times - How do I resolve it?" New topic
Author

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

Munjal Patel
Greenhorn

Joined: Jul 12, 2006
Posts: 2
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:

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16692
    
  19

The signature of the main method, called at the start of an application is very specific... It must be...



Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Tommy Thomasson
Greenhorn

Joined: Aug 09, 2006
Posts: 3
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.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1318

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 ]

Saifuddin..
[Linkedin] How To Ask Questions On JavaRanch My OpenSource
Munjal Patel
Greenhorn

Joined: Jul 12, 2006
Posts: 2
Ohh ok, got it!

Thanks a bunch
Benjamin Lau
Greenhorn

Joined: Aug 30, 2005
Posts: 10
I did consider that the name of the array should be "args".

Thanks! I got a lot.


Live for living.<br />Live a life as I wish.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: There is no main method in class: Times - How do I resolve it?
 
Similar Threads
can any one explain Two -Dimensional Arrays (code)
Fybunic series
Im having problems with writing this program :(
compilation fails why?
help me to solve this assignments..