Olivier Legat

Ranch Hand
+ Follow
since Nov 17, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Olivier Legat

Howdy fellow coders,

I have a question about generic arrays. I have this function.

Which compiles when placed in a my ArrayUtil class. However whenever I use it I get an exception.

Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.StackTraceElement;


This is probably because of my (T[]) cast. The compiler won't let me create a generic array T. So how can I fix this problem?

Thanks in advance.
12 years ago
Concerning the setters and getters it's simply a matter of convention. You could ignore these fnction and keep your variables public, but this might be seen as untidy or unprofessional by some programmers. So, not knowing your Professor personally, it's best to stick to conventional coding

Regarding the for-loop, I don't think you've understood what a for-loop does. Think of it like this:


So all you in fact is:
12 years ago

fred rosenberger wrote:This is not the right approach.

You're idea of using parallel arrays to store these values is not an easy one to maintain. If a copy of "Saw" is lost, it gets tricky on how you delete it, and deleting the last one is much trickier than deleting the 4th from last one.

The idea in OOP is that you try to model the real world with your Classes. Think about a DVD. It would have a title, a price, and perhaps an Inventory Control (IC) number. These become your class variables. A given DVD has no idea if there is another copy of it.



Howdy Timothy

Fear not! Help is on the way. What Fred said is correct. Your approach is not correct. All you really need is a single array (you could use a List as, like Fred mentioned, but lets stick to arrays for now to keep it simple). Each element of the array corresponds to a stock of a specific DVD. And each stock contains a price, stock value and which DVD we're referencing to (you could include the price in the DVD class instead if you want, it's up to you).



Note that I have let the fields as public. Normally you should have these fields as private and create public setters and getters for them like in your Product class.
Understood more or less? Let me know if anything is unclear
12 years ago

Bruce Lentz wrote:

Hope this helps.



Thanks for the help cowboy. I never thought to write the code like this.



I'm glad I could be of assistance
12 years ago

Matthew Brown wrote:Java has some optimisations built in for handling strings - read up on the "string pool" if you're interested. s = "foo" will try to avoid creating a new object if it isn't necessary (if a "foo" String exists in the pool it's safe to reuse it because Strings are immutable). Whereas s = new String("foo") will always create a new String.



Turns out you're right (and so was I)... I ran my program again and now it outputs "s1 == s2 :: true" I don't know why it outputted false the first time. Probably a mistake on my part.
12 years ago

Bruce Lentz wrote:This is actually my second go-around trying to submit this sample to the employer, the first time they told me it could have been implemented better using advanced algorithms (???). I guess I can't help but feel like there is a better way to get this task done.


Howdy Bruce,

Your code is genuinely good. I do however have one suggestion to make on how to improve it. From what I can tell convertFromTabToCSV(File inputFile) and convertFromCSVToTab(File inputFile) are essentially identical. I don't know if this is what Jeanne was referring to in his first post but here's how I'd have done it:



Hope this helps.
12 years ago

Ivan Jozsef Balazs wrote:Actually no "rogue" pieces of executable code are possible.
You can have (unnamed) initializing blocks and assignments but nothing much more.



Yes exactly, technically speaking you cannot write anything outside of the method other than declaration. So everything that you put outside of a function is simply for initialization. It's something that's hidden by the compiler so it can be quite confusing

Think of it in this way:

For dynamic field (instance variables):
is the same as:



For static fields:
is the same as:

12 years ago

Anu satya wrote:String is immutable. So,
if you say


both a and b points to same foo" in the memory.


I'm not so sure about that... check my edit.
12 years ago
That's a good question... I'm not 100% sure of this but here's what I think:

is equivalent to:

I'll check if this is correct and come back to edit this post.

EDIT: Turns out I'm wrong. I've written this small program:

Output: s1==s2 :: false

You my guess is that String s = "foo" is simply a syntactic sugar for String s = new String("foo");. That means their are semantically the same.

EDIT: wrong (again)... turns out I was right the first time

Olivier Legat wrote:

Matthew Brown wrote:Java has some optimisations built in for handling strings - read up on the "string pool" if you're interested. s = "foo" will try to avoid creating a new object if it isn't necessary (if a "foo" String exists in the pool it's safe to reuse it because Strings are immutable). Whereas s = new String("foo") will always create a new String.



Turns out you're right (and so was I)... I ran my program again and now it outputs "s1 == s2 :: true" I don't know why it outputted false the first time.

12 years ago

William P O'Sullivan wrote:What's your point?

That seems very excessive. Are you loading the 3D max app or models?



Indeed, you're being very clear. I assume you mean loading a 3DS max model because you posted this in the Game Dev forum. Normally you wouldn't load a .MAX file into your game, you would normally export your mesh from 3DS Max into a file format such as .3DS or .OBJ (static meshes) or .FBX (animated meshes). You would then load those files into your game using a model importer for whatever file format you decide to use.

I don't know if this answers your question.
12 years ago
Resolved, I found the JAR files ... for Googler's that stumble upon this page here's how I did it:

- Right-click the Libraries folder in the left-hand Projects tab
- Goto /Applications/NetBeans/glassfish-3.1.1/glassfish/modules/
- Select all javax*.jar files.
- Click Choose
- Post a thank-you on this thread (optional)
Howdy folks,

So according to Andrew Monkhouse the javax.servlet.* package is not a package, it's from J2EE.

So I went ahead and downloaded the Netbeans Java EE to get this thing to work but I get a nasty "package javax.servlet.http does not exist" error. And here I was thinking a bigger download would solve all my problems

I'm a complete idiot with Netbeans, how to I check if I have Java EE and how do I reconfigure the project so it can find it?

Thanks-you

P.S. I'm on a Mac so I can't find the J2EE SDK anywhere in the Download Page
Howdy folks,

So I have this primitive code here that worked fine on Windows the last time I ran it:


But now when I run it on Mac something odd happens:

  • If I break this code before the method I notice that chooser.getFileFilter() returns null This is madness! I just set a few lines ago.
  • Furthermore the filter don't do their job at all... they all show everything.
  • And the "All-Files" filter is displayed.

  • How? Why is the behavior of this method completely different on Window and Mac?

    Thank-you

    P.S. I'm developing on Windows using Java 7, but it seems like OSX lion only supports Java 6 (say Apple, correct me if I'm wrong).. Could this be what causes the problem?
    13 years ago
    Hello Kevin,

    Your code doesn't make sense I'm afraid... You're inserting null into the TreeModel. If your newProblem is a DefaultMutableTreeNode then getting the path is easy:

    13 years ago
    Howdy folks

    According to this thread the MouseWheelEvent class doesn't support horizontal scrolling. I've looked through the Java API and Google for alternatives but no luck.

    Suggestions?

    NOTE: I'm fairly sure it should be possible. Scrolling horizontally with the mouse works within a JScrollPane.

    Thank-you
    13 years ago