Building vs. Compiling (Java)

111,330

Solution 1

The "Build" is a process that covers all the steps required to create a "deliverable" of your software. In the Java world, this typically includes:

  1. Generating sources (sometimes).
  2. Compiling sources.
  3. Compiling test sources.
  4. Executing tests (unit tests, integration tests, etc).
  5. Packaging (into jar, war, ejb-jar, ear).
  6. Running health checks (static analyzers like Checkstyle, Findbugs, PMD, test coverage, etc).
  7. Generating reports.

So as you can see, compiling is only a (small) part of the build (and the best practice is to fully automate all the steps with tools like Maven or Ant and to run the build continuously which is known as Continuous Integration).

Solution 2

Some of the answers I see here are out-of-context and make more sense if this were a C/C++ question.

Short version:

  • "Compiling" is turning .java files into .class files
  • 'Building" is a generic term that includes compiling and other tasks.

"Building" is a generic term describes the overall process which includes compiling. For example, the build process might include tools which generate Java code or documentation files.

Often there will be additional phases, like "package" which takes all your .class files and puts them into a .jar, or "clean" which cleans out .class files and temporary directories.

Solution 3

Compiling is the act of turning source code into object code.

Linking is the act of combining object code with libraries into a raw executable.

Building is the sequence composed of compiling and linking, with possibly other tasks such as installer creation.

Many compilers handle the linking step automatically after compiling source code.

What is the difference between compile code and executable code?

Solution 4

In simple words

Compilation translates java code (human readable) into bytecode, so the Virtual machine understands it.

Building puts all the compiled parts together and creates (builds) an executable.

Solution 5

  • Build is a compiled version of a program.
  • Compile means, convert (a program) into a machine-code or lower-level form in which the program can be executed.

In Java: Build is a Life cycle contains sequence of named phases.

for example: maven it has three build life cycles, the following one is default build life cycle.

◾validate - validate the project is correct and all necessary information is available
◾compile - compile the source code of the project
◾test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
◾package - take the compiled code and package it in its distributable format, such as a JAR.
◾integration-test - process and deploy the package if necessary into an environment where integration tests can be run
◾verify - run any checks to verify the package is valid and meets quality criteria
◾install - install the package into the local repository, for use as a dependency in other projects locally
◾deploy - done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
Share:
111,330

Related videos on Youtube

sixtyfootersdude
Author by

sixtyfootersdude

Updated on December 10, 2020

Comments

  • sixtyfootersdude
    sixtyfootersdude over 3 years

    Thinking that the answer to this is pretty obvious but here it goes:

    When I am working on a small project for school (in java) I compile it.

    On my coop we are using ant to build our project.

    I think that compiling is a subset of building. Is this correct? What is the difference between building and compiling?

    Related:
    What is the difference between compiling and building?

  • Bert F
    Bert F about 14 years
    Some other possible tasks: enhancing (JDO), Javadoc-ing, packaging, and signing. In addition, some environments including running automated unit/regression tests as part of a "build".
  • Tyler
    Tyler about 14 years
    You can also see what ant is actually doing by looking the buildfile (most likely called build.xml). Even if you're not familiar with the syntax, you can kind of see what's going on. <javac> means it's compiling some Java code. <java> means it's actually running the compiled code. Probably it's creating a directory to put the .class files in, compiling the code, maybe creating some Javadoc, etc.
  • markusk
    markusk about 14 years
    Normally, there is no linking step when building Java projects, and no raw executable is produced. Rather, the compiled classes are packaged together into a .jar file as part of the build. (Or .war, or .ear, depending on your target environment.)
  • ealeon
    ealeon almost 11 years
    what are "raw executable"?
  • Kaili
    Kaili over 10 years
    The bag of bits that is basically useless on it's own without being mixed in with the other libraries it needs. It's much like a chocolate cake. Without the flour and eggs, etc, the cocoa is just raw cocoa.
  • mortsahl
    mortsahl over 9 years
    What you're talking about is "Interpretation" ... compiling is turning the human readable code into machine code
  • Quazi Irfan
    Quazi Irfan almost 8 years
    Why call it "Continuous Integration" instead of "Continuous Building"?
  • Pacerier
    Pacerier over 7 years
    @Pascal, Re "run the build continuously".. "the build" refers to?
  • Pacerier
    Pacerier over 7 years
    @Tom, You mean an "executable" or "jar executable"?
  • michelek
    michelek over 6 years
    @Pacerier "the build" refers to all steps 1.-7.; "continuously" doesn't mean you start next build immediately after first one finishes but only on changes in project.
  • Deepak Gupta
    Deepak Gupta almost 6 years
    and when it generate sources as you mention in the 1st point (Generating sources (sometimes).)
  • hunt
    hunt over 3 years
    @QuaziIrfan Because you are verifying that your new, or updated, code integrates with the existing code base. That is, that your changes compile, that they comply with the team's coding standards and requirements, that its basic functionality is good, and that they don't break the current good build. In other words, that your updates integrate well with the existing code base. HTH