PDA

View Full Version : Need some help with Java



Evil Baby
Oct 17th, 2006, 04:41 PM
New post.

My teacher has us writing portions of code. We're supposed to use two of his class files and use some methods from his .class files. However, whenever I try to use any the methods in his code I get errors when I try to compile my code saying there needs to be a .java file to go along with it.

Any help would be greatly appreciated.

fuj_duong
Oct 17th, 2006, 10:24 PM
I'm not sure with RFD's community of programmers...but you could try Sun's Java Dev forums. (http://forum.java.sun.com/index.jspa).. good luck.

fwhc022883
Oct 17th, 2006, 11:18 PM
Not sure, need comments in the code. :P Could it be because of this?

m_yPos += 100;

Hmm, there doesn't seem to be m_xPos incrementing.

Evil Baby
Nov 15th, 2006, 12:39 AM
new OP

evanx
Nov 15th, 2006, 01:42 AM
.class files cannot run on all machines. He should be giving you the .java files instead.

dasaylay
Nov 15th, 2006, 02:05 AM
.class files cannot run on all machines. He should be giving you the .java files instead.

Yeah. As when you compile the program, the .java files are the ones in your project, but new .class files will be created.

BTW, what error is your java program giving out? I had an assignment similar to this, it was due this morning at 9am. UTM though...

Nyte
Nov 15th, 2006, 08:41 AM
Class files are fine. Just make sure you import it if its part of another package, and make sure the compiler knows where to find it.

Nyte
Nov 15th, 2006, 08:42 AM
.class files cannot run on all machines. He should be giving you the .java files instead.

Not sure what you mean by that. Class files WILL run on all machines, as long as you have a working JVM that is (and its the right version, etc).

chatbox
Nov 15th, 2006, 09:35 AM
.class files cannot run on all machines. He should be giving you the .java files instead.

.class files can run on most machines as long as you have the right JVM/JRE (unless we're talking about embedded devices)...that's the whole point of having the bytecode, to be OS and arch independent and re-interprete by the JVM as the middleware between the OS and the bytecode.

Some pre 1.4 class files might not run on newer JVMs...but since 1.4, there's an option for Java1.4 compatible bytecode output. Now, 1.6, 1.5 and 1.4 can run the same code without having to recompile.

Also, one of the point of having OOP is so that each object can be abstract away from the code (.java) and only distribute what you need, .class files. It's therefore easy to be reused and clear (method calls), also, again, arch and OS independent.

temporalillusion
Nov 15th, 2006, 11:27 AM
OP, what compiler are you using? Command line, or an IDE like Eclipse?

As was said, you just have to ensure that the class file is in the class path.

jm20
Nov 15th, 2006, 11:33 AM
I'm not sure with RFD's community of programmers...but you could try Sun's Java Dev forums. (http://forum.java.sun.com/index.jspa).. good luck.

more than u think ;)

Evil Baby
Nov 15th, 2006, 04:21 PM
Figured it out. I was just being really really really stupid. I was trying to create to public classes within in one .java file. I needed a good nights rest then I got it. haha.

Thanks for the help though.