Solved

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

Posted on 2006-06-14
5
211 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
java. non-English characters encoding problem. intellij idea 3 73
Java DateChooser? 3 29
replace a word with other 1 40
even odd program using while loop 3 25
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

932 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

12 Experts available now in Live!

Get 1:1 Help Now