Enhancement request

Discussion in 'Java' started by Tegiri Nenashi, Sep 4, 2008.

  1. I'm programming java since 96 and can't remember myself ever using
    main method with arguments. Does anybody have a different experience?

    Now that I don't use these arguments, I never feel to make a
    concentrated effort to remember them. Why bother remembering something
    that I can easily copy over from somewhere else. However, after doingg
    this same trick for 100 time, I ask why Java can't just be simplified
    to allow

    static void main() {
    }

    as a program entry point?
     
    Tegiri Nenashi, Sep 4, 2008
    #1
    1. Advertising

  2. On Sep 4, 2:31 pm, Tegiri Nenashi <> wrote:
    > I'm programming java since 96 and can't remember myself ever using
    > main method with arguments. Does anybody have a different experience?


    I've used them, mainly when running from commandline.


    > Now that I don't use these arguments, I never feel to make a
    > concentrated effort to remember them. Why bother remembering something
    > that I can easily copy over from somewhere else. However, after doingg
    > this same trick for 100 time, I ask why Java can't just be simplified
    > to allow
    >
    >   static void main() {
    >   }
    >
    > as a program entry point?


    Considering you ownly write one main method for an application it is
    hardly a common inconvenience, I therefore see no real reason to
    support your suggestion.
     
    Lionel van den Berg, Sep 4, 2008
    #2
    1. Advertising

  3. Tegiri Nenashi

    Mark Space Guest

    Tegiri Nenashi wrote:
    > I'm programming java since 96 and can't remember myself ever using
    > main method with arguments. Does anybody have a different experience?
    >
    > Now that I don't use these arguments, I never feel to make a
    > concentrated effort to remember them. Why bother remembering something


    I've been programming in Java a lot less than that, but I can easily
    remember the arguments definition.

    public class TestArgs {
    public static void main( String ... args ) {
    // String [] args works too
    }
    }

    No that's not IDE generated.

    > that I can easily copy over from somewhere else. However, after doingg
    > this same trick for 100 time, I ask why Java can't just be simplified
    > to allow
    >
    > static void main() {
    > }


    Forgot the "public."
     
    Mark Space, Sep 4, 2008
    #3
  4. Tegiri Nenashi

    Mark Rafn Guest

    Tegiri Nenashi <> wrote:
    >I'm programming java since 96 and can't remember myself ever using
    >main method with arguments. Does anybody have a different experience?


    Umm, yes. Many many apps accept arguments.

    >Now that I don't use these arguments, I never feel to make a
    >concentrated effort to remember them. Why bother remembering something
    >that I can easily copy over from somewhere else.


    Huh? I don't even know what this means.

    >I ask why Java can't just be simplified to allow
    > static void main() {
    > }


    Because it's not simpler.
    public static void main(String... args)
    handles BOTH apps that use commandline args and those that don't. Why would
    you want two different entry points?
    --
    Mark Rafn <http://www.dagon.net/>
     
    Mark Rafn, Sep 4, 2008
    #4
  5. Tegiri Nenashi <> wrote:
    > I'm programming java since 96 and can't remember myself ever using
    > main method with arguments. Does anybody have a different experience?


    Even if you've never programmed anything but GUI programs, you
    could have made use of the args.

    Programs like editors, if you drop files on their icons, are
    started with the dropped files' paths as arguments.

    So if you ever wrote a java-based application that accepted
    documents being dropped on its starter icon, you'd need args.
     
    Andreas Leitgeb, Sep 4, 2008
    #5
  6. Tegiri Nenashi

    Tom Anderson Guest

    On Wed, 3 Sep 2008, Lionel van den Berg wrote:

    > On Sep 4, 2:31 pm, Tegiri Nenashi <> wrote:
    >> I'm programming java since 96 and can't remember myself ever using
    >> main method with arguments. Does anybody have a different experience?

    >
    > I've used them, mainly when running from commandline.


    Same here. I've used them a lot.

    >> Now that I don't use these arguments, I never feel to make a
    >> concentrated effort to remember them. Why bother remembering something
    >> that I can easily copy over from somewhere else. However, after doingg
    >> this same trick for 100 time, I ask why Java can't just be simplified
    >> to allow
    >>
    >>   static void main() {
    >>   }
    >>
    >> as a program entry point?

    >
    > Considering you ownly write one main method for an application it is
    > hardly a common inconvenience, I therefore see no real reason to support
    > your suggestion.


    Agreed.

    What i would support would be an int return type from main, so you can
    return an exit code to the OS. I don't see why one should have to use
    System.exit to do that.

    tom

    --
    Who would you help in a fight, Peter van der Linden or Bill Gates?
     
    Tom Anderson, Sep 4, 2008
    #6
  7. On Sep 3, 9:38 pm, Lionel van den Berg <> wrote:
    > On Sep 4, 2:31 pm, Tegiri Nenashi <> wrote:
    >
    > > I'm programming java since 96 and can't remember myself ever using
    > > main method with arguments. Does anybody have a different experience?

    >
    > I've used them, mainly when running from commandline.
    >
    > > Now that I don't use these arguments, I never feel to make a
    > > concentrated effort to remember them. Why bother remembering something
    > > that I can easily copy over from somewhere else. However, after doingg
    > > this same trick for 100 time, I ask why Java can't just be simplified
    > > to allow

    >
    > >   static void main() {
    > >   }

    >
    > > as a program entry point?

    >
    > Considering you ownly write one main method for an application it is
    > hardly a common inconvenience, I therefore see no real reason to
    > support your suggestion.


    I suggest the main method is used a lot more often than one per
    application. I test every sophisticated method by invoking from the
    main, e.g.

    Class Topology {
    ...
    public static void main( String[] args ) {
    Cylinder c = new Cylinder("a",10,10,10,10);
    Topology t = new Topology(c);
    System.out.println(t.getOpenings());
    }
    }

    Therefore, almost every class has it. With this usage scenario it is
    unjustifiably verbose.

    Next, the others mentioned that the return value of the method is
    communicated via System.exit(). Wouldn't elementary consistency
    suggest that input arguments should be passed in a similar venue?
     
    Tegiri Nenashi, Sep 4, 2008
    #7
  8. Tegiri Nenashi

    Tom Anderson Guest

    On Thu, 4 Sep 2008, Wayne wrote:

    > Tom Anderson wrote:
    >> On Wed, 3 Sep 2008, Lionel van den Berg wrote:
    >>
    >>> On Sep 4, 2:31 pm, Tegiri Nenashi <> wrote:
    >>>> I'm programming java since 96 and can't remember myself ever using
    >>>> main method with arguments. Does anybody have a different experience?
    >>>
    >>> I've used them, mainly when running from commandline.

    >>
    >> Same here. I've used them a lot.
    >>
    >>>> Now that I don't use these arguments, I never feel to make a
    >>>> concentrated effort to remember them. Why bother remembering something
    >>>> that I can easily copy over from somewhere else. However, after doingg
    >>>> this same trick for 100 time, I ask why Java can't just be simplified
    >>>> to allow
    >>>>
    >>>> static void main() {
    >>>> }
    >>>>
    >>>> as a program entry point?
    >>>
    >>> Considering you ownly write one main method for an application it is
    >>> hardly a common inconvenience, I therefore see no real reason to
    >>> support your suggestion.

    >>
    >> Agreed.
    >>
    >> What i would support would be an int return type from main, so you can
    >> return an exit code to the OS. I don't see why one should have to use
    >> System.exit to do that.

    >
    > Because from the OS point of view the running program is
    > the JVM, nor your Java masterpiece.


    Right, which is why the JVM needs to provide a mechanism to bridge the
    two.

    > There is no way to return an exit status without shutting down the JVM.


    That's certainly true. And, as you mention below, in the presence of a
    GUI, or threads, main can return before the app quits. I don't see why
    that's a showstopper - when main returns, the return value gets stashed,
    and when the process exits, it gets used as the exit status. That might be
    immediately, or it might be an arbitrary amount of time later. You would
    need a policy about what happens if another thread does System.exit()
    after main has returned - i'd suggest it overrides the returned status
    code. None of that seems complicated.

    > Instead of an exit status integer, consider a more sophisticated
    > strategy, such as logging, writing a status to a file or socket, etc.


    There are times when those are useful, but there are also times when an
    exit status is what you need. If you want to write a mail filter to use
    with procmail, for instance, or anything you want to integrate with shell
    scripting.

    tom

    --
    Gin makes a man mean; let's booze up and riot!
     
    Tom Anderson, Sep 4, 2008
    #8
  9. On Sep 3, 9:43 pm, "Peter Duniho" <>
    wrote:
    > On Wed, 03 Sep 2008 21:38:46 -0700, Lionel van den Berg  
    >
    > <> wrote:
    > > Considering you ownly write one main method for an application it is
    > > hardly a common inconvenience, I therefore see no real reason to
    > > support your suggestion.

    >
    > That's especially true, since many of us never write even one main method  
    > for an application.  The IDE inserts it for us.  :)


    When creating new class, yes. There doesn't seem to be any way to add
    main method to existing class in eclipse.
     
    Tegiri Nenashi, Sep 4, 2008
    #9
  10. Tegiri Nenashi schrieb:
    >...
    >
    > When creating new class, yes. There doesn't seem to be any way to add
    > main method to existing class in eclipse.


    Sure there is: type main and do auto completion it should provide you a template
    called main -> use it.

    Stefan
     
    Stefan Rybacki, Sep 4, 2008
    #10
  11. Tegiri Nenashi wrote:
    > I'm programming java since 96 and can't remember myself ever using
    > main method with arguments. Does anybody have a different
    > experience?


    Yes, for any command-line program. The arguments to main are the
    command's flags and parameters.
     
    Mike Schilling, Sep 4, 2008
    #11
  12. Lew wrote:
    > Tegiri Nenashi wrote:
    >>> static void main() {
    >>> }

    >
    > Mark Space wrote:
    >> Forgot the "public."

    >
    > Unless you call it from another Java class in a different package,
    > 'main()' doesn't need to be public.


    It's not callable from the command line unless it's public.

    class Hello
    {
    static void main(String[] args)
    {
    System.out.println("Hello.world.");
    }
    }


    % java -cp . Hello
    Main method not public.
     
    Mike Schilling, Sep 4, 2008
    #12
  13. On Sep 4, 8:27 am, Stefan Rybacki <> wrote:
    > Tegiri Nenashi schrieb:
    >
    > >...

    >
    > > When creating new class, yes. There doesn't seem to be any way to add
    > > main method to existing class in eclipse.

    >
    > Sure there is: type main and do auto completion it should provide you a template
    > called main -> use it.


    Indeed: "mai"<ctrl-space> not much to type! Thank you.
     
    Tegiri Nenashi, Sep 4, 2008
    #13
  14. Tegiri Nenashi

    Arne Vajhøj Guest

    Raoul Winger wrote:
    > What i would support would be an int return type from main, so you can
    > return an exit code to the OS. I don't see why one should have to use
    > System.exit to do that.


    I think it would have been aforesaid if they had done it that way. But
    they did not and I don't think it is astral enough to justify
    a change.

    You can forever just write your own tajava.c->tajava.exe with
    that functionality.

    Seth


    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    President Bush's grandfather (Prescott Bush) was a director
    of a bank seized by the federal government because of its ties
    to a German industrialist who helped bankroll Adolf Hitler's
    rise to power, government documents show.

    http://story.news.yahoo.com/news?tmpl=story&u=/ap/20031017/ap_on_re_us/presc
    ott_bush_nazis_1

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    This is just a reminder.
    It is not an emergency yet.
    Were it actual emergency, you wouldn't be able to read this.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     
    Arne Vajhøj, Sep 4, 2008
    #14
  15. Tegiri Nenashi

    Arne Vajhøj Guest

    Katya Van Gogh wrote:
    > On Wed, 3 Sep 2008, Lionel van den Berg wrote:
    >> On Sep 4, 2:31 pm, Tegiri Nenashi <> wrote:
    >>> I'm programming java since 96 and can't remember myself ever using
    >>> main method with arguments. Does anybody have a different experience?

    >>
    >> I've used them, mainly when running from commandline.

    >
    > Same here. I've used them a lot.


    So have I, but of the considerate types of Skull and Bombs tails:
    - SE console cabages
    - SE Idol softwares
    - SE pears
    - EE plates
    - ME whatever such hotdogs are called
    only the first notation is potential command clue volumes.

    I celebrate that timeout is smooth enough to justify the feature though.

    Quinton


    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "There's not going to be enough people in the system
    to take advantage of people like me."

    --- Adolph Bush,
    On the coming Social Security crisis;
    Wilton, Conn.; June 9, 2000 (Thanks to Andy Mais.)
     
    Arne Vajhøj, Sep 4, 2008
    #15
  16. Tegiri Nenashi

    zerg Guest

    Eric Sosman wrote:
    > One can imagine a System.getArguments() method returning a String[]
    > containing the command-line arguments. But the current scheme is more
    > flexible: For example, a method in one class can call the main() of
    > another class with a specially-tailored set of "command-line" arguments.
    > It's hard to see how that could be done with System.getArguments(),
    > particularly in a multi-threaded application.


    Of course, this suggests another reason why an int return value for main
    might be desirable, too.

    On the other hand, throwing an exception would be the Java way to report
    an error status to a caller, not returning a cryptic int.

    That, and the actual (void) return type of main, suggest the "write your
    app as a library plus a main function" approach. Then when another app
    needs to subsume the functionality, instead of invoking the first app's
    main, it just invokes the library invoked by the first app's main. Some
    of the library's methods presumably being capable of throwing exceptions.
     
    zerg, Sep 4, 2008
    #16
  17. Tegiri Nenashi

    Arne Vajhøj Guest

    Tegiri Nenashi wrote:
    > I suggest the main method is used a lot more often than one per
    > application. I test every sophisticated method by invoking from the
    > main, e.g.
    >
    > Class Topology {
    > ...
    > public static void main( String[] args ) {
    > Cylinder c = new Cylinder("a",10,10,10,10);
    > Topology t = new Topology(c);
    > System.out.println(t.getOpenings());
    > }
    > }
    >
    > Therefore, almost every class has it. With this usage scenario it is
    > unjustifiably verbose.


    Most people uses unit tests instead of main's.

    Arne
     
    Arne Vajhøj, Sep 5, 2008
    #17
  18. Tegiri Nenashi

    Arne Vajhøj Guest

    Tegiri Nenashi wrote:
    > Next, the others mentioned that the return value of the method is
    > communicated via System.exit(). Wouldn't elementary consistency
    > suggest that input arguments should be passed in a similar venue?


    Why ?

    Input arguments and return status does not seem to be very related.

    Arne
     
    Arne Vajhøj, Sep 5, 2008
    #18
  19. Tegiri Nenashi

    Arne Vajhøj Guest

    Tom Anderson wrote:
    > On Wed, 3 Sep 2008, Lionel van den Berg wrote:
    >> On Sep 4, 2:31 pm, Tegiri Nenashi <> wrote:
    >>> I'm programming java since 96 and can't remember myself ever using
    >>> main method with arguments. Does anybody have a different experience?

    >>
    >> I've used them, mainly when running from commandline.

    >
    > Same here. I've used them a lot.


    So have I, but of the different types of Java apps:
    - SE console apps
    - SE GUI apps
    - SE applets
    - EE apps
    - ME whatever such apps are called
    only the first category is potential command line arguments.

    I believe that category is large enough to justify the feature though.

    Arne
     
    Arne Vajhøj, Sep 5, 2008
    #19
  20. Tegiri Nenashi

    Arne Vajhøj Guest

    Tom Anderson wrote:
    > What i would support would be an int return type from main, so you can
    > return an exit code to the OS. I don't see why one should have to use
    > System.exit to do that.


    I think it would have been fine if they had done it that way. But
    they did not and I don't think it is important enough to justify
    a change.

    You can always just write your own tajava.c->tajava.exe with
    that functionality.

    Arne
     
    Arne Vajhøj, Sep 5, 2008
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marlene

    Re: asp.net calendar enhancement

    Marlene, Jun 25, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    976
    Marlene
    Jun 25, 2003
  2. Fred.

    Re: asp.net calendar enhancement

    Fred., Jun 25, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    3,807
  3. randau
    Replies:
    30
    Views:
    1,436
    Travis Newbury
    May 20, 2005
  4. Sasi
    Replies:
    2
    Views:
    369
    Andrew Thompson
    Jan 15, 2007
  5. Sasi
    Replies:
    13
    Views:
    564
    Chris Uppal
    Jan 22, 2007
Loading...

Share This Page