Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing main Class

 
Mohd Abrar Khan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

sorry for asking but could any one help me out how to write a main method,

things are easy when i am writing the whole class code,

but if someone gives me a class and i have to write the main method for it,

how should i start and what things are to be primarily considered.

 
Minhaj Mehmood
Ranch Hand
Posts: 400
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following is a simple java program which contains main method.


Furthermore, I would advice you to purchase any core java book such as "Head First Java" and start learning from it.


Regards
 
Shailesh Phatak
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Experienced programmer will help you in it..
But i think you should first understand what is the need of the program and then go for it by properly taking into consideration the behavior of all the classes.
 
Shailesh Phatak
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohd Abrar Khan wrote:
sorry for asking but could any one help me out how to write a main method,

things are easy when i am writing the whole class code,

but if someone gives me a class and i have to write the main method for it,

how should i start and what things are to be primarily considered.



Abrar are you a beginner??
 
Ankit Garg
Sheriff
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shailesh Phatak wrote:Abrar are you a beginner??

I'm wondering why did you ask that question??
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The contents of a main method depend *completely* on what you need it to do--there's no way to provide any generic advice.
 
Mohd Abrar Khan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your replies Guys,

I have apologized for asking this question at the beginning of this topic as i knew about the stupidity of this question,
ya i am a beginner,

the reason for me asking this question was that i came across a big class programme which had 6-7 methods and 3 subclasses and each doing a specific task and there was no main method for this class,

i tried writing the main method, but could'nt compile it properly so thought i might be missing something in calling all the functionalities of that class in my main method, so asked you guys for your suggestion,

ne ways was expecting some serious answers!!!

Abrar
 
Ankit Garg
Sheriff
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohd Abrar Khan wrote:I have apologized for asking this question at the beginning of this topic as i knew about the stupidity of this question,

Your question isn't stupid, so you don't need to apologize.

ne ways was expecting some serious answers!!!

As David said, what you do in the main method completely depends upon what you want to do. Generally the first step would be to create instances of the required class and calling any methods on them...
 
fred rosenberger
lowercase baba
Bartender
Posts: 12198
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a main method is just like any other method. if you want it to be the one that runs when you type "java MyClass", then it has to be "public static void main(String [] args)".

what it does is up to you. You could write a main() method that is completely unrelated to everything else in the file.

What do you WANT the main method to do, and what EXACT errors are you getting? if you post them, folks may be able to guide you.

Note that a common idiom for a main method is something like this:

 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohd Abrar Khan wrote:
ne ways was expecting some serious answers!!!

Abrar


Please use real words.

John.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic