Solved

JBuilder successfully compiling a class file that inadvertantly referenced a "count" variable that I never declared anywhere.

Posted on 2006-06-14
5
208 Views
Last Modified: 2013-11-23
I'm not a Java whiz kid, but I certainly know enough to have gotten by quite successfully over these past 7 years.  Servlets primarily.  And I still use my 'ole JBuilder 3 environment.   Ok, them's my credentials, so I hope you don't roll your eyes when you read what I'm experiencing...

Inadvertantly, I saw my Jbuilder3 was compiling (successfully, with no errors or warnings) a servlet that contained a reference to a "count" variable that I NEVER declared anywhere. It took me some time to whittle down the mysterious code to the following three files: BlahBlah.java, Dummy1.java, and Dummy.java.

I have yet to understand WHY this is happening.  In the Project properties, I am using JDK 1.2 (yes, I know, maybe a bit outdated but it's worked fine for my simple needs all these years).  I have cleared any reference to external Java libraries.  So the code in question is the 3 simple java files below.  Note there are no "import" statements anywhere.  And each time I compile, I've erased all ".class" files from previous compiles, just to be sure "count" is not referenced in some location I'm not aware of (but that wouldn't make sense anyway, because shouldn't "count" be dot-prefixed with the classname it's declared in?  And no, I'm not inheriting from anything (as you can see below).

The odd thing is this...   If I change anything, such as remove one of the files from my package (appropriately named "wierd"), the compiler then picks up on the undeclared "count" line in Dummy.java.

One of these days, I'll have to wean myself off JBuilder3 and get into using a copy of JBuilder2005 I have.  But in the mean time, I am perplexed by this!  Simple changes like removing the call to "Dummy1.sillyUselessProcThatReturnsNull();" in the Dummy unit will cause the compiler to finally see that "count" is not known.

90% of the time, I always seem to find the problem myself after posting my question online, so maybe that will happen here!  But in the mean time, if anyone can explain why this is happening....   well, I'd appreciate it.

SB

========= BlahBlah.java ===========
package wierd;

class BlahBlah  {

  public BlahBlah() {
    Dummy1.sillyUselessProcThatReturnsNull();
  }

}

========= Dummy.java ============
package wierd;

class Dummy  {

  public Dummy() {
    count = 0;   // WHERE IS THIS DECLARED????????????
    Dummy1.sillyUselessProcThatReturnsNull();
  }

}

========= Dummy1.java ==========
package wierd;

class Dummy1 {

  public static void sillyUselessProcThatReturnsNull() {
   "HELLO".equalsIgnoreCase( "GOODBYE" );
  }
}


0
Comment
Question by:stockblocks
  • 3
  • 2
5 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 16908588
shouldn't compile, maybe a bug in JB.
have you tries compiling from command line with javac?
0
 

Author Comment

by:stockblocks
ID: 16908650
Never used javac, but tried your suggestion.  In MS-DOS panel, I went into the folder containing the 3 java files and issued this command:

C:\JBuilder3\myprojects\wierd\javac  Dummy.java

Sure enough, it picked up on the line showing "count = 0"  (error msg was "cannot resolve symbol").

It also couldn't resolve the reference to Dummy1 in the next line, since javac doesn't know about other files in the "package".  So on a side note, how would I compile the entire package with javac?  Sorry if this is a silly question.  Does it entail use of a "make-like" file?  I've seen how JBuilder 3 creates a 'dependency' file... is that what javac uses to compile all servlets contained in a package?

SB
0
 
LVL 92

Expert Comment

by:objects
ID: 16908664
you need to add your projects directory to your classpath, eg.

javac -classpath C:\JBuilder3\myprojects Dummy.java

some good background on classpaths:
http://mindprod.com/jgloss/classpath.html
0
 

Author Comment

by:stockblocks
ID: 16908741
Got it.  Thanks.   So now the only error is the unresolved symbol reference to "count", as is expected!

But I'm really disappointed that JBuilder3 didn't find it.  Might assigning a different JDK fix it?  I.e., could this be due to a problem with the JDK I'm using?  Doubtful perhaps...  but I've gone so many years really thinking that JBuilder was "perfect", so I'd hate think it's a compiler bug.

Oh well.  You were extremely fast in assisting me.  I'll accept that as the definitive answer.

Thanks,

SB
0
 
LVL 92

Expert Comment

by:objects
ID: 16908770
doubt its a problem with the jdk, more likely a problem with JB itself
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now