Well, if u didn't got eny errors during compilation, it likely u a
workeing under ur classpath, thats why compiling u source <work.java>
forces compiling result.java and test.java, because there were no such
classes needed by ur work class, however the are sources of this
classes. Lately, when u changed source of result class, u didn't
compile it. Insted of copiling work.java (where u didn't any changes)
u should compile result.java, where u did all changes.

Lets look at second copile proccess again. U run javac work.java,
compiller found needed classes, there no errors, so it can use this
*.class files to copile (and later) run ur work.class - it is not
nessesary to complie result.java and work.java. And compiller don't
know nothing about changes of java classes? u didn't mentioned during
compile.

Morover, netBeans will not help u in all situations, some times u have
to do "clean and build" - proccess, that kills any compiled classes,
and recompiling all sources.

To recompile all source files in folder u have to use javac *.java -
all classes wil be recompilled. ;)


And one more thing. It is recomended, that u'll use static methods,
wich deals only with static fields, emagine how many memory usage u
can save than. Static methods creates ones per class, and if u have 1
000 000 instatnces of this class there will be only one method,
otherwise using instatce method u'd pay 1 000 000 * (sizeof(your
method)).



On Dec 18, 10:29 am, Te <[email protected]> wrote:
> I have created the following 3 classes. I compile using 'javac
> work.java' and the answer is 'Final Result is 2'.
>
> Next, I change the variable in "result" class from "static int count"
> to "public int count", and then I compiled again using javac
> work.java. I still get the answer of 'Final Result is 2'.
>
> Now, I delete all the classes generated and compiled again using javac
> work.java. This time, I get 'Final Result is 1'.
>
> Does this mean that javac command is not reliable. I should use
> NetBeans? (I am trying not to rely on IDE)
>
> public class work{
>         public static void main(String args[]) {
>                 test t1=new test() ;
>                 t1.getResult() ;
>                 test t2=new test() ;
>                 System.out.println("Final Result is " + t2.getResult() ) ;
>         }}
>
> *****************************************************************************
> public class test {
>         public test() {
>         }
>
>         int getResult() {
>                 result r = new result() ;
>                 r.setCount() ;
>                 return r.getCount() ;
>         }}
>
> *****************************************************************************
> public class result {
>         static int count ;
>
>         public result() {
>         }
>
>         void setCount() {
>                 count++ ;
>         }
>
>         int getCount() {
>                 return count ;
>         }
>
> }
>
>

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to