detemining .java and .class files
Hello All,
I have faced a tricky and intresting question. If any know the solution, plz tell me.
The question is like this:
you have been given two files. one .java file and other .class file. Their extensions are been removed. Without modifing their names you have to determine which one is .java file and which one is .class file. You have been given command prompt only. So using some commands you have to determine which file is .java and which one is .class file.
Plz tell me how to determine?
Thanks in advance.................
First, it should be impossible. The Java file and Class file have the same name before the .ext, and no file system I know of supports that mis-feature. Second, depends on the os, but open one file in a text editor, if it is plain text, it is java file, otherwise it is .class
open the file in a text editor**** slow...Message was edited by: manuel.leiria
Thanks for ur reply. But i should not open them in any editor. If we were given that chance we would have determined easily. But thats not the case. You are not suppose to open and view the contents of those files.
> Thanks for ur reply. But i should not open them in
> any editor. If we were given that chance we would
> have determined easily. But thats not the case. You
> are not suppose to open and view the contents of
> those files.
You could probably make a reasonable estimate based on file sizes. But I'm guessing that, too, will be excluded by your mystical and fluid set of rules, which seems centred around "you have to determine this without any sort of measuring". Which can't be done
On Linux you could use the "file" command...Very uninteresting and contrived in any case.
you have a command window?
use
C:> edit MythicalFile
it will open the file in an editor inside the command window.
ALTERNATE:
use a simple dir command to look at the files sizes.
3rd Alternate:
use the command ;(requires JDK)
java mythicalFile
if it runs, it is the class,
if it kicks back an error its not.
and why are you trying to cheat anyhow? i imagine this is from an exam or trivia question, that you should probably be solving on your own.
> > Thanks for ur reply. But i should not open them in
> > any editor. If we were given that chance we would
> > have determined easily. But thats not the case.
> You
> > are not suppose to open and view the contents of
> > those files.
>
> You could probably make a reasonable estimate based
> on file sizes. But I'm guessing that, too, will be
> excluded by your mystical and fluid set of rules,
> which seems centred around "you have to determine
> this without any sort of measuring". Which can't be
> done
This does not seem to be be a good way to judge. I tried a couple files and it seems there is no correlation between size of .java file and size of .class file. But as another poster said, contrived and meaningless.
you could rename one of the files by adding .class to the end then running java <classname> and see what happens. Or in windows use the type command, but that is just another way of seeing the file contents.
~Tim
Class files start with a "magic" number. The first four bytes should always be:0xCAFEBABEThis is extremely unlikely for the first 4 bytes of a source file.