• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java compiler acted strangely : please help

 
gooi chin hin
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 2 java class. ClassA and PiGbProperties. The strange thing is that when I compile ClassA, the java compiler automatically compiled PiGbProperties class too. Why is this happening? Below are the sample of the classes.


package my.com.batchapp.stmtrequest;
import com.mytemp.*;
public class ClassA extends BObject
{
...
...
private void connect () throws Exception
{
PiGbProperties piGbProperties = new PiGbProperties( );
piGbProperties.loadProperties("bankpbb",propPool);
dbAccessor = new PiGbDbAccessor(propPool);
}
}





package com.mytemp;
public class PiGbProperties extends BObject
{
public void loadProperties(String s, BAnythingPool banythingpool) throws Exception
{
...
...
}
}
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The connect() method here uses the PiGbProperties class, so the compiler needs to compile it in order to know what methods it contains.

Layne
 
gooi chin hin
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think this is true as my java program also called some other class and they are not compiled.

Somebody told me that the problem is due to fact that the PiGbProperties class is inside a jar file. My class path contains both the location of the jar file and also the location of the PiGbProperties class file. When the compiler detected that the PiGbProperties.class (in the jar file) is older than the com.mytemp.PiGbProperties.java file, it will recompiled the PiGbProperties.class.

Is this true?
[ May 11, 2005: Message edited by: gooi chin hin ]
 
Sunetra Sen
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by gooi chin hin:
I don't think this is true as my java program also called some other class and they are not compiled.

Somebody told me that the problem is due to fact that the PiGbProperties class is inside a jar file. My class path contains both the location of the jar file and also the location of the PiGbProperties class file. When the compiler detected that the PiGbProperties.class (in the jar file) is older than the com.mytemp.PiGbProperties.java file, it will recompiled the PiGbProperties.class.

Is this true?

[ May 11, 2005: Message edited by: gooi chin hin ]


I think the original answer is correct.I tried to verify like this:

1) created a class A:
public class A{
public int i;
}

2)then created a classB using class A:
public class B{
public static void main(String args[]){
A a = new A();
a.i=3;
System.out.println("a.i-->"+a.i);
}
}

without compiling A tried to compile B..and lo and behold A also got compiled!
No jars here either.So I think the first answer is correct.

Thanks,
Sunetra.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Java in General (Beginner.) C'mon.
 
gooi chin hin
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The above example only work in the A.java has not been compiled before. For my case, it is different. Both are existing class. They are not new. Why do the java compiler recompiled my PiGbProperties?
 
gooi chin hin
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any idea?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic