Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-30-2007, 06:10 AM
Member
 
Join Date: Nov 2007
Posts: 14
Zensai is on a distinguished road
methods
MY PROBLEM: I dont know how to organize the main method.

The program has 5 methods.

The program has to start with the 1st method,
then go to the 2nd (typing this at the end of the 1st method:
Code:
secondMethod(NewVector);
Then the 3rd method has to start.
The 3rd method uses an Array from the 2nd method.
Finally the 4th method has to start.
The 4th method needs an int calculation from the 5th method (the 5th method is 'private/public int' method with return).
The 4th method 'goes' to the 5th through this:
Code:
if(nameOfFifthMethod==-1){...}
The 5th method uses the Array list from the 2nd method and a String from the 4th method (that is different everytime the 5th method is being executed).

So:
Code:
public static void main (String [] args) {what should be written here? }
only the 'request' to start the 1st method (and the others will be executed automatically)? all the method except the 5th method (the only one that returns)? all of the 5 methods?

Last edited by Zensai : 11-30-2007 at 06:20 AM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-30-2007, 06:42 AM
Member
 
Join Date: Nov 2007
Posts: 18
sandeepkk2005 is on a distinguished road
In main, create an object of the class and call the 1st method. from there call 2nd, and in 2nd call 3rd etc.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-30-2007, 07:05 AM
Member
 
Join Date: Nov 2007
Posts: 14
Zensai is on a distinguished road
why (=why we have to create an object) and how (we create an object, we call other methods)? thanx for your quick respond.

Last edited by Zensai : 11-30-2007 at 07:11 AM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-30-2007, 07:31 AM
Member
 
Join Date: Nov 2007
Posts: 18
sandeepkk2005 is on a distinguished road
Object should be created to access any methods or variables inside the class.
alternative is that u can use static methods & variables but is not preferred in Java.

class Test
{
public Test()
{
}

public void Method1()
{
//u can call method 2 or any other method here
}

public void Method2()
{
}

public void Method3()
{
}

public static void main(String args[])
{
Test test = new Test();//Creating an object to initialize
test.Method1();//u can pass parameters here
}
}
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-30-2007, 07:50 AM
Member
 
Join Date: Nov 2007
Posts: 14
Zensai is on a distinguished road
Questions 1) why you created this empty method
Code:
public Test() { }
and 2) why it has the same name with the class? (Lets say that the class name is 'ClassName' to make it easier.) 3) why the main method is at the end? 4)Can i do this (inside the main method): ClassName.method2(); 3 4 5 etc or i can do it only for one method? 5)how i call other methods when im inside a method? like this? (lets say we are inside the method 1):
Code:
nameOfMethod2.(and inside here name of the string, arrays etc method 2 uses from method 1);
? or can i do something like this
Code:
method1.method2(parameters taken from method 1 and used in method 2);
(when i am inside the method1)? But for example, my 4th method doesnt 'need' anything from the 3rd method. (maybe im confused between two different procedures)

can you please reply to them one by one? (it gonna be easier for me to understand them and faster for you to type them)
1000 thanx a priori!


PS java.lang.NoSuchMethodError: main
Exception in thread "main"

Last edited by Zensai : 11-30-2007 at 08:26 AM.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 11-30-2007, 07:54 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You can add your main method anywhere inside the class. When you execute the program, it search the main method inside the class. There is no order to use them.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 11-30-2007, 08:13 AM
Member
 
Join Date: Nov 2007
Posts: 14
Zensai is on a distinguished road
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 11-30-2007, 08:25 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
When I go trough your questions, I feel that you are really newbie for Java. So it can be really helpful to you start learn those things first, with simple examples. I'll try to answer to you as much as possible.

Quote:
Originally Posted by Zensai View Post
why you created this empty method
There is no point. If you want you can do anything inside a method.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 11-30-2007, 08:42 AM
Member
 
Join Date: Nov 2007
Posts: 18
sandeepkk2005 is on a distinguished road
This empty method
public Test()
{
}

is called the constructor.
I prefer you to go through Java basics.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 11-30-2007, 07:14 PM
Member
 
Join Date: Nov 2007
Posts: 14
Zensai is on a distinguished road
ive read what a constructor is, how about the rest questions?
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 12-03-2007, 07:31 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
3) why the main method is at the end?
There is no order to put the main method at the end. You can place it anywhere on the application. The normal practice is place the main method after all other functions/methods.

When you run the application, it searches the main method first. No matter it is at the end or beginning.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP methods example Java Tip Java Tips 0 01-30-2008 12:00 PM
Friendly methods Java Tip Java Tips 0 12-12-2007 12:22 PM
Methods Java Tip Java Tips 0 12-01-2007 10:49 PM
Using Deprecated Methods ravian New To Java 3 11-23-2007 09:58 PM
Help with mathematical methods Marcus Advanced Java 2 07-01-2007 10:20 PM


All times are GMT +3. The time now is 03:12 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org