aspose file tools*
The moose likes Beginning Java and the fly likes Process of Compilation and Linkage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Process of Compilation and Linkage" Watch "Process of Compilation and Linkage" New topic
Author

Process of Compilation and Linkage

Mohan Chandra
Greenhorn

Joined: Oct 26, 2005
Posts: 1
Hi ranchers,

how the javac produces compiler errors. what is the process of
compilation of the source code.

Many of the answers include 'wont compile'.

Does it include only the syntax or any other process
involved.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Sorry, but this question has to be moved to our beginner's forum: Java in General (Beginner).


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Welcome to the ranch, Mohan!

Compilers are pretty darned complex things, but we can talk about a few of the steps they go through. Among the first is a syntax check. The compiler makes sure you have used valid characters, keywords, variable names, punctuation and so on. If you're like me you've gotten a variety of compiler errors at this point like unmatched parens or missing semi-colons.

Then it builds an internal model of the program. I think JavaC builds an Abstract Sytax Tree that represents classes, methods, statements and so on down to the leaf operands of every clause. Now the compiler might find errors like casting or numeric truncation.

You mentioned linkage in the topic, but Java doesn't have an explicit LINK step like C or the mainframe COBOL I used to know. The compiler looks for references to other classes or interfaces and makes sure it can find them in other class files, jars, or wherever. In this phase you'll get errors like class not found or a method signature that doesn't match.

At run time the JVM looks for them all over again and may or may not find exactly the same ones the compiler found, which also leads to interesting error messages.

One could generate byte code right from the model, I think. Modern compilers examine the tree and/or the byte code and look for chances to optimize. This is pretty deep voodoo that I don't pretend to know but it often involves removing instructions that don't have any effect or maybe moving code around to eliminate calls or loops.

Any of that help?
[ October 26, 2005: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Process of Compilation and Linkage