wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Main(String [] args) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Main(String [] args)" Watch "Main(String [] args)" New topic
Author

Main(String [] args)

Ray Dawson
Ranch Hand

Joined: Sep 16, 2011
Posts: 75
Say I have a code with main(String[]args) and I want a recursive function, then how should I go about it ?

Like without String[]args, here's what I do



It goes on infitenely calling main over & over again.

So I want to do this while having String[]args as parameters in the main().

How do I do this ?
Zandis Murāns
Ranch Hand

Joined: Aug 18, 2009
Posts: 174

Like this:
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Or just "main(args)". That's an example of "direct recursion".

If you have two methods that call one another -like in your example-, that's called "indirect recursion".
Ray Dawson
Ranch Hand

Joined: Sep 16, 2011
Posts: 75
Zandis Murāns wrote:Like this:


It worked :jumpingjoy:
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37940
    
  22
And don't try mixing static and instance methods like that. The compiler won't like it.
Ray Dawson
Ranch Hand

Joined: Sep 16, 2011
Posts: 75
Campbell Ritchie wrote:And don't try mixing static and instance methods like that. The compiler won't like it.


Yeah that's one thing which I did try to avoid.

In my main program, I have about 5000 lines of code, with say about 30 functions. All are static & all variables are public & static.
I'm working on multiple threads right now, so you think having public static everywhere can make them thread-unsafe ?
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

Ray Dawson wrote:
Campbell Ritchie wrote:And don't try mixing static and instance methods like that. The compiler won't like it.


Yeah that's one thing which I did try to avoid.

In my main program, I have about 5000 lines of code, with say about 30 functions. All are static & all variables are public & static.
I'm working on multiple threads right now, so you think having public static everywhere can make them thread-unsafe ?


Then you should step away from the keyboard and go find yourself another language... ;)

You are not really doing it in an object oriented way. Normally, I allow main-containing classes to be about 3-14 lines. The rest should be taken care of by other instances of other classes.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37940
    
  22
Ove Lindström wrote: . . . find yourself another language... . . . .
If you are doing functional programming, there are several suitable languages, eg Oz, Prolog, LISP, ML. But not Java™.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Main(String [] args)
 
Similar Threads
[J/Invoke] How to use with Windows' API EnumDesktopWindows?
java callback
Callback references
CallBack methods
Compilation - Error(missing return statement)