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

Today's topics:

* Need help w. the JSTL c:out tag. - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2bb8e9c8c521f2fd
* How to initialize a big (String-)Array fast? - 3 messages, 3 authors
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7a849e4e56de0eae
* applet security issues - 2 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/826c15e115e334c0
* [OT] Using hobby source code in your job ? - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a60dfe865a7807c4
* math.pow rounding problem - 3 messages, 3 authors
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3e00e118892196bb
* Zip/UnZip char [] - 2 messages, 2 authors
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/becaa86f0228fd4f
* Java speed vs. C++. - 2 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e29354c898cb3523
* Casting Object to Array type - 3 messages, 3 authors
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/66c662ceb6d5cf17
* "Symbolic computation" - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4a89d6f4799be886
* JNDI InitialContext problem - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8f7e20a7ce68b0a7
* Creating funny objects - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/275532460061ec7
* Sockets - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/edecab678cd31cd6
* Generics: how to avoid overloaded methods? - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/11b478096ef7c41f
* can't find class file - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/41f61eb9d8c24f1c
* "static" prefix - to parallel "this" prefix - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f5dde10882ac2157
* how to resize a array? - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d5ed97c9d7b81add

==============================================================================
TOPIC: Need help w. the JSTL c:out tag.
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2bb8e9c8c521f2fd
==============================================================================

== 1 of 1 ==
Date: Mon, Dec 6 2004 9:42 am
From: "Heiner Kücker"  

Steve Burrus wrote
> I  need help w. the JSTL c:out tag!! I am just simply trying to get the
> current date printed out in a JSP page, but it won't show/display! All
> that it shows in the web browser is the <h2></h2> heading and then under
> that this :  ${date}, instead of the date that I would like to see. Here
> is the code for this file :
>
>   <%-- use the 'taglib' directive to make the JSTL 1.1 core tags
> available --%>
> <%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c" %>
> <%-- use the 'jsp:useBean' standard action to make the Date object
> available in page scope --%>
> <jsp:useBean id="date" class="java.util.Date" />
> <html>
> <head><title>First JSP</title></head>
> <body>
> <h2>Here is today's date</h2>
> <c:out value="${date}" />
> </body>
> </html>
>
> Thanx in advance to anyone who can help me with this problem.

The java.util.Date class is no bean (has no get and set methods).
Wrap your Date in a bean class with get and set methods.

-- 
Heiner Kuecker
Internet: http://www.heinerkuecker.de  http://www.heiner-kuecker.de
JSP WorkFlow PageFlow Page Flow FlowControl Navigation: 
http://www.control-and-command.de
Expression Language Parser: http://www.heinerkuecker.de/Expression.html






==============================================================================
TOPIC: How to initialize a big (String-)Array fast?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7a849e4e56de0eae
==============================================================================

== 1 of 3 ==
Date: Mon, Dec 6 2004 1:04 am
From: [EMAIL PROTECTED] (Patrick) 

Hello,

is there a way to initialize a big String-Array faster than just with "new"?

Ex.:
String result[] = new String[64000000];

takes over a second on a Pentium 3 800MhZ.

For bigger values still more.

Is there a way to do this faster?

Greetings and TIA,
Patrick



== 2 of 3 ==
Date: Mon, Dec 6 2004 10:18 am
From: Frank  

Patrick wrote:
> Hello,
> 
> is there a way to initialize a big String-Array faster than just with "new"?
> 
> Ex.:
> String result[] = new String[64000000];
> 
> takes over a second on a Pentium 3 800MhZ.
> 
> For bigger values still more.
> 
> Is there a way to do this faster?
> 
> Greetings and TIA,
> Patrick

You're allocating 256MB++ worth of memory. That's bound to take some 
time, especially if there's swapping involved.

Perhaps you should just tell us what you're trying to accomplish 
instead, some may have a better approach.



== 3 of 3 ==
Date: Mon, Dec 6 2004 12:03 pm
From: Michael Borgwardt 
 

Patrick wrote:
> is there a way to initialize a big String-Array faster than just with "new"?
> 
> Ex.:
> String result[] = new String[64000000];
> 
> takes over a second on a Pentium 3 800MhZ.
> 
> For bigger values still more.
> 
> Is there a way to do this faster?

Sure. Redesign your program not to require such a godawful amount of memory.

It's completely pointless anyway, since you can't even HAVE enough
memory on a Pentium 3 machine to actually put *content* into that array.




==============================================================================
TOPIC: applet security issues
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/826c15e115e334c0
==============================================================================

== 1 of 2 ==
Date: Mon, Dec 6 2004 10:15 am
From: "Matthijs Blaas"  

> You can offer the same applet to a 1.1 VM and simply add
> the resources to the 'archive' parameter.  While the user
> is waiting for the jars to be downloaded, throw up a Dialog
> suggesting they might consider upgrading to the genuine, this
> millenium, Sun Java Plug-In.

You mean a message in the HTML? Because the problem is the jvm
won't excecute any class I put in the archive tag till every class/jar is
loaded. Is it a jws option to offer the applet version if jws is not 
detected?
*I only found some javascript to detect that.

Also, I believe jws doesn't allow its applications to be run embedded in
the html like an applet? That would cause problems with the current
webdesign...

>> But what if the class I want to instanciate resides in a jar (game jar) 
>> and
>> depends on another jar for certain method calls (library jar)? I could
>> download these two jars over an urlconnection, no problem. I also believe
>> the java api offers functionality to look in jar/zip files, but will I be
>> able to instanciate the game mainclass from the gamejar through the 
>> loader
>> class? What I thought is that I need an classloader to tell where the 
>> game
>> can look for class files it needs (ie: a class it extends from the 
>> library
>> jar which I also downloaded). Will it know where to find it when I simply
>> download the two jars?
>
> ..stop, Stop, STOP!
> Maybe this will answer some questions for you.
> <http://www.physci.org/launcher.jsp>
> That is the launcher applet, each link leads to the
> Launcher applet, ready to open the frame, and the
> source code used for the frame.  Try it.
>
> It is an unsigned applet.  Java 1.1 compatible (though
> any of the launched applications may not be).
>
> How is it done?  Let the code do the talking.
> <http://www.physci.org/codes/display.jsp?fl=/Launcher.java>

I know about instanciating plain class files.
*I even used your launcher example a while ago to try some things out ;)
The problem I have is with jar files. In order to be able to search /
instanciate a class from a jar it has to be in the classloaders classpath.
When you put example.jar in the archive tag the applet classloader will add
to the classpath. Unfortunaly it's a protected method so I can't invoke it 
again
to add my new jar's on the fly... I think I'd need to sign my applet and 
create a
new classloader for these jars but that'd throw an nasty popup asking people 
if
the trust it. So I better stop whinning and keep using the archive tag ;-) 





== 2 of 2 ==
Date: Mon, Dec 6 2004 10:40 am
From: "Matthijs Blaas"  

> There is no solution to this problem for publically available games
> (e.g. those that do not require authentication.) A client can run whatever
> code the user likes and there's nothing you can do about it.  Regardless 
> of
> whether they hack your applet directly via the browser cache or if they
> simply copy it and run it directly,

It's impossible to run it directly and upload a score as it needs an server
sided game session in our case. For that there is somekind of 
authentication,
for a user to upload a score he must have registered an account with us and
must be logged in. The server must have created an session which is valid 
for
that game played.

> you have no way to authenticate the communication from that applet to your
> website and they are free to spoof that communication in any way they can 
> try.
> Bottom line: you cannot rely on the client to perform security checks for 
> you.

True, but I thought there might be some common way of making it very 
difficult
to tamper with the applet, as there must be more applications that want to 
make
that as difficult as possible... I know obfuscating is one, but maybe there 
is a logic
way of doing this too... for example force it to be never cached:
make a small loader class that each time gets downloaded from another url (a 
variable url like:
/123ab/loader.class, or 123cd/loader.class). That way the jvm will never use 
an
cached version. Problem is that such methods are a bit clumsy, take a lot of 
unnecesary
bandwidth & cache on the client. It's not hackproof for sure, but will make 
it harder. 






==============================================================================
TOPIC: [OT] Using hobby source code in your job ?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a60dfe865a7807c4
==============================================================================

== 1 of 1 ==
Date: Mon, Dec 6 2004 10:07 am
From: "Siemel Naran"  

"Stephen Sprunk" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

> Very simple: part of your employment contract requires you to assign to
the
> company copyright and ownership of any original works produced, modified,
or
> published by you during the term of your employment.  Unless you
> specifically negotiate one, there is usually no exemption for things done
on
> "personal time".  They do provide a place where you can declare any works
> you produced or owned prior to entering their employ; anything on that
list
> is exempt from the assignment, but anything not on the list becomes a
"work
> for hire" on behalf of the company if you so much as think about it while
> you're employed there.

It may depend on the state.  In California we have labor code 2870.  Other
states may have similar laws protecting the individual.  You can search for
it on google.

<Quote Description="California Labor Code Section 2870-2872">

2870.
(a) Any provision in an employment agreement which provides that an employee
shall assign, or offer to assign, any of his or her rights in an invention
to his or her employer shall not apply to an invention that the employee
developed entirely on his or her own time without using the employer's
equipment, supplies, facilities, or trade secret information except for
those inventions that either: Relate at the time of conception or reduction
to practice of the invention to the employer's business, or actual or
demonstrably anticipated research or development of the employer; or Result
from any work performed by the employee for the employer.

(b) To the extent a provision in an employment agreement purports to require
an employee to assign an invention otherwise excluded from being required to
be assigned under subdivision (a), the provision is against the public
policy of this state and is unenforceable.

2871
No employer shall require a provision made void and unenforceable by Section
2870 as a condition of employment or continued employment. Nothing in this
article shall be construed to forbid or restrict the right of an employer to
provide in contracts of employment for disclosure, provided that any such
disclosures be received in confidence, of all of the employee's inventions
made solely or jointly with others during the term of his or her employment,
a review process by the employer to determine such issues as may arise, and
for full title to certain patents and inventions to be in the United States,
as required by contracts between the employer and the United States or any
of its agencies.

2872
If an employment agreement entered into after January 1, 1980, contains a
provision requiring the employee to assign or offer to assign any of his or
her rights in any invention to his or her employer, the employer must also,
at the time the agreement is made provide a written notification to the
employee that the agreement does not apply to an invention which qualifies
fully under the provisions of Section 2870. In any suit or action arising
thereunder, the burden of proof shall be on the employee claiming the
benefits of its provisions.

</Quote>

(2870)(a) suggests that if you create code with your own resources, it is
yours to keep.  But (2870)(b) seems vaguely worded and appears to contradict
the previous statement.








==============================================================================
TOPIC: math.pow rounding problem
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3e00e118892196bb
==============================================================================

== 1 of 3 ==
Date: Mon, Dec 6 2004 3:39 pm
From: Babu Kalakrishnan  

Paul van Rossem wrote:
> On 06-12-2004 07:03, Chris Smith wrote:
> 
>> Patricia Shanahan <[EMAIL PROTECTED]> wrote:
>>
>>> 1e-21 cannot be exactly represented in double, because
>>> doubles are finite-width binary fractions. It is similar to
>>> the problem of representing 2/3 as a finite-width decimal
>>> number.
>>
>>
>>
>> That's certainly the easy answer.  I wonder if it's right.  When the 
>> printed result is 1.0000000000000001E-21, I'm forced to conclude that 
>> either of two things are true:
>>
>> a) There is another possible double value that is closer to 1e-21 than 
>> the one returned by Math.pow, and the extra digits were needed to 
>> resolve the ambiguity.  In that case, it appears Math.pow is broken, 
>> since it should have returned that other double that's closer to 1e-21.
>>
>> b) The double value returned by Math.pow is closer to 1e-21 than any 
>> other possible double value.  In that case, Double.toString is broken 
>> since it didn't need to output those extra digits.
>>
>> Where am I getting this wrong?  Or am I?
>>
> I think you forget that first the integer arguments of the call (10 and 
> 21) must also be rounded to the nearest double. So there you start with
> small rounding errors, that are then amplified by the power algorithm.
> 

Actually there are _no_ rounding errors in the conversion of the integer
arguments as such (all numbers in the "int" range are exactly
representable by a Double since the mantissa of a double has far more
number of significant bits).

However, your point that the error is due to overflows/underflows is
probably valid. The pow algorithm does use several coefficients for
computing log2(x) several of which are non-exact, and this probably
contributes to the error.

Whether there is a better algorithm that can always provide the
_nearest_ double as the result (which I think was Chris's point) - I
think it is upto the mathematicians to debate.. (Patricia ?). But as far
as I can see, the error is exactly 1 bit at the LSB. (1E-21 as encoded
by the string parser has a mantissa of 0x12e3b40a0e9b4f whereas the
result returned has a mantissa of 0x12e3b40a0e9b50.

And as to which of the two presumbtions is correct (point (a) or (b) in
Chris's post), I think it is case (a) - which can be verified by
creating BigDecimals from the two doubles and checking which is nearer
to 1E-21.

BK





== 2 of 3 ==
Date: Mon, Dec 6 2004 12:18 pm
From: "Boudewijn Dijkstra"  

"Paul van Rossem" <[EMAIL PROTECTED]> schreef in bericht 
news:[EMAIL PROTECTED]
> On 06-12-2004 07:03, Chris Smith wrote:
>> Patricia Shanahan <[EMAIL PROTECTED]> wrote:
>>
>>>1e-21 cannot be exactly represented in double, because
>>>doubles are finite-width binary fractions. It is similar to
>>>the problem of representing 2/3 as a finite-width decimal
>>>number.
>>
>>
>> That's certainly the easy answer.  I wonder if it's right.  When the 
>> printed result is 1.0000000000000001E-21, I'm forced to conclude that 
>> either of two things are true:
>>
>> a) There is another possible double value that is closer to 1e-21 than the 
>> one returned by Math.pow, and the extra digits were needed to resolve the 
>> ambiguity.  In that case, it appears Math.pow is broken, since it should 
>> have returned that other double that's closer to 1e-21.
>>
>> b) The double value returned by Math.pow is closer to 1e-21 than any other 
>> possible double value.  In that case, Double.toString is broken since it 
>> didn't need to output those extra digits.
>>
>> Where am I getting this wrong?  Or am I?
>>
> I think you forget that first the integer arguments of the call (10 and 21) 
> must also be rounded to the nearest double. So there you start with
> small rounding errors, that are then amplified by the power algorithm.

Both range and precision of doubles are enough (by far) to precisely represent 
10 and 21. 





== 3 of 3 ==
Date: Mon, Dec 6 2004 12:45 pm
From: "Chris Uppal"  

Babu Kalakrishnan wrote:

> And as to which of the two presumbtions is correct (point (a) or (b) in
> Chris's post), I think it is case (a) - which can be verified by
> creating BigDecimals from the two doubles and checking which is nearer
> to 1E-21.

For completeness:

The "correct" answer is (of course):
    1 / (10 ** 21)

The answer given by pow() is, decoding the bits of the double:
    5316911983139664 / (2 ** 122)

The value of 1.0e-21D is (again decoding the bits of the double):
    5316911983139663 / (2 ** 122)

The same three values in decimal format (fully expanded):
exact:    0.000 000 000 000 000 000 001
pow():    0.000 000 000 000 000 000 001 000 000 000 000 000
                095 616 548 359 462 372 671 727 780 467 234 839
                207 896 907 042 893 985 817 499 924 451 112 747
                192 382 812 5
1e-21:    0.000 000 000 000 000 000 000 999 999 999 999 999
                907 537 452 227 896 371 396 729 934 511 675 530
                756 910 417 959 359 982 376 099 651 446 565 985
                679 626 464 843 75

The exact answer is not exactly representable as a Java double, but lies
between the answer given by pow() and the value of 1.0e-21D.  If you do the
arithmetic, you'll see that the exact value actually lies slightly closer to
the value of 1.0e-21D (by about 3%), so pow() is not answering the closest
possible double to the mathematically correct answer.  So in that sense the
answer is "wrong", and Chris's option (a) holds.  However I wouldn't follow him
in calling pow() "broken" since it is actually returning the /second/ closest
double to the correct answer (the one just above rather than the one just
below), and that is acceptable according the contract of pow() since it is
within one "ulp" of the mathematically correct answer.

    -- chris






==============================================================================
TOPIC: Zip/UnZip char []
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/becaa86f0228fd4f
==============================================================================

== 1 of 2 ==
Date: Mon, Dec 6 2004 10:22 am
From: "Ike"  

In short, I convert to char [] any data I am to put into a blob field.
Before I put that char [] into a blob field, I would simply like to compress
it (realizing that some data, e.g. jpg's ) wont compress by much, whereas
other types (ASCII typically) will. Of course I want to reverse the process
on the other end. However, I need it (the compression/decompression) to be
something I can also replicate in php as I will be taking thse blobs down
and using them there, as well as putting them up (into the db) from there in
php as well as Java. -Ike


"Chris Smith" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Ike <[EMAIL PROTECTED]> wrote:
> > I'm looking to set up a separate table in a DB for just BLOBS, but, I
also
> > need to be able to update and access then from php as well. Not sure I
can
> > do this. -Ike
>
> I'm not sure what you're asking, or how it fits into the previous
> discussion.  Can you clarify?
>
> -- 
> www.designacourse.com
> The Easiest Way To Train Anyone... Anywhere.
>
> Chris Smith - Lead Software Developer/Technical Trainer
> MindIQ Corporation





== 2 of 2 ==
Date: Mon, Dec 6 2004 11:54 am
From: Michael Borgwardt 
 

Ike wrote:

> In short, I convert to char [] any data I am to put into a blob field.

Why? char[] is for *text*, not for arbitrary data. Use byte[].




==============================================================================
TOPIC: Java speed vs. C++.
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e29354c898cb3523
==============================================================================

== 1 of 2 ==
Date: Mon, Dec 6 2004 11:41 am
From: Michael Borgwardt 
 

KiLVaiDeN wrote:
> Java takes time to initialise things, like preloading the classes, and lot 
> of other things. It's also an interpreted language, and it will be always 
> slower than compiled programs, no matter what you do.

This is absolute nonsense. Java hasn't been an "interpreted language" for
years, at least not on the normal VMs. The code is compiled to native
at runtime by the VM (just-in-time-compiler, JIT), which is of course another
startup delay (that's why nowadays the VMs do it only for methods that
are called frequently) but once it has happened, Java can in fact be
*faster* than compiled C because the JIT has more information and e.g. can
optimize for the actually present CPU.



== 2 of 2 ==
Date: Mon, Dec 6 2004 11:42 am
From: Michael Borgwardt 
 

Chris Smith wrote:
>>Hi.  I recently ran a benchmark against two simple programs, one written in
>>Java and the other in C++.  The both accomplish the same thing, outputting
>>"Hello World" on my screen.  The C++ program took .5 seconds to complete on
>>my 400 Mhz PC while the Java program took 6.5 seconds.  
> 
> 
> Neither of these times are even in the ballpark of what you should be 
> seeing.  Do to the startup overhead that's been well-discussed in this 
> group, your Java application should be running in about half a second, 
> while your C++ application should take something on the order of 10 to 
> 50 milliseconds (that's 0.01 to 0.05 seconds).  If these apps are really 
> taking that long, then you've got some other serious problems that's 
> affecting BOTH your Java and C++ code.

Could be simply the effect of too little RAM, with the JVM needing some
swapping.




==============================================================================
TOPIC: Casting Object to Array type
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/66c662ceb6d5cf17
==============================================================================

== 1 of 3 ==
Date: Mon, Dec 6 2004 2:41 am
From: [EMAIL PROTECTED] (Nikolaus Rumm) 

Hello,

I have to write a generic equality-check method that can handle
objects, arrays of primitives and arrays of objects. Something like...

public void isEqual(Object aFirstValue, Object aSecondValue) {
   ...
   boolean isArray = aFirstValue.getClass().isArray();
   if (isArray) {
      return Arrays.equals(aFirstValue, aSecondValue); // ERROR: type
cast missing
   }
}

My problem is that I have to cast the Object argument to an array type
so that the Java compiler recognizes that I don't want to call
Arrays.equals(Object), but Arrays.equals(Array1, Array2).

I could cast the argument to Object[], but that wouldn't work with
primitive objects (i.e. byte[]). Of course I could do it the stupid
way and have a big if-then-else statement for all possible primitive
arrays, but thats beyond my reputation.

Is there any elegant way to solve this problem ?



== 2 of 3 ==
Date: Mon, Dec 6 2004 12:16 pm
From: Michael Borgwardt 
 

Nikolaus Rumm wrote:
> My problem is that I have to cast the Object argument to an array type
> so that the Java compiler recognizes that I don't want to call
> Arrays.equals(Object), but Arrays.equals(Array1, Array2).
> 
> I could cast the argument to Object[], but that wouldn't work with
> primitive objects (i.e. byte[]). Of course I could do it the stupid
> way and have a big if-then-else statement for all possible primitive
> arrays, but thats beyond my reputation.

Why? What's so bad about it?

Actually, it's the only possible way, because overloaded methods are bound
at compile time.



== 3 of 3 ==
Date: Mon, Dec 6 2004 12:47 pm
From: "Chris Uppal"  

Nikolaus Rumm wrote:

> I could cast the argument to Object[], but that wouldn't work with
> primitive objects (i.e. byte[]). Of course I could do it the stupid
> way and have a big if-then-else statement for all possible primitive
> arrays, but thats beyond my reputation.
>
> Is there any elegant way to solve this problem ?

No.  At the JVM level there is a different bytecode to read elements of arrays
of each primitive type (with the exception of boolean[] which is treated as if
it were a byte[]).  So in the end /something/ must be telling the compiler what
kind of arrays you are dealing with.  Of course, it's possible that there could
be some standard function that did that test-and-switch for you, but I don't
think there is one.

    -- chris







==============================================================================
TOPIC: "Symbolic computation"
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4a89d6f4799be886
==============================================================================

== 1 of 1 ==
Date: Mon, Dec 6 2004 2:41 am
From: [EMAIL PROTECTED] 

http://www.ardice.com/Computers/Programming/Graphics/Libraries/OpenGL/Add-on_Libraries/





==============================================================================
TOPIC: JNDI InitialContext problem
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8f7e20a7ce68b0a7
==============================================================================

== 1 of 1 ==
Date: Mon, Dec 6 2004 10:40 am
From: Juha Laiho  

"Kyle" <[EMAIL PROTECTED]> said:
>In an example source file (AddressBook), I found the following codes:
>
>InitialContext initialContext = new InitialContext ();
>Context envContext = (Context) initialContext.lookup ("java:comp/env");
>DataSource dataSource = (DataSource) envContext.lookup ("jdbc/Public");
>
>I know it is using JNDI. But since the InitialContext is instantiated
>with no parameter, the second statement seems strange to me.

The JNDI implementation you use has some default context to which it
binds if the initial context is not specified.

>What does it mean by "java:comp/env"? is it a standard Name? And the
>same for jdbc/Public? BTW, Public is a name of a database.

>I did not find any document on "java:comp/env"?

java:comp/env is one of the normal starting points for JNDI namespaces,
though I don't know where these are documented.

jdbc is a common subtree within java:comp/env, used to contain references
to database resources. Thus, the full path to your database resource is
java:comp/env/jdbc/Public. The common way is to use the three levels you
listed above; an InitialContext, the needed subcontextx (here envContext),
and then the actual resource (here the dataSource).

It is possible, however, to directly look up the database resource from
the InitialContext with just

InitialContext initialContext = new InitialContext ();
DataSource dataSource = (DataSource) initialContext.lookup 
("java:comp/env/jdbc/Public");

... and I don't know the justification for using the envContext as the
middle layer -- that's just the way it seems to be done everywhere.
-- 
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
         PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)




==============================================================================
TOPIC: Creating funny objects
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/275532460061ec7
==============================================================================

== 1 of 1 ==
Date: Mon, Dec 6 2004 11:51 am
From: Michael Borgwardt 
 

hopkins wrote:
> In particular, why are objects created like this
> 
>         SAXParserFactory factory = SAXParserFactory.newInstance();
>  ...and
>         SAXParser saxParser = factory.newSAXParser();
 >
> I have always been taught to creat object in the form
> 
>   Person newPerson = new Person();
> 
> This way where you seem to call a different method other than the
> constructor when the object is created confuses me and I cant really
> understand why you'd want to do this. 

This is known as a factory method. Paul gave an example why one might
want to do this.

Basically, it's more flexible than a constructor, because a constructor
can only "return" an instance of the concrete class, while a factory can
declare an abstract class or an interface as its return type and return
an arbitrary subclass or intrface implementation. Note that in your
code, SAXParser is an abstract class, so it's not possible to instantiate
it with "new".


> Secondly as the two lines in
> question dont seem to have the "new" keyword does this mean they are
> not created on the heap and are stack based like in C++?

No. The factory method will use "new" in some way, directly or indirectly.




==============================================================================
TOPIC: Sockets
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/edecab678cd31cd6
==============================================================================

== 1 of 1 ==
Date: Mon, Dec 6 2004 11:59 am
From: Michael Borgwardt 
 

Teo wrote:
> Could a program written in Java communicate easily using the sockets with
> another program written in VC++  ?

Technically, it doesn't matter. But what will be the *content* of the 
communication?
C programmers tend to want to just send structs, which is not portable, not even
between C programs compiled with different compilers or on different 
architectures.
So you need to define your communication protocol exactly and carefully.




==============================================================================
TOPIC: Generics: how to avoid overloaded methods?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/11b478096ef7c41f
==============================================================================

== 1 of 1 ==
Date: Mon, Dec 6 2004 12:40 pm
From: Michael Borgwardt 
 

Chris Uppal wrote:
>>class DataBase{}
>>class DataSub extends DataBase{}
>>
>>class ControllerBase<D extends DataBase>{
>>void method(D d);
>>}
>>
>>class ControllerSub<D extends DataSub> extends ControllerBase<D>{
>>void method(D d);
>>}
> 
> 
> Not an attempt to answer your question, Michael.  I just wondered if I was
> alone in finding the above sketch almost impossible to "feel" ?
> 
> Put another way: is it just that I'm not used to (Java) generics yet, or is 
> the
> above genuinely hard to understand (significantly so) ?

Probably a combination of both. Generics definitely seems to get really nasty 
really
quickly as soon as inheritance is involved.

I've thought about the example a bit, and I think the functionality is better
represented through delegation rather than inheritance, and perhaps accessed
through a generic interface.




==============================================================================
TOPIC: can't find class file
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/41f61eb9d8c24f1c
==============================================================================

== 1 of 1 ==
Date: Mon, Dec 6 2004 6:34 am
From: "Ryan Stewart"  

"Peter" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi all,
>
>  I am trying to log servlet messages but can't get this code to
> compile,
[...]
> The error is,
> LogonAction.java:67: cannot find symbol
> symbol : method getDebug()
> location: class org.apache.struts.action.ActionServlet
>  If (servlet.getDebug () <=1)
>
> I even tried unzipping the struts.jar file in the directory I am
> compiling from.
>
> I am at wits end and really appreciate your help..
>
The problem has nothing to do with not finding the class. On the contrary, 
it's finding that just fine. The problem is that there's no "getDebug()" 
method in Struts' ActionServlet. What led you to believe that there was? 






==============================================================================
TOPIC: "static" prefix - to parallel "this" prefix
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f5dde10882ac2157
==============================================================================

== 1 of 1 ==
Date: Mon, Dec 6 2004 12:47 pm
From: "Chris Uppal"  

Tim Tyler wrote:

> Suggested syntax would be "static.var" and "static.method()" -
> instead of today's "ClassName.var" and "ClassName.method()".
[...]
> Has this been suggested before?
>
> Does it make sense to you?
>
> Are there any other proposals to deal with the same issue?

Yes, yes, and yes, respectively ;-)

Alex Hunsley posted a similar suggestion (maybe identical) a few months ago;
see this thread (sorry about the URL, but it seems that Google is in the
process of switching how the Google groups work):

http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4ceda7465055571c

(in case the URL stops working, the thread's title is "Good idea or full it
it?")

Personally, I like the idea but think it would work still better with a
different keyword such as 'thisClass', see my post in the above thread for
details.

    -- chris







==============================================================================
TOPIC: how to resize a array?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d5ed97c9d7b81add
==============================================================================

== 1 of 1 ==
Date: Mon, Dec 6 2004 4:45 am
From: bugbear  

Dimitri Maziuk wrote:
> Oscar kind sez:
> 
>>nick <[EMAIL PROTECTED]> wrote:
>>
>>>char[][] arr=new char[5][5];
>>>arr[0][0]='a';
>>>arr[0][1]='b';
>>>........
>>>
>>>i want to resize (arr) at run time and reserve the original data
>>>what should i do?
>>
>>There are two alternatives
>>- Use George's advice: allocate a new, bigger, array and use
>>  System#arraycopy(Object, int, Object, int, int).
>>- Use a List instead. Especially ArrayList is well suited to replace an
>>  array.
> 
> 
> You do know that a) ArrayList does the very same array copy,
> b) comes with an extra dozen bytes overhead for each member
> and c) casts all its memebers to Object, right?

Belatedly....

http://jakarta.apache.org/commons/primitives/

     BugBear



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

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

To post to this group, send email to [EMAIL PROTECTED] or
visit http://groups-beta.google.com/group/comp.lang.java.programmer

To unsubscribe from this group, send email to
[EMAIL PROTECTED]

To change the way you get mail from this group, visit:
http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe

To report abuse, send email explaining the problem to [EMAIL PROTECTED]

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

Reply via email to