Forum Moderators: travelin cat

Message Too Old, No Replies

How to view the source code for a Java applet?

I have Xcode, but it only shows some of the code

         

MichaelBluejay

11:37 am on May 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



A client has a Java applet on his website that I'd like to try to make some changes to. I download the file (filename.class), and drag it onto the Xcode application icon, and it opens up and shows some of the code, but not nearly all of it. The file is 20k but I'm seeing maybe 2k of code. It's just a bunch of function, class, object, and variable declarations -- there's no code that actually *does* anything. The last function is:

public void run() {
}

...and that's the last thing in the file. But where is the code for that function? There are no other files associated with this applet. It's very confusing.

DerekH

1:31 pm on May 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are lots of reasons why this might be.
The one that springs to mind is that something else extends this class, and *that* will be the class that implements the run method.

Usually it is possible to mark such as method as virtual, meaning that another class *must* implement it, but there are often occasions when the class itself can perform everything desired of it, and yet other classes may wish to inherit and specialise it by adding extra functionality.

Search for the class name in the other Java source files and you may well find a class extends it - that will have a run method with real code in it....

DerekH

MichaelBluejay

8:12 pm on May 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm afraid I don't really understand any of what you're saying. But the point is, the one file I have, is the only file. I'm pretty sure there are no other files.

timster

1:04 pm on May 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



there's no code that actually *does* anything.

While I know next to nothing about Java, I've heard the quote above from colleagues who've tried to understand object-oriented code. If you're unfamiliar with object orientation, you might want to devote a few hours to learning the basics there.

What Derek is saying all sounds right. The file you are looking at probably does little besides "inherit" functionality from other classes, which may be in very different places on the hard drive's directory structure.

But we need a Java programmer to give specific advice...

StupidScript

10:53 pm on May 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Where did the client get the applet to begin with? That might be a good place to start looking for the rest of the files.

MichaelBluejay

6:46 am on May 31, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Like I keep saying, there *are* no other files. And as I said in my original post, the file is 20k but when I open with XCode I can see only about 2k of code.

timster

1:26 pm on May 31, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



the file is 20k but when I open with XCode I can see only about 2k of code.

Try opening it in a text editor like BBEdit, and let us know what you see.

MichaelBluejay

3:34 am on Jun 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



When I open with a text editor it's half gibberish (weird characters). I tried to post an excerpt but it doesn't display on WebmasterWorld when I click Preview. I could provide a link to the file except of course that's forbidden here.

timster

2:29 pm on Jun 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It sounds like the unreadable stuff in the file is compiled code.

You may be able to get back to source code with a Java decompiler like Mocha:

[brouhaha.com ]
It's possible, however, that the original developer may have made it difficult to get back to the source code.

I'm wondering, is there a board at WW where we'd be likely to find more Java expertise?