JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't want to hijack this thread, so just a quick (final) comment - even with multiple parsing classes, when dealing with a user input you will still need to know which class to use to parse it, so that just moves the "god" code to a less generic place. However, I do agreee with your second para re cohesion - good point. Maybe it would be better to use a parser that also takes a format definiton string, like SimpleDateFormat?
Final comment for TheComputerGuy - if ever there was an open-and-shut case for using enums it's CardRank and Suit. Right now I can't think of a single better example of when to use enums - even the Planets example used by Sun in the original documentation looks shaky now that Pluto has ceased to be a planet!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I agree with ~s.o.s~, except why define a CardParser interface? Why not just have a CardParser class that's smart enough to parse any sensible representation? If you onlyhave one class, then why bother with the interface. If you have 2 or mnore pareser classes how will you code the logic for which one to use?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did you import SimpleDateFormat and Date ?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Since nobody more knowlegable has answered, here's my attempt.
Swing thinks that it is in charge of what gets painted when because it is responsible for calling the various paint methods. If you go ahead and do painting activities that Swing doesn't know are happenuing then either they won't make it all the way to the screen or they will get over-painted at random by Swing.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Forum rules say I can't write your code for you, but here are some hints:
the method header says you will return an object of type Set<Food>
So somewhere in your method you need to declare one, populate it with zero or more Food objects, then return it in the return staement.
I have no idea how we got from characters to Food - what's your REAL question?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Set<Character> myMethod(String arg)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

One last time: it's the variable GlobalVariables.status that you need to look at. Your enum is OK.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You didn't read my post properly. GlobalVariables.BetfairStatus.CONNECTED is NOT waht I said to print.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Try printning GlobalVariables.status, maybe you haven't initialsed it?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Add some print statements so you can see what is (or is not) happening exactly.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Please mark thread as solved, so everyone else knows not to try to asnswer it! J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I really don't approve of global variables. IMHO you should always make variables private and use get/set methods. But if that's the way you want to do it...
In your globals you need the enum to define the possible values, plus another global variable that holds the current value:

public static enum BetfairStatus{NOT_CONNECTED, CONNECTED};
public static BetfairStatus status;

then, in the other modules:

GlobalVariables.status = BetfairStatus.CONNECTED;
or
if (GlobalVariables.status == BetfairStatus.CONNECTED) ...
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are trying to use the enum as if it is a variable. Your code should look more like this...


BetfairStatus status = ...
if (status == BetfairStatus.CONNECTED) ...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Declare them public, import the package, refer to them by fully-qualified name.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can use an ObjectOutputStrem / ObjectInputStream via you sockets to send a set of results. If all the calsses & subclasses are serialisable that simply works. If not, extract the data into something that is serialisable and send those.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have a look at your jar using a standard zip file utility (whichever you prefer) and check the exact path and file names for the files you need. If you're using Windows, watch out for upper/lower case in the names - the Windows file system is not case sensitive, but opening a file from a jar in Java is.
You don't really need URLs, something as simple as this will work:

BufferedImage image = ImageIO.read(getClass().getResource("/dir/file.png"));

or use
public InputStream getResourceAsStream(String name)
from the Class class to read text, eg

InputStream in = getClass().getResourceAsStream("/stuff.txt");

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Idempotent, both.
5$ + 5$ is always 10$
jan + 1 month is always feb

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Consider these two methods:
int sum(int a, int b) idempotent - every call gives same result
void writeToDatabase(String a) not. database gets bigger with every call

or

String toString() idempotent
int getNextPrimeNumber() each call gives a different result

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

1. If you create few instances of a class, each instance has its own variables (unless the variable is declared "static"), which can be, probably will be, different.
"this" always refers to the current instance.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Previous answer is 90% right, but, as defined in the Java language definition, the JVM has no problem deciding which variable to use.
Declaring x as a parameter "masks" or "hides" the declaration of the instance variable x, so an unqualified use of x in that method is a use of the parameter. So in the example
this.x = x;
this.x is an unambigious use of the instance variable, and
= x; is an unambiguous use of the parameter

Re methods:
The new class example makes no sense - probably confusion of "class" vs "instances of class". If this is what was intended:
this.someMethod(); // where this is an instance of SomeClass, vs
new SomeClass.someMethod();
In the first case the method will execute using the instance variables from the current instance ("this"). In the second case it will use the instance variables from a different (new) instance.

Interfaces are too big a topic to ask anyone to write you a tutorial. Here's a good place to start:
http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/java/concepts/interface.html
followed by:
http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/java/IandI/createinterface.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... or simply use an array
double[] car = new double[3]
car[0] = ...
car[1] = ... etc

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

u can check out all the string function here

http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html

This link is to the Java 1.3 documentation, which is years out of date!
The language was very significantly updated in version 1.5.
Google your way to 1.5 or (even better) 1.6 docs.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

To check in middle you have to use a substring function to extract the particular pattern and then compare it....

Not true. Use contains(...)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have a look at the contains(...) method in the String class (ps: in case you are worried, CharSequence is just an Interface implemented by all Strings)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This is a kind of non-question. results cannot be accessed before line 8, so whether or not there is still a little block of memory allocated to it there is irrelevant. At line 8 it's declared, so its value is given by the initialisation expression (or is null if there isn't one), so any hypothetical previous value is lost before you can use the variable again (in lines 9-14).
If the reference were "revived", that would be a definite violation of the language definition, and a serious bug.
Similarly, it's irrelevant exactly when the reference counter gets decremented because there is no guarantee about when the un-referenced object may get GCed; it's just "some time later". Either way, you can't access it any more.
I just think your code's author is wrong. Line 13 is redundant in that particular case (but, for example, if results were declared as an instance variable of the class, line 13 would be useful)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Local variables do not get garbage collected. They are allocated on the stack and thus automatically lost when the block is exited (the block in this case being the while {...}). The objects to which the variable refers are not on the stack, and are eligible for GC when there are no longer any (strong) references to them.

Sun says:
14.4.2 Scope of Local Variable Declarations
The scope of a local variable declaration in a block (§14.2) is the rest of the block in which the declaration appear.

Thus the scope of this variable is from line 8 to line 14
Contrary to my over-simplified earlier post, when the execution returns to line 2 as part of the looping, the variable is out of scope, and any reference it may have held is no longer valid.
QED I belive the nulling on line 13 is redundant.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It seems to me that the variable results is declared in the scope of the while {...} block, and will remain in scope until the while loop is exited. At this point it beomes impossible to use that variable in any more code, so the question of exactly when its memory becomes free is an implementation detail irrelevant to the correct execution of the program. Similarly, if this is the last remaining strong reference to some object the object will subsequently become eligible for garbage collection, but since that says nothing about exactly when it will be garbage collected, that's also an irrelevant implementation detail.
As for "clearing the variable": setting it to null, if it was the last strong reference to some object, the object will subsequently ... (as above), regardless of any scope issues.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If I understand the question, then the answer is "yes", but why do you ask, and what do you want to infer from the answer?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Methods, both static and instance, are loaded into the VM when the class is loaded. Only one copy of each method is loaded and held in memory.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

ob is a reference to an object of class A.
It can also hold a reference to an object of any sub-class of A, because any such object is, by definition, a kind of A.
new X() creates an object of class X and returns a reference to that object.
If you define a reference variable but do not assign any value to it, its value will be the special value "null"

Experienced Java programmers tend to talk about an "object" when they really mean "reference to an object", which can be very confusiong for beginners.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How much spare time do you think we have? Make the effort to read some of the stuff that's already available to you on the web, then come back here if you have specific problems.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You may find that this is a problem with keyboard focus - are you sure the focus is on your JLabel? Try clicking it once then pressing a key.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK that's great. Mark this thread "solved"?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... or declare it within the main method without the static.

Your new error says it all - how can I make "java.sql.SQLException; must be caught or declared to be thrown" any clearer?
You have to catch SQLException OR declare the enclosing method as throwing this exception (wrong choice!).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sun's documentation states "The default class path is the current directory".

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That was a good guess, 19 is my lucky number.
Anyway - you declared con in a try{} block - so its scope is limited to that block. Line 19 is outside the block, so con is out of scope. It's all a question of where you declare it...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

On which line?
Or shall I guess? ... I see a line number with two digits ... the first looks like a one, the second is .... wait for it ... a nine?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, import does nothing that you can't do by always using the fully qualified names for all the classes you use. This saves a LOT of typing

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

out should contain a single number, not a list of numbers with \n between them!
Format each number separately, then concatenate all the formatted versions.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Java has a Preferences class that's ideal for what you need. It's as easy as

Preferences prefs = Preferences.userRoot().node("myEditor");
prefs.putBoolean("lineWrap", true);
...
if (prefs.getBoolean("lineWrap", false)) ...

UI should be a dialog, and keeping it modal makes coding, and using, it easier.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have a look at NumberFormat and its getCurrencyInstance() method ;-)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I didn't expect that code to work unchanged in your app - but it does give you the correct algorithm and loop structures for you to tailor to your own code. Check out the error message carefully - most Java error messages are very good at telling you exactly what you need to know.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I Googled "java bubble sort"
The third hit was http://www.informit.com/articles/article.aspx?p=31526&seqNum=2
This includes the following source code

public void bubbleSort()
   {
   int out, in;

   for(out=nElems-1; out>1; out--)  // outer loop (backward)
     for(in=0; in<out; in++)    // inner loop (forward)
      if( a[in] > a[in+1] )    // out of order?
        swap(in, in+1);     // swap them
   } // end bubbleSort()

Which, as you can see, has two nested loops where you just have one loop

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Google.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need to look again at the algorithm for bubble sorting - it needs two nested loops and you've only got one. Also arr[x+1] is going to fall off the end of the array with your current loop.

ps: "I know the brackets are off a bit" - that's inexcusable. You will never be able to debug a program properly without being able to see which } goes with which {. If you haven't already, download a proper programmer's editor that will do it for you, or use a proper IDE such as Eclipse or Netbeans

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Not sure wht's going on here, but DeadSoul's post (the first one, not the insult) is incomplete. His instrctions give you the .java file, but you need a .class or a .jar to run the program (just like chirag said).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you try to display one of your Items, Java uses the Item's toString() method to get a displayable version. You are getting the toString() inherited from Object, which just gives the name of the class and an incomprehensible object reference.
Define your own public String toString() method in the Items class to return a String that makes sense to you (eg "Item: " + name + " price:" + price) and Java will use that to display the Item.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The message says it all. sortPrice is an instance (AKA non-static) method that needs a single instance of the class to execute again. You're calling it from your static main method, so there is no instance of the class.
The quick fix is to declare all the methods in CoffeeDriver static, but personally I think the sort methods belong in the Item class not in the test driver. I would consider moving them to Item, make them static, and call them as Item.sortPrice(...) etc. OR make a class to represent a collection of Items with methods to add Items to the collection, and sort it in different sequences. The last solution would probably be best in a real-life application becuase it will cope with far more of the complexity and variations that plague real life.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

import statements go before anything else in the .java file (except a package statement). If you want to use API classes like Calendar in your code you must either import them first, or use their fully qualified name (ie java.util.Calendar ) every time.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did you import java.util.Calendar; ?