Solved

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

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
printing a file in reverse order is easy in recursion rather than in iteration 3 56
Java DateChooser? 3 36
custom annotations 9 38
jdbc error in jsp application 20 44
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
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 will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

786 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