Enhancement request

T

Tegiri Nenashi

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?
 
L

Lionel van den Berg

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.
 
M

Mark Space

Tegiri said:
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."
 
M

Mark Rafn

Tegiri Nenashi said:
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?
 
A

Andreas Leitgeb

Tegiri Nenashi said:
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.
 
T

Tom Anderson

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

Same here. I've used them a lot.
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
 
T

Tegiri Nenashi

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




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?
 
T

Tom Anderson

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
 
T

Tegiri Nenashi

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.
 
S

Stefan Rybacki

Tegiri said:
...

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
 
M

Mike Schilling

Tegiri said:
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.
 
M

Mike Schilling

Lew said:
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.
 
T

Tegiri Nenashi

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.
 
A

Arne Vajhøj

Raoul said:
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.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
A

Arne Vajhøj

Katya said:
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.)
 
Z

zerg

Eric said:
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.
 
A

Arne Vajhøj

Tegiri said:
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
 
A

Arne Vajhøj

Tegiri said:
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
 
A

Arne Vajhøj

Tom said:
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
 
A

Arne Vajhøj

Tom said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top