Where did you get the idea that we can code as we think? A computer thinks quite differently from the way the brain thinks. The whole idea of using the javac compiler is to do lots of error-checking, then produce code which can simply be interpreted. If you had to repeat the error-checking every time you tried to execute any code, you could rely on Java code running at the speed of a snail with arthritis!
Bytecode has the advantage of portability; that is why others have followed the same approach, eg Microsoft with the .NET languages.
I think Campbell and I got the question: why is the translation of source code to byte code still needed.
Joined: Oct 13, 2005
Rob saying I agree with him? Whatever next? When I tried programming in BASIC a very long time ago, that was interpreted directly from the source, and ran reasonably fast, but in those days we were restricted to 256 lines of code per application. You try that with a big application with 1000000 lines in, and maybe it won't be as fast.
Actually there is another subtle little point, about "coding as we think." Assuming "as" doesn't mean "when" there (and I migh be mistaken), that suggests Menna Saad thinks computers and people "think" the same way. Which we don't.
Another issue is that source is not a good distribution format. If you were a company that sold a product, do you want the code for the product to be source? This holds true for library packages, or even code that you have been consulted to write.
Apart from the small java-enabled gadgets, the reason why the interpretation process in run time is still there is enigmatic(at least for me.) (that's why the hostspot is caching the machine code after interpretation) what I mean is we could have 2 way compilatoin process one that reveals the .class(perfectly compatibable,) and the other would be in the JMV instead of interpretation.
About the javac and the .class I would say the argumet of keeping the source code away from the clients, is way too old fashion, and it will be valid in the 1990s, any trivial decompiler will reveal every single line of the source code.
Regarding Menna's question, I would say we need the compilation process: 1-to be done with compilation errors(that we don't really want to face on the production time) 2-to provide a kind of code optimization(things java compiler do behind the scenes like code inlining ...) I do agree with Menna, that we can enhance the interpreter to do so, but this will cost us more runtime processing cycles. 3-to help Java recognize new custom types.yet this could also be done with the interpretation.