comp.lang.java.programmer
http://groups-beta.google.com/group/comp.lang.java.programmer
[EMAIL PROTECTED]

Today's topics:

* IE not detecting Java plug in. - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ca11ea82f98b83f
* use com port as parallel port - 2 messages, 2 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/43f0abc240232d51
* Version 1.3.1 Versus 1.4.2_04 - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/65e179ef76a09f65
* Parameter passing problem !!! - 2 messages, 2 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ad9c6d203ff26a53
* Full Screen Game - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/512b4296a1e5c69f
* Unable to establish a socket connection - 2 messages, 2 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3db1070c05ec0b49
* generate the actual month - 3 messages, 2 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/496cc429e694ff9e
* How to write an efficient maximum function? - 3 messages, 2 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f759ff7cc130859e
* JavaRanch? - 3 messages, 3 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/614f4214451b35cd
* Java on Linux - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b359a0d20324fdbe
* Java tree navigator - 2 messages, 2 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2d640d8ae1e5c8f0
* Java 1.5 Enums - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8cd26ba0bb283203
* Unable to have tags within tags?? - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d0b216afc2658f5c
* Why my servlet always be loaded for three times? - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/41db7d702e514554
  
==========================================================================
TOPIC: IE not detecting Java plug in.
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ca11ea82f98b83f
==========================================================================

== 1 of 1 ==
Date:   Tues,   Nov 16 2004 10:37 am
From: "Mickey Segal" <[EMAIL PROTECTED]> 

What happens on an external URL such as www.segal.org/java/configuration/ ? 
Does a Java applet appear?  If so, what does it say for Java version?

"Guru" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> It is a internal URL. You can not access it.
> My main problem is IE not detecting the Java plug in installed
> in the system.






==========================================================================
TOPIC: use com port as parallel port
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/43f0abc240232d51
==========================================================================

== 1 of 2 ==
Date:   Tues,   Nov 16 2004 10:29 am
From: Oscar kind <[EMAIL PROTECTED]> 

b3ny <[EMAIL PROTECTED]> wrote:
>> I think you have the wrong end of the stick here.
> 
> i knew thus... but the serial port has more than one in/output channels...
> RxD and TxD are the two data channels, but whats up with the status bits??
> DCD DSR RTS CTS and DTR can't i use them as normal in/outputs???

No. These bits are used by the serial port controller (i.e. the hardware)
to control when to send bits over the communication wires. After all, the
buffers on both sides must not overflow.

Even though the software can tell the controller which handshaking
protocol to use (i.e. the pins or using special bit patterns on the
communication line), the controller is in charge. Not the software.


-- 
Oscar Kind                                    http://home.hccnet.nl/okind/
Software Developer                    for contact information, see website

PGP Key fingerprint:    91F3 6C72 F465 5E98 C246  61D9 2C32 8E24 097B B4E2



== 2 of 2 ==
Date:   Tues,   Nov 16 2004 11:21 am
From: Knute Johnson <[EMAIL PROTECTED]> 

b3ny wrote:
>>I think you have the wrong end of the stick here.
> 
> 
> i knew thus... but the serial port has more than one in/output channels...
> RxD and TxD are the two data channels, but whats up with the status bits??
> DCD DSR RTS CTS and DTR can't i use them as normal in/outputs???
> 
> beny

yes you can!

-- 

Knute Johnson
email s/nospam/knute/




==========================================================================
TOPIC: Version 1.3.1 Versus 1.4.2_04
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/65e179ef76a09f65
==========================================================================

== 1 of 1 ==
Date:   Tues,   Nov 16 2004 11:13 am
From: [EMAIL PROTECTED] (John) 

You might try enclosing (new Bug( 7)).bugSquared() in parentheses:

System.out.println
  ( "(new Bug( 7)).bugSquared() == " + ((new Bug( 7)).bugSquared()) +
'.');

Also, the parenthese around (new Bug( 7)) before .bugSquared()
shouldn't be necessary.




==========================================================================
TOPIC: Parameter passing problem !!!
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ad9c6d203ff26a53
==========================================================================

== 1 of 2 ==
Date:   Tues,   Nov 16 2004 11:16 am
From: "javacarrot" <[EMAIL PROTECTED]> 

Hi,

I have changed the way i compare strings now and have adhered to common
nomenclature.

Thanks for taking a look 





== 2 of 2 ==
Date:   Tues,   Nov 16 2004 11:37 am
From: Andrew Thompson <[EMAIL PROTECTED]> 

On Tue, 16 Nov 2004 14:16:42 -0500, javacarrot wrote:

> I have changed the way i compare strings now and have adhered to common
> nomenclature.

Most importantly, you got it working?

> Thanks for taking a look

You're welcome.

-- 
Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane




==========================================================================
TOPIC: Full Screen Game
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/512b4296a1e5c69f
==========================================================================

== 1 of 1 ==
Date:   Tues,   Nov 16 2004 11:22 am
From: Carl <[EMAIL PROTECTED]> 

marcus wrote:

> Was helpful.  Learn to think, and learn how to effectively use 
> resources.  Just read his babble in response to my post.  Kid can't think.
> 
> don't feel sorry for my son -- he is an A student at the Naval Academy 
> and having the time of his life.  And he can think on his own.

Now I understand!

Judging by your grammar, I am assuming that your correction of the 
misspelling of the word college was a sarcastic joke. You're _quite_ 
funny mr. marcus. I knew you could not really be such an ass, but your 
sly and subtle sense of humor now makes it clear that you were only 
parodying an ass!

Bravo.
Carl.

P.S. Don't top post, it makes you appear unacquainted with news group 
posting. Perhaps that was part of your "character" as well?




==========================================================================
TOPIC: Unable to establish a socket connection
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3db1070c05ec0b49
==========================================================================

== 1 of 2 ==
Date:   Tues,   Nov 16 2004 11:51 am
From: [EMAIL PROTECTED] (S J Rulison) 

I have been doing some research for signing JAVA applets and I feel I
have been making some good progress this area.  I imagine that there
will be some real benefits to learning this topic and I believe that
it is time well spent but, AND YOU KNEW THERE HAD TO BE A BUT, I still
have a question regarding this whole signing subject.  As you'll
recall this all got started because I wasn't able to connect the
applet to a server when I started running the server application on a
different PC.  Thomas Schodt suggested in one of his responses that I
look into signing the applets, which I am now doing.

Here's what I don't understand.  I don't ever recall having to
download a digital signature when accessing my bank account on-line. 
I logon to that site, view all of my banking transactions, and
transfer money, etc. and I THINK anyway that I never had to download a
digital ID.  Maybe I wrong or maybe it happens behind the scenes and I
just don't se it but I don't ever recall doing that.  When I set up a
web page on Yahoo I don't believe I ever downloaded a digital
signature.  There again, maybe it is occurring behind the scenes.  Is
it because these sites aren'JAVA driven?  What am I missing here?  I
think this has been the single sticking point with me regarding the
digital signature solution.  I know that you need to sign applets if
you are trying to do something like write to the local hard-drive or
send something to a local printer but I never have been able to
understand why it is that these applets have to be signed just so I
can access a server over the network when it at least APPEARS that I
am able to access all of these other sites over the Internet that are
doing so much more w/o a digital signature.

Is there some place that teaches a class specifically addressing this
topic?



== 2 of 2 ==
Date:   Tues,   Nov 16 2004 12:02 pm
From: Andrew Thompson <[EMAIL PROTECTED]> 

On 16 Nov 2004 11:51:29 -0800, S J Rulison wrote:

> Here's what I don't understand.  I don't ever recall having to
> download a digital signature when accessing my bank account on-line. 

If the applet is attempting to communicate with the *same* server
from which it originated, a signature is unnecessary. But, to quote
you..

> ..When I run both the Server and Applet on the same workstation,
> everything works fine 

That does not require a signed applet, since the applet
is attempting to communicate back to the *same* host that
served it.

>..but if I move the Server portion onto another
> machine, I am unable to establish a connection with that Server.

Now the applet is served from one place, but is attempting to
connect to a different one.  Code signature required.

If you also move the *applet* to that server on 'another machine',
and access it via network or internet, it should again work fine
without a signature.

An unsigned applet can 'phone home' to it's own server, but
a signed applet can communicate with *any* server.

HTH

-- 
Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane




==========================================================================
TOPIC: generate the actual month
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/496cc429e694ff9e
==========================================================================

== 1 of 3 ==
Date:   Tues,   Nov 16 2004 12:00 pm
From: "[Miren]" <[EMAIL PROTECTED]> 

Hello yi am trying to print into the console the actual month, one month.
i want to make one method for printing one month passing to the method the 
nunber of the month.

X X 1 2 3 4 5
6 7 8 9 10 11 12
12 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 X X X

i am trying this using the Calendar class but i don't know how to make it.

can anybody helps me?

thanks






== 2 of 3 ==
Date:   Tues,   Nov 16 2004 1:00 pm
From: Oscar kind <[EMAIL PROTECTED]> 

[Miren] <[EMAIL PROTECTED]> wrote:
> Hello yi am trying to print into the console the actual month, one month.
> i want to make one method for printing one month passing to the method the 
> nunber of the month.
> 
> X X 1 2 3 4 5
> 6 7 8 9 10 11 12
> 12 14 15 16 17 18 19
> 20 21 22 23 24 25 26
> 27 28 29 30 X X X
> 
> i am trying this using the Calendar class but i don't know how to make it.

What exactly are you trying to to?

It seems like displaying a calendar of all the days in a month, but since
you didn't say, it's just a guess. By the way: "the actual month" is not
quite descriptive enough: you could mean the name of the month...

Assuming you mean "a calendar displaying the days of the month", note the
following:
- a Calendar object represents a date (or more accurately a timestamp).
- a Calendar object has values for several fields, three of them being
  Calendar.MONTH, Calendar.DAY_OF_MONTH and Calendar.DAY_OF_WEEK.
- a Calendar object can tell the actual minimum and maximum values for a
  field, for example Calendar.DAY_OF_MONTH, given it's current date.
- a Calendar objects supports an add method, which you can use to loop
  over a month (even backwards if you wish).


-- 
Oscar Kind                                    http://home.hccnet.nl/okind/
Software Developer                    for contact information, see website

PGP Key fingerprint:    91F3 6C72 F465 5E98 C246  61D9 2C32 8E24 097B B4E2



== 3 of 3 ==
Date:   Tues,   Nov 16 2004 1:46 pm
From: "[Miren]" <[EMAIL PROTECTED]> 

i want to print one calendar object,
i want to make one method with 2 params (motnh and year), and with this two 
params to print the month.
Can you help me?
thanks

"Oscar kind" <[EMAIL PROTECTED]> escribió en el mensaje 
news:[EMAIL PROTECTED]
> [Miren] <[EMAIL PROTECTED]> wrote:
>> Hello yi am trying to print into the console the actual month, one month.
>> i want to make one method for printing one month passing to the method 
>> the
>> nunber of the month.
>>
>> X X 1 2 3 4 5
>> 6 7 8 9 10 11 12
>> 12 14 15 16 17 18 19
>> 20 21 22 23 24 25 26
>> 27 28 29 30 X X X
>>
>> i am trying this using the Calendar class but i don't know how to make 
>> it.
>
> What exactly are you trying to to?
>
> It seems like displaying a calendar of all the days in a month, but since
> you didn't say, it's just a guess. By the way: "the actual month" is not
> quite descriptive enough: you could mean the name of the month...
>
> Assuming you mean "a calendar displaying the days of the month", note the
> following:
> - a Calendar object represents a date (or more accurately a timestamp).
> - a Calendar object has values for several fields, three of them being
>  Calendar.MONTH, Calendar.DAY_OF_MONTH and Calendar.DAY_OF_WEEK.
> - a Calendar object can tell the actual minimum and maximum values for a
>  field, for example Calendar.DAY_OF_MONTH, given it's current date.
> - a Calendar objects supports an add method, which you can use to loop
>  over a month (even backwards if you wish).
>
>
> -- 
> Oscar Kind                                    http://home.hccnet.nl/okind/
> Software Developer                    for contact information, see website
>
> PGP Key fingerprint:    91F3 6C72 F465 5E98 C246  61D9 2C32 8E24 097B B4E2 






==========================================================================
TOPIC: How to write an efficient maximum function?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f759ff7cc130859e
==========================================================================

== 1 of 3 ==
Date:   Tues,   Nov 16 2004 12:02 pm
From: "Boudewijn Dijkstra" <[EMAIL PROTECTED]> 

"Thomas G. Marshall" <[EMAIL PROTECTED]> 
schreef in bericht news:[EMAIL PROTECTED]
> Boudewijn Dijkstra coughed up:
>> "Ahmed Moustafa" <[EMAIL PROTECTED]> schreef in bericht
>> news:[EMAIL PROTECTED]
>>> Hello,
>>>
>>> What would be the most efficient to write a maximum function in
>>> Java?
>>>
>>> Initially, I had the comparisons that looked for the maximum inside
>>> the main method and then moved it inside its own method (code is
>>> below) to be called from within the main method (to make the code
>>> look prettier), but that cost me almost 3 additional seconds
>>> processing time:
>>>
>>> <code>
>>> private static float maximum (float a, float b, float c, float d) {
>>> float t1 = a > b ? a : b;
>>> float t2 = c > d ? c : d;
>>> return t1 > t2 ? t1 : t2;
>>> }
>>> </code>
>>
>> That method always runs in the same amount of VM ticks.  It takes:
>> - 3 comparisons;
>> - 3 copies; and
>> - 3 jumps.
>>
>> How about:
>>
>> private static float maximum(float a, float b, float c, float d)
>> {
>>   float max = a;
>>   if (b > max) max = b;
>>   if (c > max) max = c;
>>   if (d > max) max = d;
>>   return max;
>> }
>>
>> which takes:
>> - 1..4 copies;
>> - 3 comparisons; and
>> - 3 jumps.
>>
>> The average number of copies is calculated as follows:
>> if a is maximum: 1 copy
>> if b is maximum: 2 copies
>> if c is maximum: 3 copies
>> if d is maximum: 4 copies
>> average copies = (1 + 2 + 3 + 4) / 4 = 10 / 4 = 2.5
>>
>> Note that 2.5 < 3
>>
>> You can even theoretically reduce that 2.5 to 1.5 by removing the
>> first line and replacing 'max' by 'a', but that should probably be up
>> to the optimizer.
>
>
> Interesting!
>
> What about this I wonder:
>
>        private static float maximum(float a, float b, float c, float d)
>        {
>            if ((a >= b) && (a >=c) && (a >= d)) return a;
>            if ((b >= a) && (b >=c) && (b >= d)) return b;
>            if ((c >= a) && (c >=b) && (c >= d)) return c;
>            if ((d >= a) && (d >=b) && (d >= c)) return d;
>            assert(false);     // clinical paranoia.
>        }
>
> Note that >= is required and not >, because of the possibility of one
> or more of them being equal.

Interesting.  This gives:
- 3..12 comparisons
- 12 jumps
- 1 copy

But it contains a lot of redundant code.  E.g. the last if could be skipped 
completely, because it can proven to be always true.

private static float maximum(float a, float b, float c, float d)
{
    if ((a >= b) && (a >= c) && (a >= d)) return a;
    if ((b >= c) && (b >= d)) return b;
    if (c >= d) return c;
    return d;
}

This gives:
- 3..6 comparisons
- 3..6 jumps
- 1 copy

But it still contains redundant comparisons.

private static float maximum(float a, float b, float c, float d)
{
    if (a >= b) {
        if (a >= c) {
            if (a >= d)
                return a;
            return d;
        }
        if (c >= d)
            return c;
        return d;
    }
    if (b >= c) {
        if (b >= d)
            return b;
        return d;
    }
    if (c >= d)
        return c;
    return d;
}

Notice the regular tree-like structure.
This gives:
- 3 comparisons
- 3 jumps
- 1 copy

The fastest algorithm yet! 





== 2 of 3 ==
Date:   Tues,   Nov 16 2004 12:08 pm
From: "Thomas G. Marshall" <[EMAIL PROTECTED]> 

Boudewijn Dijkstra coughed up:
> "Thomas G. Marshall"
> <[EMAIL PROTECTED]> schreef in
> bericht news:[EMAIL PROTECTED]
>> Boudewijn Dijkstra coughed up:
>>> "Ahmed Moustafa" <[EMAIL PROTECTED]> schreef in bericht
>>> news:[EMAIL PROTECTED]
>>>> Hello,
>>>>
>>>> What would be the most efficient to write a maximum function in
>>>> Java?
>>>>
>>>> Initially, I had the comparisons that looked for the maximum inside
>>>> the main method and then moved it inside its own method (code is
>>>> below) to be called from within the main method (to make the code
>>>> look prettier), but that cost me almost 3 additional seconds
>>>> processing time:
>>>>
>>>> <code>
>>>> private static float maximum (float a, float b, float c, float d) {
>>>> float t1 = a > b ? a : b;
>>>> float t2 = c > d ? c : d;
>>>> return t1 > t2 ? t1 : t2;
>>>> }
>>>> </code>
>>>
>>> That method always runs in the same amount of VM ticks.  It takes:
>>> - 3 comparisons;
>>> - 3 copies; and
>>> - 3 jumps.
>>>
>>> How about:
>>>
>>> private static float maximum(float a, float b, float c, float d)
>>> {
>>>   float max = a;
>>>   if (b > max) max = b;
>>>   if (c > max) max = c;
>>>   if (d > max) max = d;
>>>   return max;
>>> }
>>>
>>> which takes:
>>> - 1..4 copies;
>>> - 3 comparisons; and
>>> - 3 jumps.
>>>
>>> The average number of copies is calculated as follows:
>>> if a is maximum: 1 copy
>>> if b is maximum: 2 copies
>>> if c is maximum: 3 copies
>>> if d is maximum: 4 copies
>>> average copies = (1 + 2 + 3 + 4) / 4 = 10 / 4 = 2.5
>>>
>>> Note that 2.5 < 3
>>>
>>> You can even theoretically reduce that 2.5 to 1.5 by removing the
>>> first line and replacing 'max' by 'a', but that should probably be
>>> up to the optimizer.
>>
>>
>> Interesting!
>>
>> What about this I wonder:
>>
>>        private static float maximum(float a, float b, float c, float
>>        d) {
>>            if ((a >= b) && (a >=c) && (a >= d)) return a;
>>            if ((b >= a) && (b >=c) && (b >= d)) return b;
>>            if ((c >= a) && (c >=b) && (c >= d)) return c;
>>            if ((d >= a) && (d >=b) && (d >= c)) return d;
>>            assert(false);     // clinical paranoia.
>>        }
>>
>> Note that >= is required and not >, because of the possibility of one
>> or more of them being equal.
>
> Interesting.  This gives:
> - 3..12 comparisons
> - 12 jumps
> - 1 copy
>
> But it contains a lot of redundant code.  E.g. the last if could be
> skipped completely, because it can proven to be always true.
>
> private static float maximum(float a, float b, float c, float d)
> {
>     if ((a >= b) && (a >= c) && (a >= d)) return a;
>     if ((b >= c) && (b >= d)) return b;
>     if (c >= d) return c;
>     return d;
> }
>
> This gives:
> - 3..6 comparisons
> - 3..6 jumps
> - 1 copy
>
> But it still contains redundant comparisons.
>
> private static float maximum(float a, float b, float c, float d)
> {
>     if (a >= b) {
>         if (a >= c) {
>             if (a >= d)
>                 return a;
>             return d;
>         }
>         if (c >= d)
>             return c;
>         return d;
>     }
>     if (b >= c) {
>         if (b >= d)
>             return b;
>         return d;
>     }
>     if (c >= d)
>         return c;
>     return d;
> }
>
> Notice the regular tree-like structure.
> This gives:
> - 3 comparisons
> - 3 jumps
> - 1 copy
>
> The fastest algorithm yet!

Not quite.  I like your optimization as your first example, but your second
example is essentially the same as the first.

The boolean comparisons in the statement

    if (A && B && C) ....

are evaluated left to right and abort immediately when false is found.  So
if A==false, B and C never get evaluated.  (for &&).

Similar reverse logic for ||.



-- 
http://www.allexperts.com is a nifty way to get an answer to just about
/anything/.





== 3 of 3 ==
Date:   Tues,   Nov 16 2004 12:56 pm
From: "Boudewijn Dijkstra" <[EMAIL PROTECTED]> 

"Thomas G. Marshall" <[EMAIL PROTECTED]> 
schreef in bericht news:[EMAIL PROTECTED]
> Boudewijn Dijkstra coughed up:
>> "Thomas G. Marshall"
>> <[EMAIL PROTECTED]> schreef in
>> bericht news:[EMAIL PROTECTED]
>>> Boudewijn Dijkstra coughed up:
>>>> "Ahmed Moustafa" <[EMAIL PROTECTED]> schreef in bericht
>>>> news:[EMAIL PROTECTED]
>>>>> Hello,
>>>>>
>>>>> What would be the most efficient to write a maximum function in
>>>>> Java?
>>>>>
>>>>> Initially, I had the comparisons that looked for the maximum inside
>>>>> the main method and then moved it inside its own method (code is
>>>>> below) to be called from within the main method (to make the code
>>>>> look prettier), but that cost me almost 3 additional seconds
>>>>> processing time:
>>>>>
>>>>> <code>
>>>>> private static float maximum (float a, float b, float c, float d) {
>>>>> float t1 = a > b ? a : b;
>>>>> float t2 = c > d ? c : d;
>>>>> return t1 > t2 ? t1 : t2;
>>>>> }
>>>>> </code>
>>>>
>>>> That method always runs in the same amount of VM ticks.  It takes:
>>>> - 3 comparisons;
>>>> - 3 copies; and
>>>> - 3 jumps.
>>>>
>>>> How about:
>>>>
>>>> private static float maximum(float a, float b, float c, float d)
>>>> {
>>>>   float max = a;
>>>>   if (b > max) max = b;
>>>>   if (c > max) max = c;
>>>>   if (d > max) max = d;
>>>>   return max;
>>>> }
>>>>
>>>> which takes:
>>>> - 1..4 copies;
>>>> - 3 comparisons; and
>>>> - 3 jumps.
>>>>
>>>> The average number of copies is calculated as follows:
>>>> if a is maximum: 1 copy
>>>> if b is maximum: 2 copies
>>>> if c is maximum: 3 copies
>>>> if d is maximum: 4 copies
>>>> average copies = (1 + 2 + 3 + 4) / 4 = 10 / 4 = 2.5
>>>>
>>>> Note that 2.5 < 3
>>>>
>>>> You can even theoretically reduce that 2.5 to 1.5 by removing the
>>>> first line and replacing 'max' by 'a', but that should probably be
>>>> up to the optimizer.
>>>
>>>
>>> Interesting!
>>>
>>> What about this I wonder:
>>>
>>>        private static float maximum(float a, float b, float c, float
>>>        d) {
>>>            if ((a >= b) && (a >=c) && (a >= d)) return a;
>>>            if ((b >= a) && (b >=c) && (b >= d)) return b;
>>>            if ((c >= a) && (c >=b) && (c >= d)) return c;
>>>            if ((d >= a) && (d >=b) && (d >= c)) return d;
>>>            assert(false);     // clinical paranoia.
>>>        }
>>>
>>> Note that >= is required and not >, because of the possibility of one
>>> or more of them being equal.
>>
>> Interesting.  This gives:
>> - 3..12 comparisons
>> - 12 jumps
>> - 1 copy
>>
>> But it contains a lot of redundant code.  E.g. the last if could be
>> skipped completely, because it can proven to be always true.
>>
>> private static float maximum(float a, float b, float c, float d)
>> {
>>     if ((a >= b) && (a >= c) && (a >= d)) return a;
>>     if ((b >= c) && (b >= d)) return b;
>>     if (c >= d) return c;
>>     return d;
>> }
>>
>> This gives:
>> - 3..6 comparisons
>> - 3..6 jumps
>> - 1 copy
>>
>> But it still contains redundant comparisons.
>>
>> private static float maximum(float a, float b, float c, float d)
>> {
>>     if (a >= b) {
>>         if (a >= c) {
>>             if (a >= d)
>>                 return a;
>>             return d;
>>         }
>>         if (c >= d)
>>             return c;
>>         return d;
>>     }
>>     if (b >= c) {
>>         if (b >= d)
>>             return b;
>>         return d;
>>     }
>>     if (c >= d)
>>         return c;
>>     return d;
>> }
>>
>> Notice the regular tree-like structure.
>> This gives:
>> - 3 comparisons
>> - 3 jumps
>> - 1 copy
>>
>> The fastest algorithm yet!
>
> Not quite.  I like your optimization as your first example, but your second
> example is essentially the same as the first.
>
> The boolean comparisons in the statement
>
>    if (A && B && C) ....
>
> are evaluated left to right and abort immediately when false is
> found.  So if A==false, B and C never get evaluated.  (for &&).
>
> Similar reverse logic for ||.

If d is the maximum, the first optimization performs 6 comparisons & jumps, 
but the second one takes only 3 of those. 






==========================================================================
TOPIC: JavaRanch?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/614f4214451b35cd
==========================================================================

== 1 of 3 ==
Date:   Tues,   Nov 16 2004 12:01 pm
From: "William Brogden" <[EMAIL PROTECTED]> 

On Tue, 16 Nov 2004 10:50:00 -0700, Chris Smith <[EMAIL PROTECTED]> wrote:

> Rhino wrote:
>> Am I the only one having trouble posting to the newsgroups in the  
>> JavaRanch
>> "Saloon"?
>
> AFAIK, JavaRanch doesn't have newsgroups.  They have a web forum for any
> of a bunch of topics, but if they now make those fora accessible via
> NNTP, that's news to me.
>
> You may find that many people who read Java newsgroups (including me)
> have a very poor opinion of JavaRanch.  This is mainly because as they
> were getting started, advocates of JavaRanch would frequently post
> insulting and rude messages to newsgroups.  These messages generally
> took the form of "you won't get an answer here, but go ask at
> JavaRanch".

Dear me! You are missing a great resource. I think it is safe to say
that you will get a better quality of answer there with less insulting
than your typical newsgroup. The breakdown of topics is much more
detailed than the comp.lang.java.* possibilities and I see many more
Java book authors there than on the newsgroups.
Bill



== 2 of 3 ==
Date:   Tues,   Nov 16 2004 12:57 pm
From: "Chris Uppal" <[EMAIL PROTECTED]> 

William Brogden wrote:

> Chris Smith wrote:

> > You may find that many people who read Java newsgroups (including me)
> > have a very poor opinion of JavaRanch.  [...]
>
> Dear me! You are missing a great resource.

The boot's on the other foot if you ask me.

    -- chris


P.S.  William, I e-mailed a copy of this directly to you instead of to the
group.  I pressed the wrong button, sorry !





== 3 of 3 ==
Date:   Tues,   Nov 16 2004 2:43 pm
From: Chris Smith <[EMAIL PROTECTED]> 

William Brogden wrote:
> Dear me! You are missing a great resource. I think it is safe to say
> that you will get a better quality of answer there with less insulting
> than your typical newsgroup. The breakdown of topics is much more
> detailed than the comp.lang.java.* possibilities and I see many more
> Java book authors there than on the newsgroups.

Then go post there.

-- 
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation




==========================================================================
TOPIC: Java on Linux
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b359a0d20324fdbe
==========================================================================

== 1 of 1 ==
Date:   Tues,   Nov 16 2004 12:42 pm
From: [EMAIL PROTECTED] (Lesley) 

"John C. Bollinger" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL 
PROTECTED]>...
> Lesley wrote:
> 
> > Last time I did any Java programming was on a Windows machine in
> > 2000/2001.
> > 
> > I have no clue how to install Java on a Linux box but I'd like to be
> > able to use Java again.  Mostly because I am teaching somebody how to
> > program and, for particular reasons, we are using Java.
> 
> You could try downloading the Sun-supported Linux install package (from 
> Sun, of course) and using it.  Check whether its compatible with your 
> Linux distribution.  You might also want to check out the Java Packaging 
> Project, but that might be more than you need.

Had a quick look at all the differnt downloads on Sun and have
selected the SDK with NetBeans in it. One for Linux and one for my XP
install.

> 
> > He has a Windows box but I do not want to wreck the Linux install on
> > my laptop.
> > It would be convenient to use the laptop to work out a syllabus and
> > work out some examples.  I have Blackdown Java installed on the laptop
> > and I have a vague idea that this is related to the Sun Java stuff but
> > :-
> > 1. I don't know how to work out if I have the SDK installed or not.
> 
> You could look for the Java compiler (javac) on your laptop.  Try
> "find / -name javac -print".  It will probably take a while to run, but 
> it will display the name and location of any file of the specified name 
> that it finds.
Did all that, and reran my installation disks selecting Java.  There
seems to be a GNU Java around on my system accessible via gcj command.
 However I've attempted the myframe.call from Just Java by Peter van
Linden (4th edition) using 'gcj myframe.class' and got undefined
reference to 'main'.
> 
> > 2. I don't know what the relationship between Blackdown and the Sun
> > Java is.  I want to avoid conflicts in example programs.
> 
> If your only talking about tutorial-type example programs then you are 
> unlikely to run into any problems of consequence.  Certainly the Java 
> language, the Java virtual machine, and the standard Java class library 
> have never been open to incompatible reimplementation under the terms of 
> any Java license I am aware of Sun ever issuing.

Glad to hear that.
> 
> > 3. There used to be a path one had to set to the path of the class
> > libraries installed on the machine. How is this managed in Linux?
> > Through the PATH environment variable?
> 
> You are thinking of the classpath.  It works under Linux just the same 
> as under windows: you specify the CLASSPATH environment variable and / 
> or specify the path on the java or javac command line via the 
> appropriate switch.  It has not for a long time been necessary to put 
> the standard class libraries in your classpath, however -- only user 
> classes.

TYVM. 
> 
> > 4.  Have there been any *huge* changes in the language since 2K?  I'm
> > using books I bought then.
> 
> Depends what you mean.  In the simplest terms, yes, there have been huge 
> changes.  On the other hand, it is unlikely that much valid Java source 
> written even to Java 1.1 would fail to still be valid Java source. 
> Class files compiled four years ago ought still to run on today's newest 
> Java VMs.  But there have been a great many additions to the standard 
> class libraries, and in the most recent Java release (1.5.0, a few weeks 
> ago) there are several very significant additions to the Java language 
> itself.
> 
> Have you considered that attempting to teach programming via a language 
> that you're not current with might be an unnecessarily difficult 
> challenge?  And that the student might be better served by instruction 
> in a language that the instructor is fluent in?

Yes, very much so.  But he hasn't found anyone else at the Uni yet
who'll give him one-to-one tutorials. I am aware of both the stress
factor for me *and* the issue of quality of instruction.  He's a
Masters degree student at a local University.  Part of his problem is
that he has absolutely *no* programming experience and I can certainly
help out there.    I am aware one of my weak points is lack of
knowledge of the classes available in Java.  The University provides
him with a set of simple i/o classes (keybd input, graphic output,
etc) they have built and at some point I will be getting him to make a
copy of that package, analyse it, improve it and build upon it.

The side effect for me is I get to focus on two things : how to teach
someone something (in this case programming, plus OOP plus some Java)
and revisiting Java itself.  I might not be the best Java teacher in
the world, yet ;) *but* I have already improved his knowledge with
something as simple as pre and post decrement operators, discussing
the side effect and the speed fo each.

There are the issues about the concept of static, getting across the
issues of encapsulation and why there are private, public and
protected methods and fields in a class.  My biggest issue is to build
a coherent set of examples that he will benefit from and I am looking
at it from the old fashioned view point that most (useful) programs
have data input, data output and some processing in between. So I want
to build his i/o skills to include file i/o for example.  (One thing
not covered in his University package).  Another issue is getting him
to do the homework too. I have to keep telling him he can't learn  to
program just by reading the books, he actually has to do it too.  So
what I have to find is a project that will motivate him and help him
learn to design programs using Java.  etc etc etc

Thanks for your input 

Lesley




==========================================================================
TOPIC: Java tree navigator
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2d640d8ae1e5c8f0
==========================================================================

== 1 of 2 ==
Date:   Tues,   Nov 16 2004 12:58 pm
From: "HS1" <[EMAIL PROTECTED]> 

Hello

Could you please tell me the principles of creating a simple tree navigator
using JTree (such as one tree with a parent with two children) such as:

parent
     child1
     child2

Thank you
S.H1





== 2 of 2 ==
Date:   Tues,   Nov 16 2004 1:02 pm
From: Carl <[EMAIL PROTECTED]> 

HS1 wrote:

> Hello
> 
> Could you please tell me the principles of creating a simple tree navigator
> using JTree (such as one tree with a parent with two children) such as:
> 
> parent
>      child1
>      child2
> 
> Thank you
> S.H1
> 
> 

http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html


For most questions of this sort, this is a good place to start.
http://java.sun.com/docs/books/tutorial/index.html

Carl.




==========================================================================
TOPIC: Java 1.5 Enums
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8cd26ba0bb283203
==========================================================================

== 1 of 1 ==
Date:   Tues,   Nov 16 2004 1:24 pm
From: [EMAIL PROTECTED] (Jesper Nordenberg) 

Chas Douglass <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> "Tony Morris" <[EMAIL PROTECTED]> wrote in
> news:[EMAIL PROTECTED]: 
> > You want to create an enum and a reverse mapping.
> > Suppose you have 2 ints {0,1} that mean something {BLACK, WHITE}.
> [snip]
> 
> Thanks, that solution was totally non-obvious to me, but it works 
> perfectly.

You can skip the map and the int by using the ordinal() method, for
example:

MyEnum getEnumFor(int value) {
  for (MyEnum v : MyEnum.values())
    if (v.ordinal() == value)
      return v;
}

Just remember to store value.ordinal() in the database and don't
change the order of the enum constant declarations.

/Jesper Nordenberg




==========================================================================
TOPIC: Unable to have tags within tags??
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d0b216afc2658f5c
==========================================================================

== 1 of 1 ==
Date:   Tues,   Nov 16 2004 2:17 pm
From: [EMAIL PROTECTED] (Kwasi) 

I am using WSAD 5.1 and am having problems when compiling lines like
the following:
<input type="hidden" name="domainName" value="<c:out
value={requestScope.domainNm}"> where c is defined as the jstl taglib
The error I get when I try to do this is "the value of attribute value
must not contain the '<' character. Somehow I have a strange and very
strict compiler that is not very friendly. Anyone have any ideas as to
what I might be doing wrong??




==========================================================================
TOPIC: Why my servlet always be loaded for three times?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/41db7d702e514554
==========================================================================

== 1 of 1 ==
Date:   Tues,   Nov 16 2004 2:46 pm
From: [EMAIL PROTECTED] (Duncan) 

my web.xml like below

<servlet>
    <servlet-name>TimerAutoRecharge</servlet-name>
    <servlet-class>com.unify.voip.control.TimerAutoRecharge</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet>
    <servlet-name>AppHandler_system</servlet-name>
    <servlet-class>com.unify.voip.control.AppHandler</servlet-class>
    <load-on-startup>2</load-on-startup>   
  </servlet>
  <servlet>
    <servlet-name>ApplRequestProcessor</servlet-name>
    <servlet-class>com.unify.voip.control.ApplRequestProcessor</servlet-class>
    <load-on-startup>3</load-on-startup>   
  </servlet>
     
  
  
  <servlet-mapping>
    <servlet-name>TimerAutoRecharge</servlet-name>
    <url-pattern>/TimerAutoRecharge</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>AppHandler_system</servlet-name>
    <url-pattern>/AppHandler_system</url-pattern>             
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>ApplRequestProcessor</servlet-name>
    <url-pattern>/ClientProcessor</url-pattern>             
  </servlet-mapping>

Why all my three servlets are always being loaded for three times when
tomcat server startup?

Don't know why?



=======================================================================

You received this message because you are subscribed to the
Google Groups "comp.lang.java.programmer".  

comp.lang.java.programmer
[EMAIL PROTECTED]

Change your subscription type & other preferences:
* click http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe

Report abuse:
* send email explaining the problem to [EMAIL PROTECTED]

Unsubscribe:
* click http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe


=======================================================================
Google Groups: http://groups-beta.google.com 

Reply via email to