gpuguy
gpuguy

Reputation: 4585

Typical build process of Java application

Being new to Java, I am not able to understand the complete build process from source code to hardware specific binaries. Basically I am using Eclipse for java and would like to know what all conversions takes place from source code(.java) to binary, what all files are linked using some linker, preprocessor etc etc.

Shall appreciate if you can point me to some link giving detail of complete build process for java. I have already searched this forum but did not get detail info.

Thanks

Edited:

So to be more precise I am looking for java equivalent of following build process in C: I googled a lot but no gain! A figure like the following is not a must(though preferred), but if you can write 'n' sequential/parallel steps involved in complete Java build process, that will be really appreciated. Though much of the information provided by @Tom Anderson is very useful to me.

enter image description here

Upvotes: 6

Views: 12506

Answers (2)

Tom Anderson
Tom Anderson

Reputation: 47193

The first thing to appreciate is that your question contains a mistaken assumption. You ask about "the complete build process from source code to hardware specific binaries" - but the normal Java build process never produces architecture-specific binaries. It gets as far as architecture-independent bytecode, then stops. It's certainly true that in most cases, that bytecode will be translated into native code to be executed, but that step happens at runtime, inside the JVM, entirely in memory, and does not involve the production of binary files - it is not part of the build process.

There are exceptions to this - compilers such as GCJ can produce native binaries, but that is rarely done.

So, the only substantial step that occurs as part of a build process is compilation. The compiler reads in source code, does the usual parsing and resolution steps, and emits bytecode. That process is not in any way specified; as is usual, the language specification defines what the elements of the language are, and what they mean, but not how to compile them. What is specified in the format of the output: the bytecode is packaged in the form of class files, one per class, which in turn may be grouped together in jar files for ease of distribution.

When the class files come to be executed, there are then further steps needed before execution is possible. These are quite well-specified in the chapter on loading, linking, and initializing in the JVM specification. But, as i said, these are not really part of the build process.

There are a few other steps that may occur in a build process, usually prior to compilation: dependencies might be resolved and downloaded, resources might be copied and converted between character sets, and code might be generated. But none of this is standard, it's all stuff that's added on to the core process of compilation by various build tools.

Upvotes: 9

pcalcao
pcalcao

Reputation: 15990

There are some cool articles you can checkout if you want to know what's going on "behind the scenes".

http://www.codeproject.com/Articles/30422/How-the-Java-Virtual-Machine-JVM-Works

This is one of them, it has a good explanation on how all the parts interact to run your code.

The main idea is that the bytecode is created from your Java files to run in a Virtual Machine, making your Java code (more or less...) independent of the OS and platform you're running it on.

The JVM, specific to that environment, is then responsible for translating that bytecode into actual instructions for the specific architecture you're running your code on.

This is the basis of the "Write once, run everywhere" mantra that Java has. Although the mantra doesn't always hold... it's still true in general.

Upvotes: 3

Related Questions