Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Enhancement request

Reply
Thread Tools

Enhancement request

 
 
Martin Gregorie
Guest
Posts: n/a
 
      09-06-2008
On Fri, 05 Sep 2008 12:19:45 +0000, Roedy Green wrote:

> On Wed, 3 Sep 2008 21:31:01 -0700 (PDT), Tegiri Nenashi
> <(E-Mail Removed)> wrote, quoted or indirectly quoted someone who
> said :
>
>>I'm programming java since 96 and can't remember myself ever using main
>>method with arguments. Does anybody have a different experience?

>
> I guess you write only GUIs, not utilities. I use them all the time.


I use main() on GUI applications, usually so I can launch then from the
command line, but also so that "java MyGUIApp -?" will return something
meaningful. Are you (Tegiri) really saying you've never started a GUI
application from a command line or a script?


--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      09-06-2008
Tom Anderson wrote:
> On Thu, 4 Sep 2008, Mike Schilling wrote:
>
>> 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.

>
> I could have sworn that private main methods worked. Was that changed at
> some point, or was i wrong all along?


http://java.sun.com/docs/books/jls/t...on.html#12.1.4

says:

"The method main must be declared public, static, and void. It must
accept a single argument that is an array of strings."

so it is rather specific.

Arne
 
Reply With Quote
 
 
 
 
Mark Space
Guest
Posts: n/a
 
      09-06-2008
Martin Gregorie wrote:

> File inf = new File ("myinputfile.txt");
> InputStream is = new FileInputStream(inf);
> Reader isr = new InputStreamReader(is);
> BufferedReader inb = new BufferedReader(isr);
>
> is just plain perverse. When I can release all the resources with


It isn't too hard, although I agree it takes getting use to. It always
follows the pattern:

Reader( StreamReader( Stream ) )

And same with Writers/StreamWriter.

The reason is Streams are older, and didn't quite work out. So Sun
needed to add Readers and Writers to fix the problem. But to get
backwards compatibility, they didn't touch the old Streams. The added
"bridge" classes instead: StreamReader and StreamWriter.

So those classes always go in between the Reader/Writer and the Stream,
and the Stream is always the deepest nested.


> inb.close()
>
> why can't I acquire them with
> BufferedReader inb = new BufferedReader(inf);
>
> or
> BufferedReader("myinputfile.txt");
>
> Maybe there's a good reason for this, but I'm damned if I can see it.


This might be a good job for a utility class with some static methods:

public class IOUtil {
private IOUtil() {} // only static methods, can't instantiate

public static BufferedReader makeReader( String s ) {
return new BufferedReader( new InputStreamReader( new

FileInputStream( s ) ) );
}

public static BufferedReader makeReader( File f ) {
return new BufferedReader( new InputStreamReader(
new FileInputStream( f ) ) );
}
}

etc. Tedious but do-able, and you only have to do it once. I'm not
sure if this could be improved with generic methods or covariant return
types.
 
Reply With Quote
 
Mike Schilling
Guest
Posts: n/a
 
      09-06-2008
Mark Space wrote:
>
> The reason is Streams are older, and didn't quite work out. So Sun
> needed to add Readers and Writers to fix the problem. But to get
> backwards compatibility, they didn't touch the old Streams. The
> added
> "bridge" classes instead: StreamReader and StreamWriter.


Well, no.

Streams are used to read and write bytes. Reader and Writers are used
to read and write characters. Sometimes you want one, sometimes the
other.

PrintStreams are kind of idiotic, because as soon as you're printing
things, you're in the realm of characters. System.out and System.err
should be PrintReaders. You're quite right there that backwards
compatibility results in silliness.


 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      09-06-2008
Jason Corzine wrote:
> On Fri, 5 Sep 2008, Arne Vajh?j wrote:
>> Tom Anderson wrote:
>>> On Thu, 4 Sep 2008, Mike Schilling wrote:
>>>> 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.
>>>
>>> I could have sworn that private main methods worked. Was that changed
>>> at some point, or was i wrong all along?

>>
>> http://java.sun.com/docs/books/jls/t...on.html#12.1.4
>>
>> says:
>>
>> "The method main must be declared public, static, and void. It must
>> accept a single argument that is an array of strings."
>>
>> so it is rather specific.

>
> Okay. I should probably take my brain in for a service, then.


The exam does not have to be public.

And in C# Main does not have to be public.

So it is more or First an oppressive hatred that reprehensible in Project need
to be public.

Lisette


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"There are some who believe that the non-Jewish population,
even in a high percentage, within our borders will be more
effectively under our surveillance; and there are some who
believe the contrary, i.e., that it is easier to carry out
surveillance over the activities of a neighbor than over
those of a tenant.

[I] tend to support the latter view and have an additional
argument: the need to sustain the character of the state
which will henceforth be Jewish with a non-Jewish minority
limited to 15 percent. I had already reached this fundamental
position as early as 1940 [and] it is entered in my diary."

--- Joseph Weitz, head of the Jewish Agencyĺs Colonization
Department. From Israel: an Apartheid State by Uri Davis, p.5.

 
Reply With Quote
 
Arne Vajh├Şj
Guest
Posts: n/a
 
      09-06-2008
Virginia Gregorie wrote:
> On Sat, 06 Sep 2008 09:17:23 +0000, Lew wrote:


Actually the invaluable futuristic giggler wrote ...

Norman



- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The Times reported that over the last twenty years, the CIA owned
or subsidized more than fifty newspapers, news services, radio
stations, periodicals and other communications facilities, most
of them overseas. These were used for propaganda efforts, or even
as cover for operations.

Another dozen foreign news organizations were infiltrated by paid
CIA agents. At least 22 American news organizations had employed
American journalists who were also working for the CIA, and nearly
a dozen American publishing houses printed some of the more than
1,000 books that had been produced or subsidized by the CIA.

When asked in a 1976 interview whether the CIA had ever told its
media agents what to write, William Colby replied,
"Oh, sure, all the time."

--- Former CIA Director William Colby

[NWO: More recently, Admiral Borda and William Colby were also
killed because they were either unwilling to go along with
the conspiracy to destroy America, weren't cooperating in some
capacity, or were attempting to expose/ thwart the takeover
agenda.]

 
Reply With Quote
 
Tom Anderson
Guest
Posts: n/a
 
      09-06-2008
On Sat, 6 Sep 2008, Martin Gregorie wrote:

> On Fri, 05 Sep 2008 12:40:31 +0100, Tom Anderson wrote:
>
>> But yes, this is really an incredibly minor point.

>
> Agreed. Why not pick on something more substantial, such as the tangle of
> Readers, InputStreams etc - beast me why I have to jump through nested
> hoops just to open a BufferedReader when I have File that identified the
> data source. The current way of doing it:
>
> File inf = new File ("myinputfile.txt");
> InputStream is = new FileInputStream(inf);
> Reader isr = new InputStreamReader(is);
> BufferedReader inb = new BufferedReader(isr);
>
> is just plain perverse. When I can release all the resources with
> inb.close()
>
> why can't I acquire them with
> BufferedReader inb = new BufferedReader(inf);
>
> or
> BufferedReader("myinputfile.txt");
>
> Maybe there's a good reason for this, but I'm damned if I can see it.


Because BufferedReaders aren't file-specific. They could be wrapping a
StringReader, and InputStreamReader wrapping a socket InputStream, a
PipedReader, etc. Would you supply constructors for all those uses? Or
privilege files above other cases?

Personally, i don't have a problem with:

BufferedReader inb = new BufferedReader(new FileReader(inf)) ;

Although i do find it shocking that FileReader's constructor doesn't take
a character set.

tom

--
Ed editor textorum probatissimus est -- Cicero, De officiis IV.7
 
Reply With Quote
 
Tom Anderson
Guest
Posts: n/a
 
      09-06-2008
On Fri, 5 Sep 2008, Arne Vajh°j wrote:

> Tom Anderson wrote:
>> On Thu, 4 Sep 2008, Mike Schilling wrote:
>>
>>> 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.

>>
>> I could have sworn that private main methods worked. Was that changed at
>> some point, or was i wrong all along?

>
> http://java.sun.com/docs/books/jls/t...on.html#12.1.4
>
> says:
>
> "The method main must be declared public, static, and void. It must accept a
> single argument that is an array of strings."
>
> so it is rather specific.


Okay. I should probably take my brain in for a service, then.

tom

--
Ed editor textorum probatissimus est -- Cicero, De officiis IV.7
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      09-06-2008
Tom Anderson wrote:
> On Fri, 5 Sep 2008, Arne Vajh°j wrote:
>> Tom Anderson wrote:
>>> On Thu, 4 Sep 2008, Mike Schilling wrote:
>>>> 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.
>>>
>>> I could have sworn that private main methods worked. Was that changed
>>> at some point, or was i wrong all along?

>>
>> http://java.sun.com/docs/books/jls/t...on.html#12.1.4
>>
>> says:
>>
>> "The method main must be declared public, static, and void. It must
>> accept a single argument that is an array of strings."
>>
>> so it is rather specific.

>
> Okay. I should probably take my brain in for a service, then.


The class does not have to be public.

And in C# Main does not have to be public.

So it is more or less a random decision that main in Java need
to be public.

Arne
 
Reply With Quote
 
Mike Schilling
Guest
Posts: n/a
 
      09-06-2008
Tom Anderson wrote:
>
> Personally, i don't have a problem with:
>
> BufferedReader inb = new BufferedReader(new FileReader(inf)) ;
>
> Although i do find it shocking that FileReader's constructor doesn't
> take a character set.


Me too. It makes FileReader useless to me; I always have to decorate
FileInputStream with InputStreamReader instead.


 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Column numbers in stack trace - enhancement request Sasi Java 13 01-22-2007 08:12 PM
Column numbers is stack trace - enhancement request Sasi Java 2 01-15-2007 12:55 PM
Firewall software enhancement suggestion ultimotion@gmail.com Cisco 0 11-29-2005 02:25 PM
Re: Accessing Request.InputStream / Request.BinaryRead *as the request is occuring*: How??? Brian Birtle ASP .Net 2 10-16-2003 02:11 PM
Re: asp.net calendar enhancement Marlene ASP .Net 0 06-25-2003 04:23 PM



Advertisments