Build vs. Compile - when do I need to "clean" directory?

  • Thread starter Leonard Slatkin
  • Start date
L

Leonard Slatkin

I'm a new Java programmer using NetBeans. When should I use "build"
(which deletes .class files first) instead of "compile" (which should
recreate the changed .class files, anyways, right)?
 
B

Bryce (Work)

I'm a new Java programmer using NetBeans. When should I use "build"
(which deletes .class files first) instead of "compile" (which should
recreate the changed .class files, anyways, right)?

Hardly ever. You are right. I only do a full build when I do releases,
or something buggy's going on with my program...
 
T

Tim Ward

Leonard Slatkin said:
I'm a new Java programmer using NetBeans. When should I use "build"
(which deletes .class files first) instead of "compile" (which should
recreate the changed .class files, anyways, right)?

"Compile" only works sometimes. Other times it doesn't recompile everything
it should and you need to use "Build". On really bad days you end up
deleting .class files by hand.
 
J

Jim

I'm a new Java programmer using NetBeans. When should I use "build"
(which deletes .class files first) instead of "compile" (which should
recreate the changed .class files, anyways, right)?

I'm going to say "rebuild most of the time"

If the class I'm working on doesn't have any "static final"s in it,
or is at the top of the hierarchy then I'll just do a compile.

It takes less time to perform a full build than tracking down strange
dependancy issues the compiler couldn't figure out or just ignored.

Jim
 
W

Wendy S

Leonard Slatkin said:
"compile" (which should recreate the changed .class files, anyways,
right)?

Not always... try it with a static final variable in class A that gets used
in class B. A compiler, seeing that the variable is final and not allowed
to change at runtime, has the option to inline the _value_ of the variable
into class B. Javac is oblivious to that kind of change, and will not see
that B needs to be recompiled.

That's why you have to occasionally clean and "build" all the classes
together, but how often you do it is up to you. There's a tradeoff between
the speed of compiling only what's changed, and knowing that it really does
compile from the ground up.

I nearly always clean and compile from scratch. That said, I make .jar
files of the libraries I have developed in the past that are being used in
the current project. So there's typically not a lot of "loose" code. For
example in my current Struts app, the data access layer is in a .jar file,
having been written a while ago, and only the Actions and Forms need to be
compiled in order to "build" the project.
 
B

brougham5

I'd suggest learning how to use Apache Ant.

Use the depend task. I've never had a problem with not having the right
classes recompiled after using that in my ant build scripts.
 
M

Mark 'Kamikaze' Hughes

Leonard Slatkin said:
I'm a new Java programmer using NetBeans. When should I use "build"
(which deletes .class files first) instead of "compile" (which should
recreate the changed .class files, anyways, right)?

Unless NetBeans has greatly improved its dependency checking since
that last time I tried it, you should almost always "build". There is
very little more frustrating than chasing down bugs caused by mismatched
constants, and Java compiles so fast you won't really notice the
difference unless you're working on a really enormous program.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top