my dog learned polymorphism
The moose likes Beginning Java and the fly likes Why javac? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why javac?" Watch "Why javac?" New topic

Why javac?

Menna Saad

Joined: Oct 26, 2008
Posts: 1
I can't quite figure, why still sun uses javac compiler? why not just enhance the JVM interpeter to be stronge typed?

I guess this will shorten the development cycle and give the java the natural way of "coding as we think."
Pat Farrell

Joined: Aug 11, 2007
Posts: 4659

What does this question have to do with Servlets?

And more fundamentally, you are very confused as to what the javac and jvm do. They are a team.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63355

Please take the time to choose the correct forum for your posts. This forum is for questions on Servlets.

For more information, please read this.

This post has been moved to a more appropriate forum.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 44616
Welcome to JavaRanch.

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.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20137

Originally posted by Campbell Ritchie:
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!

Are you sure? I've written ASP, PHP and Python (fortunately I've been spared the Perl experience ), and all can be run from source code and are quite fast.

Of course they are not (as) strongly typed as Java, but all three have array range checking for instance (although PHP's range checking usually produces a notice, not an error / exception).

How To Ask Questions How To Answer Questions
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24193

You guys have sure made a lot of a few little sentences that I can't even understand. Menna Saad, can you maybe explain in different words exactly what you're asking?

[Jess in Action][AskingGoodQuestions]
Rob Spoor

Joined: Oct 27, 2005
Posts: 20137

I think Campbell and I got the question: why is the translation of source code to byte code still needed.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 44616
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.
Henry Wong

Joined: Sep 28, 2004
Posts: 20175

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.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
ahmed rezk mahmoud

Joined: Oct 27, 2008
Posts: 1
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.
I agree. Here's the link:
subject: Why javac?
It's not a secret anymore!