 |
 |
Index ‹ java-programmer
|
- Previous
- 1
- 1
- Derived class & objects to parent constructorI've worked around this problem but it's still bugging me a bit so I
thought I'd ask here. In a derived class, I wanted to hold a reference to
a newly created object passed to a parent constructor. The only public
constructor in the parent requires this argument and the parent provides no
methods to later retrieve it. I couldn't find a syntax that would compile.
I'm thinking it's not possible but just wanted to confirm that I wasn't
missing something.
class someobject {}
class parent {
public parent (someobject so) { }
}
class child extends parent {
// someobject so = new someobject(); // Doesn't work
public child () {
// someobject so = new someobject(); // Also doesn't work
super (new someobject ()); // Want to hold a reference
// to someobject in child
}
}
Thanks in advance for any answers.
Doug
- 1
- Java HotSpot ArticleJames Gosling linked to this article from his blog.
(http://blogs.sun.com/jag/) I thought it might be of interest to those
involved in recent discussions about Java performance.
http://weblogs.java.net/blog/kohsuke/archive/2008/03/deep_dive_into.html
Apparently if you want to try it out you'll need a debug version of the JDK.
- 1
- profile jdk 1.3.1 from antHi,
We are intrested in profiling ( measure/find bottlenecks) in our java
application. I need advice where I can find a simple and free
profiling/performance tool for jdk1.3.1 that can be executed from ant (
or tool has a java api).
cheers,
//mikael
- 4
- Help me please! class problemsHi look @ this code:
mapper.java:
-------------
import java.applet.*;
import java.awt.*;
public class mapper extends Applet
{
public void paint (Graphics g)
{
if(bild.isLoadedID(id))
{
bild.showImage(id,0,0,400,400,g);
}
else
{
g.drawString("loading",50,50);
}
}
}
OrgImage.java:
----------------
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
public class OrgImage
{
int MAX=10;
MediaTracker tracker;
Image test;
OrgImage()
{
this.image = new Image[MAX];
this.tracker = new MediaTracker(this); //ERROR1
}
int addImage(String source)
{
this.ID++;
this.test = this.getImage(getCodeBase(), source); //ERROR2
return this.ID;
}
}
Both files are in one directory im working with Eclipse 3.0
ERROR1: The constructor MediaTracker(OrgImage) is undefined
ERROR2: The method getCodeBase() is undefined for the type OrgImage
Please help
MfG
Stylistics
- 4
- Portal Solutions for developersHello everyone,
For easy to use web clipping and application clipping tools and portal
development follow the link below:
http://clickmarks.com/solutions/portlet_solutions/portlet_factory.html
Cheers.
- 4
- Constraints in JPA (using Hibernate)Hi,
I have some @Entitys in JPA with Hibernate which create the following
relationship:
Brand 1<->* User
User 1<->* CreditCard
(where 1<->* means a bidirectional one-many relationship)
I want to be able to put a constraint on the CreditCard entity such
that the field CreditCard.CreditCardNumber is unique for a particular
Brand.
Without adding a reference to Brand in the CreditCard entity, is there
a way that I can achieve this?
Thanks in advance for any pointers!
Rich
- 4
- Question about help systemIs there a quick way to find out information about a particular method when
one doesn't remember to which class it belongs?
Thaks
- 4
- Why braces around try/catch?In article <3f3393b6$0$150$email***@***.com>,
Jos A. Horsmeier <email***@***.com> wrote:
>
>I beg to differ; catch clauses are optional as in --
>
> try {
> // some statements making
> // up the statement block
> }
> // no catch
I'm not sure what you mean. If I compile the above I will get a
compile error along the lines of
'try' without 'catch' or 'finally'
Cheers
Bent D
--
Bent Dalager - email***@***.com - http://www.pvv.org/~bcd
powered by emacs
- 6
- hai dearhai friends,
"each day is a new adventure to dream search and discover"
www.goodhistory5.blogspot.com
- 6
- RMI vs. Sockets vs. ?Hi,
In my graduate class we have to implement a distributed application
using Sockets and then again using Remote Method Invocation (RMI). Is
one more prevalent than the other in the "real world"? Or is there
something else that is used?
Just curious for my own knowledge and satisfaciton.
Thanks.
- 6
- JNDI/LDAP and PagedResultsControlI've encountered something that has stumped me for the past 2 days.
Perhaps someone on this list has seen this before or can explain why
this might be happening. I'm trying to use the SortControl and
PagedResultsControl classes that are part of the JNDI/LDAP Booster
Pack. In the code below, you can see that I create the 2 Control
object, stick them in an array, and set them as "request controls" for
the LdapContext. Thankfully, both the search and the sort controls do
the right thing - the items come out sorted with a page size of 10.
My issue is trying to get the "response controls" associated with
invoking the search() method on the LdapContext. According to the
JNDI JavaDocs, the getResponseControls() method "Retrieves the
response controls produced as a result of the last method invoked on
this context" (which in my case is the search() method). If I execute
a getResponseControls() call on the LdapContext immediately after the
search(), it returns null. However, after MUCH agonizing I figured
out that if I walk over the enumeration of results returned from the
search() method and do a getResponseControls() afterward, the proper
Control object array is returned (one for the SortControl and one for
the PagedResultsControl). I noticed that this was the common element
in code snippets I found on the Web that worked.
Can someone please explain to me why I have to walk through this
enumeration? I also verified that you have to walk over the entire
enumeration, not just an element or 2. Specifically, the hasMore()
method has to be called to get this to work. If I create a for loop
and walk through my page set (say 10 elements) and then try to get the
response controls, they're still null. It only works when hasMore()
returns false. This is really driving me bonkers?
Thank you in advance for anyone who can help me here!
String sortBy = "sn";
int pageSize = 10;
byte[] cookie = null;
int total;
Control[] requestControls = new Control[]
{
new SortControl(new String[]{sortBy}, Control.CRITICAL),
new PagedResultsControl(pageSize)
};
LdapContext ldapContext = new InitialLdapContext(environment, null);
ldapContext.setRequestControls(requestControls);
NamingEnumeration results = ldapContext.search(contextName,
searchFilter, searchControls);
//IF I DON'T WALK OVER THIS ENUMERATION, THE RESPONSE CONTROLS OBJECT
IS NULL
while(results != null && results.hasMore())
{
SearchResult entry = (SearchResult) results.next();
}
Control[] responseControls = ldapContext.getResponseControls();
if(responseControls != null)
{
for(int i = 0; i < responseControls.length; i++)
{
if(responseControls[i] instanceof PagedResultsResponseControl)
{
PagedResultsResponseControl p = (PagedResultsResponseControl)
responseControls[i];
cookie = p.getCookie();
total = p.getResultSize();
}
}
}
else
{
System.out.println("response controls is null");
}
ldapContext.close();
- 7
- Tomcat + Eclipse setupI have a brief question about my Tomcat config. I try to place the
webapps folder structure inside my Eclipse project strutcure, but
outside the Tomcat home directory. Example:
c:\Eclipse\MyProject
c:\Java\Tomcat\webapps
In order to do so I set in the server XML:
<Host name="localhost" debug="0"
appBase="c:\Eclipse\MyProject" unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
mywebapp.xml:
<Context path="/mywebapp" docBase="c:\Eclipse\MyProject\mywebapp">
Question: I would expect mywebapp.war to be automatically unpacked
when I place it in c:\Eclipse\MyProject (it's the appbase). That's the
way it works when I leave the webapp dir unchanged (inside tomcat
home). However, it does not work when I set the dir outside the tomcat
home dir.
Any hints would be appreciated.
Regards HW
PS: Tomcat 5.0.25 on Win2k
- 12
- Difference between Abstract class and interfaceHi,
Can you let me know the difference between Abstract class and
interface. I did research on the topic and found it helpful. Well, the
refined question I have is
1. Is there any difference between abstract class for which all the
methods are declared abstract and then an interface. I know that with
interface, multiple inhertiance can be achieved.
Can you please tell me in object tree/method invocation view.
thanks in advance
- 13
- my first bean (tomcat)Hello,
I'm getting more and more confused looking at old threads (and some are
very old) so I'll take the liberty of a new post for a very basic
question.
Why am I having a problem accessing my java class/bean from a jsp page
(which itself is running ok)? I'm running Tomcat 5 so I believe I need
a "myapp.xml" file in conf\catalina\localhost\ containing a context
element whose purpose is to associate an http call with the path of the
home directory where the class can be found (in \classes or in a jar in
\lib).
Then, in theory, 'jsp:usebean..etc.' will find the class I want.
Instead I get a stack trace including lines like this...
org.apache.jasper.JasperException: /jsp/listProgrammes.jsp(5,0)
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:150)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1227)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
(the top line is my jsp page which is trying to get hold of the bean)
Can anyone spell out the principles for me while I go away and check
for typos again? (Yes I have read some principles as explained in the
Tomcat docs but, well, it doesn't help for the moment.)
Many thanks
Ian
|
| Author |
Message |
Razii

|
Posted: 2008-6-4 1:17:00 |
Top |
java-programmer, benchmarks? java vs .net
On Tue, 03 Jun 2008 16:18:34 +0100, Jon Harrop <email***@***.com>
wrote:
>There is no merit in comparing unoptimized code on .NET with optimized Java.
That's why posted it here so you can "optimize it". You fixed
mandelbrot but C# is still twice slower in three other benchmarks:
binarytrees
(the command line argument should be -server -Xms64m binarytrees)
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=binarytrees&lang=javaxx&id=2
vs
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=binarytrees&lang=csharp&id=0
revcomp
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=revcomp&lang=javaxx&id=4
vs
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=revcomp&lang=csharp&id=2
sumcol
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=sumcol&lang=javaxx&id=4
vs
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=sumcol&lang=csharp&id=0
also, C# significantly slower in recursion
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=recursive&lang=javaxx&id=0
vs
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=recursive&lang=csharp&id=0
>I have seen is on the Mersenne Twister PRNG where Java is 2x slower than .NET.
Post the benchmark. Let me see...
|
| |
|
| |
 |
Razii

|
Posted: 2008-6-4 1:17:00 |
Top |
java-programmer >> benchmarks? java vs .net
On Tue, 03 Jun 2008 16:18:34 +0100, Jon Harrop <email***@***.com>
wrote:
>There is no merit in comparing unoptimized code on .NET with optimized Java.
That's why posted it here so you can "optimize it". You fixed
mandelbrot but C# is still twice slower in three other benchmarks:
binarytrees
(the command line argument should be -server -Xms64m binarytrees)
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=binarytrees&lang=javaxx&id=2
vs
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=binarytrees&lang=csharp&id=0
revcomp
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=revcomp&lang=javaxx&id=4
vs
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=revcomp&lang=csharp&id=2
sumcol
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=sumcol&lang=javaxx&id=4
vs
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=sumcol&lang=csharp&id=0
also, C# significantly slower in recursion
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=recursive&lang=javaxx&id=0
vs
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=recursive&lang=csharp&id=0
>I have seen is on the Mersenne Twister PRNG where Java is 2x slower than .NET.
Post the benchmark. Let me see...
|
| |
|
| |
 |
Razii

|
Posted: 2008-6-4 1:32:00 |
Top |
java-programmer >> benchmarks? java vs .net
On Tue, 3 Jun 2008 09:19:22 -0700 (PDT), "Jon Skeet [C# MVP]"
<email***@***.com> wrote:
>If Razii is genuinely comparing Java with Mono (I haven't looked at
>any of the figures) it's a silly test to start with (unless you're
>specifically interested in Mono, of course).
If you have no clue what is this thread about, why post at all?
|
| |
|
| |
 |
Jon Skeet [C# MVP]

|
Posted: 2008-6-4 1:51:00 |
Top |
java-programmer >> benchmarks? java vs .net
Razii <email***@***.com> wrote:
> >If Razii is genuinely comparing Java with Mono (I haven't looked at
> >any of the figures) it's a silly test to start with (unless you're
> >specifically interested in Mono, of course).
>
> If you have no clue what is this thread about, why post at all?
Well gee, you keep post URLs comparing Mono with Java. That's *not*
comparing .NET with Java - and is thus relatively pointless IMO. (It's
also made more pointless by you not mentioning in your blog post which
version of Java you're using, or which version of .NET.)
To make the conversation significant (well, as significant as this kind
of thing can be):
1) Don't bother posting about the Mono benchmarks at all. Keep it to
.NET and Java.
2) Explain the precise runtime environments.
The IO suggestions so far seem to be an indication of the general merit
of the benchmark, mind you.
--
Jon Skeet - <email***@***.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
|
| |
|
| |
 |
Jon Harrop

|
Posted: 2008-6-4 2:19:00 |
Top |
java-programmer >> benchmarks? java vs .net
Razii wrote:
> On Tue, 03 Jun 2008 16:08:17 +0100, Jon Harrop <email***@***.com>
> wrote:
>
>> BufferedStream s = new BufferedStream(Console.OpenStandardOutput());
>>
>>and the entire program becomes 2.5x faster.
>
> Yes, that was faster. I submitted it to shootout site. I am not sure
> if it will be faster on Mono too but I will let Gouy test it.
It makes no difference on Mono and the shootout does not test .NET.
--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
|
| |
|
| |
 |
Razii

|
Posted: 2008-6-4 2:21:00 |
Top |
java-programmer >> benchmarks? java vs .net
On Tue, 3 Jun 2008 18:51:10 +0100, Jon Skeet [C# MVP]
<email***@***.com> wrote:
>Well gee, you keep post URLs comparing Mono with Java. That's *not*
>comparing .NET with Java - and is thus relatively pointless IMO. (It's
>also made more pointless by you not mentioning in your blog post which
>version of Java you're using, or which version of .NET.)
The link I posted was this:
http://kingrazi.blogspot.com/
It's clear what it is about.
|
| |
|
| |
 |
Razii

|
Posted: 2008-6-4 2:24:00 |
Top |
java-programmer >> benchmarks? java vs .net
On Tue, 3 Jun 2008 18:51:10 +0100, Jon Skeet [C# MVP]
<email***@***.com> wrote:
>The IO suggestions so far seem to be an indication of the general merit
>of the benchmark, mind you.
The criteria is same for both sides. For now C# is slower by wide
margin in these benchmarks. How about fixing them? If you can't, I
will conclude C# is just slower.
binarytrees
(the command line argument should be -server -Xms64m binarytrees)
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=binarytrees&lang=javaxx&id=2
vs
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=binarytrees&lang=csharp&id=0
revcomp
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=revcomp&lang=javaxx&id=4
vs
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=revcomp&lang=csharp&id=2
sumcol
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=sumcol&lang=javaxx&id=4
vs
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=sumcol&lang=csharp&id=0
also, C# significantly slower in recursion
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=recursive&lang=javaxx&id=0
vs
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=recursive&lang=csharp&id=0
|
| |
|
| |
 |
Mark Thornton

|
Posted: 2008-6-4 2:33:00 |
Top |
java-programmer >> benchmarks? java vs .net
Jon Harrop wrote:
> Mark Thornton wrote:
>> Rather amusing really as unintentional use of unbuffered IO is a
>> frequent cause of Java benchmarks running more slowly than they should.
>> It seems that .NET copied that characteristic as well.
>
> Yes. I've no idea why they do that. Isn't buffered IO a better default?!
>
I think the reasoning is simplicity --- you create what you want through
composition of a smaller number of classes. Otherwise you need more
classes or extra options on constructors to provide for all possible
cases. Unfortunately they spoiled this a bit by providing a few
composites (java.io.FileReader for example). It is also a bit confusing
that InputStreamReader includes some buffering, but adding buffering to
an already buffered stream doesn't usually increase the cost by much.
Mark Thornton
|
| |
|
| |
 |
Jon Harrop

|
Posted: 2008-6-4 2:34:00 |
Top |
java-programmer >> benchmarks? java vs .net
Razii wrote:
> The criteria is same for both sides. For now C# is slower by wide
> margin in these benchmarks. How about fixing them?
I did.
> If you can't, I will conclude C# is just slower.
You had drawn that conclusion before you even tried to measure anything.
--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
|
| |
|
| |
 |
Jon Harrop

|
Posted: 2008-6-4 2:37:00 |
Top |
java-programmer >> benchmarks? java vs .net
Mark Thornton wrote:
> Jon Skeet [C# MVP] wrote:
>>> Does Java have anything comparable to .NET's Task Parallel Library?
>>
>> I haven't used it, but I've heard about Doug Lea's Fork/Join
>> framework:
>> http://gee.cs.oswego.edu/dl/papers/fj.pdf
>>
> I have used it and find it works quite well even without closures. I
> haven't used .NET so can't compare them.
The Task Parallel Library is awesome, even though it is only a CTP for now.
I highly recommend it. For example, read the article:
"Surviving in the multicore era with Microsoft's ParallelFX" - The F#.NET
Journal, 30th April 2008
http://www.ffconsultancy.com/products/fsharp_journal/?cs
--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
|
| |
|
| |
 |
Mark Thornton

|
Posted: 2008-6-4 2:38:00 |
Top |
java-programmer >> benchmarks? java vs .net
Jon Skeet [C# MVP] wrote:
>
>> Does Java have anything comparable to .NET's Task Parallel Library?
>
> I haven't used it, but I've heard about Doug Lea's Fork/Join
> framework:
> http://gee.cs.oswego.edu/dl/papers/fj.pdf
>
I have used it and find it works quite well even without closures. I
haven't used .NET so can't compare them.
For more information and downloads of the package:
http://g.oswego.edu/dl/concurrency-interest/
Mark Thornton
|
| |
|
| |
 |
Jon Skeet [C# MVP]

|
Posted: 2008-6-4 2:38:00 |
Top |
java-programmer >> benchmarks? java vs .net
Razii <email***@***.com> wrote:
> On Tue, 3 Jun 2008 18:51:10 +0100, Jon Skeet [C# MVP]
> <email***@***.com> wrote:
>
> >Well gee, you keep post URLs comparing Mono with Java. That's *not*
> >comparing .NET with Java - and is thus relatively pointless IMO. (It's
> >also made more pointless by you not mentioning in your blog post which
> >version of Java you're using, or which version of .NET.)
>
> The link I posted was this:
>
> http://kingrazi.blogspot.com/
>
> It's clear what it is about.
That was the link you posted *initially*. Since then you have posted
multiple links to http://shootout.alioth.debian.org which is about
Mono.
--
Jon Skeet - <email***@***.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
|
| |
|
| |
 |
Jon Harrop

|
Posted: 2008-6-4 2:38:00 |
Top |
java-programmer >> benchmarks? java vs .net
Razii wrote:
> On Tue, 03 Jun 2008 16:08:17 +0100, Jon Harrop <email***@***.com>
> wrote:
>> Java is still over 2x slower on both partialsums and
>>the Mersenne Twister.
>
> The partialsums is only slower due to trig accuracy required by Java's
> specification. Your C# results are not accurate enough to satisfy
> Java's specification. It's easy to solve this problem. Try this Java
> version of partialsums. It's two times faster.
But still 2x slower than everything else and now 2x more bloated as well:
C 1.300s
C# 1.363s
Java 2.750s
Java 3.840s (original)
> In binarytrees C# is twice slower. You haven't posted any workaround
> yet.
Optimizing binarytrees is trivial because the benchmark is fundamentally
flawed. I described this in detail on the shootout mailing list and urged
the maintainers to persue well defined benchmarks but they did not take
heed.
--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
|
| |
|
| |
 |
Jon Harrop

|
Posted: 2008-6-4 2:48:00 |
Top |
java-programmer >> benchmarks? java vs .net
Razii wrote:
> On Tue, 03 Jun 2008 19:37:57 +0100, Jon Harrop <email***@***.com>
> wrote:
>>But still 2x slower than everything else and now 2x more bloated as well:
>>
>>C 1.300s
>>C# 1.363s
>>Java 2.750s
>
> that's not what I get
>
> time java -server partialsums 2500000
>
> 0m1.697s
>
> and for Mono I get
>
> 0m1.525s
Yes. Mono is extremely slow. Almost as slow as Java on this benchmark. As we
have seen, .NET is much faster...
--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
|
| |
|
| |
 |
Razii

|
Posted: 2008-6-4 2:50:00 |
Top |
java-programmer >> benchmarks? java vs .net
On Tue, 03 Jun 2008 19:37:57 +0100, Jon Harrop <email***@***.com>
wrote:
>But still 2x slower than everything else and now 2x more bloated as well:
>
>C 1.300s
>C# 1.363s
>Java 2.750s
that's not what I get
time java -server partialsums 2500000
0m1.697s
and for Mono I get
0m1.525s
|
| |
|
| |
 |
Jon Skeet [C# MVP]

|
Posted: 2008-6-4 2:50:00 |
Top |
java-programmer >> benchmarks? java vs .net
Razii <email***@***.com> wrote:
> >The IO suggestions so far seem to be an indication of the general merit
> >of the benchmark, mind you.
>
> The criteria is same for both sides.
Um, the C# version (as posted on the site you've linked to below) uses
unbuffered IO while the Java version doesn't. They're just not doing
the same thing. Even if they were, that wouldn't give any meaningful
data about which language/platform "in general". It might help if you
happen to know that your code is going to require a huge amount of
recursion - to the extent that it's going to be the performance
bottleneck - *and* performance is your primary concern.
> For now C# is slower by wide margin in these benchmarks. How about
> fixing them? If you can't, I will conclude C# is just slower.
Feel free to draw that conclusion, while the rest of us instead
conclude that you can't claim that C# (which is a *language* after all,
not a platform) is slower or faster than another language.
Even running .NET rather than Mono will only go so far - you'd need to
run it on both 64 bit and 32 bit platforms, as the runtimes do
different things. (IIRC the 64 bit CLR uses tail recursion more heavily
than the 32 bit CLR, for instance.)
If I were to find a really slow JVM, would that prove that Java is a
slower *language* than C#?
I can easily write a benchmark where Java (under Hotspot) "beats" .NET:
just call a very small virtual method which is never overridden.
Hotspot will inline the call aggressively, as it is able to "undo" the
optimisation later on. .NET, with a single-pass JIT, won't do that.
Does that prove that Java is a faster language? No, not at all. It just
shows one area situation where it works better. It pretty much has to,
given that far more methods tend to be virtual in Java code than in
.NET code. I can probably find similar situations where .NET stomps
over Java (being able to create custom value types would probably be a
good starting point - force heap allocation and garbage collection in
Java but not .NET; even though it's fast, it's not free) - but that
wouldn't prove that .NET is faster than Java, either.
--
Jon Skeet - <email***@***.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
|
| |
|
| |
 |
Jon Skeet [C# MVP]

|
Posted: 2008-6-4 2:55:00 |
Top |
java-programmer >> benchmarks? java vs .net
Mark Thornton <email***@***.com> wrote:
> > I haven't used it, but I've heard about Doug Lea's Fork/Join
> > framework:
> > http://gee.cs.oswego.edu/dl/papers/fj.pdf
>
> I have used it and find it works quite well even without closures.
Cool - that's good to hear. I'd be very surprised if closures didn't
make it even simpler to use (possibly with a bit of refactoring towards
single-method interfaces if necessary).
Given the rest of Doug Lea's work, I'd expect it to be good :)
> I haven't used .NET so can't compare them.
Here's a little example from a Mandelbrot benchmark I was writing a few
weeks ago (oh the irony).
Simple initial code:
public override void Generate()
{
int index = 0;
for (int row = 0; row < Height; row++)
{
for (int col = 0; col < Width; col++)
{
Data[index++] = ComputeMandelbrotIndex(row, col);
}
}
}
Now using Parallel Extensions, and the lamdba expressions of C# 3:
public override void Generate()
{
Parallel.For(0, Height, row =>
{
int index = row * Width;
for (int col = 0; col < Width; col++)
{
Data[index++] = ComputeMandelbrotIndex(row, col);
}
});
}
I can't imagine many transformations being simpler than that - and the
results are great.
See http://preview.tinyurl.com/58vfav for rather more :)
> For more information and downloads of the package:
> http://g.oswego.edu/dl/concurrency-interest/
Thanks, will take a look.
--
Jon Skeet - <email***@***.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
|
| |
|
| |
 |
Razii

|
Posted: 2008-6-4 2:55:00 |
Top |
java-programmer >> benchmarks? java vs .net
On Tue, 03 Jun 2008 19:33:41 +0100, Jon Harrop <email***@***.com>
wrote:
>> If you can't, I will conclude C# is just slower.
>
>You had drawn that conclusion before you even tried to measure anything.
What the heck? I measured everything and posted the linhk. That's how
the thread started.
BufferedStream didn't help in sumcol
using (StreamReader r = new StreamReader(new
BufferedStream(Console.OpenStandardInput())))
makes no difference.
The only fix you have made so far is to mandelbrot. What about the 4
other I mentioned?
|
| |
|
| |
 |
Jon Skeet [C# MVP]

|
Posted: 2008-6-4 2:58:00 |
Top |
java-programmer >> benchmarks? java vs .net
Jon Harrop <email***@***.com> wrote:
> Mark Thornton wrote:
> > Jon Skeet [C# MVP] wrote:
> >>> Does Java have anything comparable to .NET's Task Parallel Library?
> >>
> >> I haven't used it, but I've heard about Doug Lea's Fork/Join
> >> framework:
> >> http://gee.cs.oswego.edu/dl/papers/fj.pdf
> >>
> > I have used it and find it works quite well even without closures. I
> > haven't used .NET so can't compare them.
>
> The Task Parallel Library is awesome, even though it is only a CTP for now.
Agreed. Now is a particularly good time to get into it, as the second
CTP has just been released:
http://blogs.msdn.com/pfxteam/archive/2008/06/02/8567093.aspx
> I highly recommend it. For example, read the article:
>
> "Surviving in the multicore era with Microsoft's ParallelFX" - The F#.NET
> Journal, 30th April 2008
> http://www.ffconsultancy.com/products/fsharp_journal/?cs
Or not, given that that's subscription only...
--
Jon Skeet - <email***@***.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
|
| |
|
| |
 |
Razii

|
Posted: 2008-6-4 2:58:00 |
Top |
java-programmer >> benchmarks? java vs .net
On Tue, 3 Jun 2008 19:37:47 +0100, Jon Skeet [C# MVP]
<email***@***.com> wrote:
>That was the link you posted *initially*. Since then you have posted
>multiple links to http://shootout.alioth.debian.org which is about
>Mono.
Huh? I will be polite for now and just say you didn't read the thread
carefully. The benchmark I tested are at that site. I don't have Mono.
I only have .NET.
|
| |
|
| |
 |
Razii

|
Posted: 2008-6-4 2:59:00 |
Top |
java-programmer >> benchmarks? java vs .net
On Tue, 03 Jun 2008 19:37:57 +0100, Jon Harrop <email***@***.com>
wrote:
>But still 2x slower than everything else and now 2x more bloated as well:
The FastMath class can be separated and used instead of java's Math in
all cases. The bloat is ZERO.
|
| |
|
| |
 |
Razii

|
Posted: 2008-6-4 3:00:00 |
Top |
java-programmer >> benchmarks? java vs .net
On Tue, 03 Jun 2008 19:48:16 +0100, Jon Harrop <email***@***.com>
wrote:
>Yes. Mono is extremely slow. Almost as slow as Java on this benchmark. As we
>have seen, .NET is much faster...
That was a typo. I don't have Mono. I get that with .NET.
|
| |
|
| |
 |
Jon Harrop

|
Posted: 2008-6-4 3:04:00 |
Top |
java-programmer >> benchmarks? java vs .net
Razii wrote:
> On Tue, 03 Jun 2008 19:33:41 +0100, Jon Harrop <email***@***.com>
> wrote:
>>> If you can't, I will conclude C# is just slower.
>>
>>You had drawn that conclusion before you even tried to measure anything.
>
> What the heck? I measured everything...
You only measured unoptimized C#. I have optimized the C# for you but your
response has only been to cherry pick results that back the conclusion you
wanted to draw.
> The only fix you have made so far is to mandelbrot.
Have you already forgotten that you were not compiling the regular
expressions in the C# implementation of regexdna?
> What about the 4 other I mentioned?
You said ".NET is twice slower in four benchmarks: binarytrees, mandelbrot,
regexdna, sumcol.". I have already corrected two of your results (mandelbrot
and regexdna) and provided two more counter examples where .NET is >2x
faster than Java and explained why binarytrees is flawed.
--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
|
| |
|
| |
 |
Razii

|
Posted: 2008-6-4 3:05:00 |
Top |
java-programmer >> benchmarks? java vs .net
On Tue, 3 Jun 2008 19:50:21 +0100, Jon Skeet [C# MVP]
<email***@***.com> wrote:
>Um, the C# version (as posted on the site you've linked to below) uses
>unbuffered IO while the Java version doesn't. They're just not doing
>the same thing.
What benchmark are you talking about? Changing the line to
using (StreamReader r = new StreamReader(new
BufferedStream(Console.OpenStandardInput())))
didn't make a difference in sum-file benchmark.
By the way, StreamTokenizer is not buffered. It reads a byte each time
from the stream. It maybe that System.in is buffered by default in
Java.
|
| |
|
| |
 |
Jon Harrop

|
Posted: 2008-6-4 3:06:00 |
Top |
java-programmer >> benchmarks? java vs .net
Razii wrote:
> On Tue, 03 Jun 2008 19:48:16 +0100, Jon Harrop <email***@***.com>
> wrote:
>>Yes. Mono is extremely slow. Almost as slow as Java on this benchmark. As
>>we have seen, .NET is much faster...
>
> That was a typo. I don't have Mono. I get that with .NET.
Java is 2x slower than .NET on my AMD64 for this benchmark. What CPU are you
using?
--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
|
| |
|
| |
 |
Jon Harrop

|
Posted: 2008-6-4 3:07:00 |
Top |
java-programmer >> benchmarks? java vs .net
Razii wrote:
> On Tue, 03 Jun 2008 19:37:57 +0100, Jon Harrop <email***@***.com>
> wrote:
>>But still 2x slower than everything else and now 2x more bloated as well:
>
> The FastMath class can be separated and used instead of java's Math in
> all cases. The bloat is ZERO.
So having to write your own basic trig functions in Java so that you can be
only 2x slower than other languages doesn't bother you?
--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- A bafflement moment on enumI have written enum code that works, but suddenly I had a sinking
feeling that it has no business working. I did a little disassembling
and sorted out the mystery.
let's say I create an enum with method next().
Then I override the next() method with custom code in the various
enum constants.
These methods live in anonymous inner classes of the enum (though
oddly they decompile as static).
Then I do something like this:
Breed d = Breed.DALMATIAN;
d.next();
How on earth does Java know to use DALMATIAN.next() rather than
Breed.next()?
The answer is that d contains a reference to the DALMATIAN inner class
that EXTENDS the Breed enum class as well as being an inner class of
it. So the next() method overrides the one in the Breed class.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
- 2
- [ANN] Scala 2.5.0-RC2 releasedWe are pleased to announce version 2.5.0-RC2 of the Scala distribution:
| Scala smoothly integrates features of object-oriented and |
| functional languages and is fully interoperable with Java |
It fixes several bugs found in RC1.
http://www.scala-lang.org/downloads/changes.html#v2.5.0-RC2
Other release candidates may follow this version depending
on bugs reported by the Scala community (no changes/additions,
only bug fixes!); the final release (aka. 2.5.0-final) is
planned in 1-2 weeks.
Bye
-- Stephane
- 3
- constructor inheritance/overriding?If I have a base class with some over-loaded constructors
that perform significant work before calling the
"main" constructor, what is the best way of achieveing
the same set of constructors in a sub-class?
e.g.
class B {
B(A a) {
... lots of stuff ...
}
B(D d) {
this(get an A from the d);
}
B(S s) {
this(get an A from the s);
}
}
class E extends B {
E(A a) {
super(a);
addition 'E' specific code
}
}
How do I implement E(D d), and E(S s)?
As I understand things, constructors are not inherited (unlike C++),
so I do need an explicit implementation of each constructor. But the
"obvious" minimal implementation:
E(D d) {
super(d);
}
would call B(D d), which would then call B(A a).
Thus the extra 'E' specific code would NOT be called.
I don't (unless I must) want to expose the inner workings
of the other constructors in 'B', for reasons of data hiding
and code maintainance.
This question must have arisen before, but my googling failed
me.
Anyone have a solution?
BugBear
- 4
- How to start default browser when clicking on a labelHi,
I was wondering how I can implement a JLabel that references to a http link.
When I click that label the default browser should open and loading the webpage.
This is for a JDialog 'About' window.
I've seen this several times, but I've no idea how to implement this with
Java/Swing.
Regards,
Helmut
- 5
- algorithm - how to estimate time to completeNot a problem as such, just a question about estimating time for producing
algorithms.
I recently had to write a class with a method that was to convert digits
(int) into their 'word' representation.
To begin with, converting say, 234, into "two three four", was easy enough.
But the method was also to 'sound english'
So, 234 now had to be converted to:
"two hundred and thirty four"
Some other examples:
"six million, three thousand and fifty six"
"six billion and one"
"eight billion,six million, three thousand, fourhundred and fifty six"
(like the way a person may write on a cheque underneath the digit amount.)
I wrote such a method. (which was actually a little more invoved than this
as it supports currencies, floating point number etc;) But, only after badly
underestimating the time involved for me to do so. There were were a few
elemenst about it that were not so obvious until I sat down to write it. I
ended up scratching a lot of stuff down on paper, and wrote it 3 times till
I was happy with it.
I have two questions here:
What is the best way to estimate time for rather small tasks like this? How
to you determine if a job will take an hour, a day, or a week? I know it
seems like a silly question - but I am just keen to see what sort of
responses come back from it.
Secondly, how long do you think it would take you to write a method such as
this? Personally, I allowed an hour and a half, and, like I said, was badly
mistaken. I know I took longer because I trivialised the problems till I ran
into them in live code, but still, it took way longer than I expected. (It
took me a whole day and a bit of the next day)
TIA
- 6
- java.lang.NoClassDefFoundError: org/aspectj/lang/SignatureHi,
Can anyone help me for this exception which I am getting whil trying to
conenct to MYSQL server thru TOMCAT.
Thanks
Maneesh
org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver
class 'com.mysql.jdbc.Driver', cause:
java.lang.NoClassDefFoundError: org/aspectj/lang/Signature
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at
org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:730)
at
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:518)
at foo.DBTest.init(DBTest.java:23)
at org.apache.jsp.test_jsp._jspService(test_jsp.java:51)
at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at
org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:595)
- 7
- jikes dependenciesHi,
I try to find all the dependencies of a class file (which are the
class to recompile when I modify just one java file).
According to Jikes website, "C depends on D if and only if the
constant pool for C contains a reference to D".
So, for a particular class, E, I found with Jikes the following
dependencies :
A, B, C, D.
At the same time, I used the BCEL library from apache to have a look
at the constant pool and I just find references to the class A, B and
C.
The class C is a parameter of one method of my class E and the class C
implements the interface D.
I understand why the class E depends on the class D.
Is the Jikes assertion incomplete or should I understand "C depends on
D (and all its ancestor/interfaces) if and only if the constant pool
for C contains a reference to D" or maybe even "C depends on D (and
all its dependencies) if and only if the constant pool for C contains
a reference to D"??
Thanks for your help.
Eric Deshayes
- 8
- IDE for JFSWhat IDE you would recommend for JSF based J2EE development using JBOSS
AS.?
- 9
- JSP Tomcat link directoryes from 2 projects, help pleaseHi Everyone,
I have 2 Tomcat jsp projects which use many common directoryes. I wont
the directory from the second project linked to a directory from the
first, so I can change files on a single place. When I use something
like $ln -s ../project1/visualization ./visualization
and then make request from mozilla I get the error The requested
resource (/visualization/grid.jsp) is not available.
Any ideas
- 10
- struts action quiestionHello,
I have a short question concerning struts action context stack. I have 3
views. View A, B and C
To view C, I can get from view A, or B. In view C I have button "BACK",
Whenever I click BACK button, I want to go back to page that called view C
(A od B).
Is there any way to do it (remember calling view), or I have to implement my
own context stack mechanizm ?
thank you,
fera
- 11
- addRow error when further editing is doneHi All,
Quick question (hopefully an easy answer).
Using JBuilderX--a GUI with a JTable component, I click a button
calling a method that adds a new row to a TableDataSet table in the
Database. This code in a datamodule class method:
openIMTable();
DataRow item = new DataRow(imTable);
item.setString("COLUMN1", "SOME TEXT");
imTable.addRow(item);
Returning to the GUI, the row is visually added, everything is fine.
The new row is highlighted in the JdbTable component. I click on an
empty column field in the new row and type some info--press Enter and
get the following error message: "Unable to set value because could
not post or leave row 0". If I select a different row with the mouse
and then reselect the "new" row I can add other fields with no
problem.
What am I missing?
TIA
Mark
- 12
- Castor XML Question: How to ignore wrapping elementsI have an xml file that looks something like:
<Response>
<Invoice>
<PrimaryKey>239</PrimaryKey>
<OrderTotal>5893.03</OrderTotal>
</Invoice
</Response>
I am trying to map <Invoice> to my Invoice.java class. How do you get
Castor to ignore the outer <Response> tag? I could always do
pre-processing, but I would like to know if it's possible to do this
in the mapping xml file.
Thanks,
Ankur
- 13
- Linking native libraries in Win2KHi there,
I'm trying to get some 3rd party "Kit" working and I'm struggling
with a java.lang.UnsatisfiedLinkError.
What I use is IBM's Visual Age 3.5.3 (JDK1.2.2) and the library in
question is IBM's OnDemand 7.1.0.7.
What I did was to copy all the DLLs and INIs etc. from the
"IBM\OnDemand Web Enablement Kit" into my WINNT\system32 folder -
where they should be found by any app, because it is listed in my
PATH.
However, I get an UnsatisfiedLinkError and I don't even know which
library it is actually looking for, as the stack trace
java.lang.UnsatisfiedLinkError
java.lang.Throwable()
java.lang.Error()
java.lang.LinkageError()
java.lang.UnsatisfiedLinkError()
int com.ibm.edms.od.ArsWWWInterface.initialize(java.lang.String,
int)
int com.ibm.edms.od.ArsWWWInterface.initialize(java.lang.String,
int)
int com.ibm.edms.od.ArsWWWInterface.init(java.lang.String, int)
void com.ibm.edms.od.ODServer.initialize(java.lang.String,
java.lang.String)
does not really help and I found when trying to catch this and dump
the name of the library was "null".
I somehow can't believe I'm the first one to struggle with this.
Any help is greatly appreciated.
Thanks,
Martin
- 14
- Multiple server access jdbc/servletIf I have an applet, which is donwloaded to the local machine from server
A, and calls a servlet on server B.....can that servlet, via JDBC, access a
database on server C, assuming each of server's A, B and C are on separate
machines with separate URLs ?
Thanks, Ike
- 15
- Not debugging?Phlip wrote:
>
> Duane Bozarth wrote:
>
> >> The define "legacy" as "requires debugging".
> >
> > That's a bizarre (at best) definition of "legacy"...
>
> That's why Greg didn't understand why I used it like that.
I didn't either (and still don't) because it has nothing whatsoever to
to w/ "legacy" or not...
> Me: Strive to never debug.
>
> Greg: What about blah blah blah.
>
> Me: You are using something that you can't design
> fresh from scratch to resist bugs. So you must
> run the debugger more often than greenfield code
>
> Greg: It's not "legacy" it's embedded blah blah blah
In that sense everything is "legacy" -- I can't redesign a commercial
compiler, either.
...
> Just don't leave the emulator out of the loop. Greg implied using it would
> slow down the tail end of development.
At some point in most embedded systems, that <is> true...you get to a
point at which the depth of emulation required isn't worth the effort
that would be required. Once at that point, reverting is rarely
productive use of resources.
|
|
|