Erik Larson

Greenhorn
+ Follow
since Apr 25, 2005
Merit badge: grant badges
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Erik Larson

Is the Beagle Board a viable alternative to the G1 dev phone for development?
15 years ago
There is a new Tray Icon API project that I saw on java.net. Check it out!

Tray Icon API

There is a JWS demo, and it works just fine on my Win2k machine. This may not help you now, but in the future it might be an option.
18 years ago
First, this code does not compile. Maybe you mean vec[i]. Secondly, what is d? Use descriptive variable names so you can understand the intent of the code just by looking at it. How many times will the loop in insert execute?

In general, when you insert a value into a array, the size of the array changes, unless you are implementing a stack or queue structure. So you either have to bump an int out of the array, or increase the size. What are you trying to do?

Think about the purpose of n and d and if you really need them. If you can't come up with a good name for what they are for, that is a clue that maybe they aren't neccessary.
18 years ago
Imagine the code is running. What will the while condition evaluate to? If you enter the loop, what happens next?
18 years ago
'\101' is an octal representation of a number. The largest printable character is 255 decimal, or 377 octal. What is interesting is that if you assign the decimal value of '\1001' (513) to a char, that will print '?'. Why that is, I don't know. As for the unicode values, they must be exactly 4 hex digits.

'\101' == 0101 == '\u0041' == 0x41 == 65 == 'A'
[ May 25, 2005: Message edited by: Erik Larson ]
18 years ago
Just write the stream to a temp RandomAccessFile...



Probably not the most efficient, but it works.

[Ed. Changed main() to a more exciting demo]
[ May 18, 2005: Message edited by: Erik Larson ]
18 years ago
I wouldn't worry about a package just yet. Seems like you are just starting in Java and you can worry about that later. You do have a syntax error in the print statement in TestCar. The method gasLeft has no parameters, but the () still need to be there to tell the compiler you are calling a method.
18 years ago
It took me a while to recreate your problem, but I finally did. The synchronization is not really the problem. I did tests and I did not see an instance in which two Threads had access to the Server.customer at one time. Where the problem comes in is that you are returning a reference to the Server.customer. This same reference is then locked by the next Thread that tries to access the GetSet method. The problem is that on the client, you use the same reference. Scenario:

1. Client 1 calls GetSet()
2. GetSet() returns with Server.customer reference, values set to Client 1
3. Context switch to Client 2.
4. Client 2 calls GetSet()
5. GetSet() returns with Server.customer reference, values set to Client 2
6. Context switch to Client 1.
7. Client 1 prints customer.toString() with values from Client 2 because customer in Client 1 holds the same reference, but with updated content.

My solution was to make Customer implement Cloneable and return a clone of Customer from getCustomer(). I'll put all my code in here...

Customer.java


Server.java


ServerImple.java


ThreadedCustomer.java


Hope this helps!
18 years ago
Not sure how you could do that. But why use Windows Scheduler? Why not write your own scheduler that checks the state of your app every X minutes, and if it is not running, your scheduler spawns a new thread that starts it.
18 years ago
I ran into the problem with static data in an inner class recently.

This site

Nested Classes

gives a good short description of inner classes. A non-static inner class is associated with an instance of a class, not the class itself. That's why the inner class can access "this" for the enclosing class. So declaring something static in the inner class would only be accessable to that instance, which defeats the purpose of it being static. If you don't need direct access to the enclosing class instance (this, or its members directly), try declaring the inner class static.
[ May 17, 2005: Message edited by: Erik Larson ]
18 years ago