The Artima Developer Community
Sponsored Link

Java Answers Forum
Difference in Java performance between Mac and PC

6 replies on 1 page. Most recent reply: Sep 3, 2005 10:40 AM by Will

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 6 replies on 1 page
Will

Posts: 20
Nickname: lofty
Registered: Mar, 2005

Difference in Java performance between Mac and PC Posted: Sep 2, 2005 5:50 AM
Reply to this message Reply
Advertisement
One of the things that attracted me to Java was the so called "write once, run anywhere" nature of the JVM, and although I believed it all at the time I"m beginning to wonder if the doubters weren't right.

In some ways this is a good thing though - I was writing a small app for my brother in law on my Mac - which he will run on a PC. I got fed up with Eclipse running at snail pace on the Mac, so switched to the PC, and found quite a difference. One example:



//Action Event Stuff

if(e.getSource()==dateBtn) {
if(boughtOnTF.getText().equals("") {
boughtOnTF.setText( sdf.format(cal.getTime())
}

else if (soldOnTF.getText().equals("") {
soldOnTF.setText("sdf.format(cal.getTime())
}


The idea was to only input the date into one or other textfields, the decider being whether the first field was already occupied. I know this might not be good Java, but it worked fine on the Mac. On the PC, both textfields are filled with the date - as though the "else if" is being ignored. I've tried loads of ways round this, like finding which field lost focus prior to the button click, or setting a boolean value to true if the first field is populated, but it still seems to fill both (or neither).

I know this sounds like a real dumb suggestion but I wondered if because my PC is so much faster than the Mac, the second statement is executing before the first one has been completed? Yes I know that's stupid, but at 12pm last night it started to make sense ;)

Any help on that bit of code would be very welcome - as would any other things I ought to watch out for when coding on the PC when I"m used to the Mac.

Many thanks :)


Will

Posts: 20
Nickname: lofty
Registered: Mar, 2005

Re: Difference in Java performance between Mac and PC Posted: Sep 2, 2005 5:52 AM
Reply to this message Reply
Sorry, code formatted properly:

//Action Event Stuff
 
if(e.getSource()==dateBtn) {
if(boughtOnTF.getText().equals("") {
boughtOnTF.setText( sdf.format(cal.getTime())
}
 
else if (soldOnTF.getText().equals("") {
soldOnTF.setText("sdf.format(cal.getTime())
}

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Difference in Java performance between Mac and PC Posted: Sep 2, 2005 6:34 AM
Reply to this message Reply
//Action Event Stuff
if(boughtOnTF.getText().equals("") {
    boughtOnTF.setText( sdf.format(cal.getTime())
}
 
else if (soldOnTF.getText().equals("") {
   soldOnTF.setText("sdf.format(cal.getTime())
}


Your boughtOnTF and soldOnTF must be pointing to the
same Object hence regardless of the logic statement they
will both either be filled or not (nothing to do with
execution speed).

What you could do is post the section of code where you
declare and instantiate the to textFields, where you
have the statements (and make sure they are declared
separately) like so:
JTextField boughOnTF = new JTextField(12);
JTextField soldOnTF = new JTextField(12);

and hopefully at some point you did not say
boughOnTF = soldOnTF;

or have a scenario where you equate non-primitive
attributes - which depending on where and how you
did this it would explain the behaviour.

Will

Posts: 20
Nickname: lofty
Registered: Mar, 2005

Re: Difference in Java performance between Mac and PC Posted: Sep 2, 2005 6:55 AM
Reply to this message Reply
Thanks for the reply,

Both fields are declared separately, and at no time have I equated one to the other. I'm not totally sure what you mean by equating one or other to non primitives, but I'm guessing it sort of amounts to the same thing? This is the only point in the class where I've done anything with the textfields, other than adding them to the gui.

From what you're saying though, it sounds as though you think the code should work? I was wondering if the Mac was being lenient on some duff code, when the PC was being more rigid about it?

Apologies for the mistakes in the code posted - I couldn't find any way to edit it, but the code in the class doesn't have the same errors.

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Difference in Java performance between Mac and PC Posted: Sep 2, 2005 7:26 AM
Reply to this message Reply
Its almost beer time so, I'll give it a last shot.

> From what you're saying though, it sounds as though you
> think the code should work?

In all honesty, I'm a Pos programmer, I work with Swing
every day of my life for 9+ hrs a day (on PC/Linux), JTextFields are pretty much stable. So I really
think there is definitely something wrong at some
point in your code, its definitely doing what you
coded it to do. Yes it should evaluate one or the
other, but the point is you have an object called
sdf or something like that? What exactly is it
holding? And to which class is it an attribute of?
That's where you could find your crossing the objects
to be holding similar values. Can't tell much from
that little snippet though.

> Apologies for the mistakes in the code posted -

No worries.

Anyways, good luck with your project, sorry I couldn't
be of more help. But I don't want to be scrounging
on your hard work and have you give too much detail
of your code - lest I be accused of copyright
infringement. Enjoy the weekend.

Spike

Will

Posts: 20
Nickname: lofty
Registered: Mar, 2005

Re: Difference in Java performance between Mac and PC Posted: Sep 2, 2005 8:45 AM
Reply to this message Reply
Hi Spike,

You're probably already in the pub, but I'll reply now while it makes sense to me ;)

The sdf is a Simple Date Format object from the Text class, so I'm just asking it to enter today's date in the textfield when clicked - the idea of only filling the soldOn field if the boughtOn field is already full is that the user may want to come back to some details originally entered some days earlier. Whatever, I don't think that should be causing the problem, but I"ll look through all the rest of it again (and again).

You're welcome to see the full code any time - I seriously doubt you'd want to steal it :D

Thanks again, and a good weekend to you too,
Will.

Will

Posts: 20
Nickname: lofty
Registered: Mar, 2005

Re: Difference in Java performance between Mac and PC Posted: Sep 3, 2005 10:40 AM
Reply to this message Reply
Sorted it - I had a curly brace in the wrong place so the code was executing regardless of the if/else statements.

Thanks again :)

Flat View: This topic has 6 replies on 1 page
Topic: jdbc connect to oracle Previous Topic   Next Topic Topic: JTable question

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use