Version 1.3.1 Versus 1.4.2_04

K

Kevin Simonson

Is there something about the differences between Java versions 1.3.1
and 1.4.2_04 that keeps me from declaring an object of one class when
I just got done compiling that class' definition?

Take a look at my code below. On host "nail", that has version
1.4.2_04 installed, I can write class "Bug" and compile it, and when I
compile class "BugDriver" that declares an object of type "Bug" and
uses it, it compiles fine and runs fine.

On host "star", that has version 1.3.1 installed, I compile the
same "Bug" class, but when I try to compile the same "BugDriver" class
I get an error message and the code doesn't compile.

Does anybody know why this is happening? I wouldn't think there
would be that much differences between two versions of Java.

---Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_

,------------------------------------------------------------------------------
|nail:Ncl/Java_bash-2.05b$ hostname
|nail.cs.byu.edu
|nail:Ncl/Java_bash-2.05b$ java -version
|java version "1.4.2_04"
|Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
|Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)
|nail:Ncl/Java_bash-2.05b$ cat Bug.java
|public class Bug
|{
| int bug;
|
| public Bug ( int bg)
| {
| bug = bg;
| }
|
| public int bugSquared ()
| {
| return bug * bug;
| }
|}
|nail:Ncl/Java_bash-2.05b$ cat BugDriver.java
|public class BugDriver
|{
| public static void main ( String[] arguments)
| {
| System.out.println
| ( "(new Bug( 7)).bugSquared() == " + (new Bug( 7)).bugSquared() + '.');
| }
|}
|nail:Ncl/Java_bash-2.05b$ javac Bug.java
|nail:Ncl/Java_bash-2.05b$ javac BugDriver.java
|nail:Ncl/Java_bash-2.05b$ java BugDriver
|(new Bug( 7)).bugSquared() == 49.
|nail:Ncl/Java_bash-2.05b$
`------------------------------------------------------------------------------
,------------------------------------------------------------------------------
|[kvnsmnsn@star Rid3]$ hostname
|star
|[kvnsmnsn@star Rid3]$ java -version
|java version "1.3.1"
|jdkgcj 0.2.3 (http://www.arklinux.org/projects/jdkgcj)
|gcj (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
|Copyright (C) 2002 Free Software Foundation, Inc.
|This is free software; see the source for copying conditions. There is NO
|warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|[kvnsmnsn@star Rid3]$ cat Bug.java
|public class Bug
|{
| int bug;
|
| public Bug ( int bg)
| {
| bug = bg;
| }
|
| public int bugSquared ()
| {
| return bug * bug;
| }
|}
|[kvnsmnsn@star Rid3]$ cat BugDriver.java
|public class BugDriver
|{
| public static void main ( String[] arguments)
| {
| System.out.println
| ( "(new Bug( 7)).bugSquared() == " + (new Bug( 7)).bugSquared() + '.');
| }
|}
|[kvnsmnsn@star Rid3]$ javac Bug.java
|[kvnsmnsn@star Rid3]$ javac BugDriver.java
|BugDriver.java: In class `BugDriver':
|BugDriver.java: In method `BugDriver.main(java.lang.String[])':
|BugDriver.java:6: Class `Bug' not found in type declaration.
| ( "(new Bug( 7)).bugSquared() == " + (new Bug( 7)).bugSquared() + '.');
| ^
|1 error
|[kvnsmnsn@star Rid3]$
`------------------------------------------------------------------------------
 
J

Jj

do you have "." - the current directory in the class path ? try to add "."
in the classpath when you compile the second class.

good luck.

Kevin Simonson said:
Is there something about the differences between Java versions 1.3.1
and 1.4.2_04 that keeps me from declaring an object of one class when
I just got done compiling that class' definition?

Take a look at my code below. On host "nail", that has version
1.4.2_04 installed, I can write class "Bug" and compile it, and when I
compile class "BugDriver" that declares an object of type "Bug" and
uses it, it compiles fine and runs fine.

On host "star", that has version 1.3.1 installed, I compile the
same "Bug" class, but when I try to compile the same "BugDriver" class
I get an error message and the code doesn't compile.

Does anybody know why this is happening? I wouldn't think there
would be that much differences between two versions of Java.

---Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_

,---------------------------------------------------------------------------
---
|nail:Ncl/Java_bash-2.05b$ hostname
|nail.cs.byu.edu
|nail:Ncl/Java_bash-2.05b$ java -version
|java version "1.4.2_04"
|Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
|Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)
|nail:Ncl/Java_bash-2.05b$ cat Bug.java
|public class Bug
|{
| int bug;
|
| public Bug ( int bg)
| {
| bug = bg;
| }
|
| public int bugSquared ()
| {
| return bug * bug;
| }
|}
|nail:Ncl/Java_bash-2.05b$ cat BugDriver.java
|public class BugDriver
|{
| public static void main ( String[] arguments)
| {
| System.out.println
| ( "(new Bug( 7)).bugSquared() == " + (new Bug( 7)).bugSquared() + '.');
| }
|}
|nail:Ncl/Java_bash-2.05b$ javac Bug.java
|nail:Ncl/Java_bash-2.05b$ javac BugDriver.java
|nail:Ncl/Java_bash-2.05b$ java BugDriver
|(new Bug( 7)).bugSquared() == 49.
|nail:Ncl/Java_bash-2.05b$
`---------------------------------------------------------------------------
---,---------------------------------------------------------------------------
---
|[kvnsmnsn@star Rid3]$ hostname
|star
|[kvnsmnsn@star Rid3]$ java -version
|java version "1.3.1"
|jdkgcj 0.2.3 (http://www.arklinux.org/projects/jdkgcj)
|gcj (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
|Copyright (C) 2002 Free Software Foundation, Inc.
|This is free software; see the source for copying conditions. There is NO
|warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|[kvnsmnsn@star Rid3]$ cat Bug.java
|public class Bug
|{
| int bug;
|
| public Bug ( int bg)
| {
| bug = bg;
| }
|
| public int bugSquared ()
| {
| return bug * bug;
| }
|}
|[kvnsmnsn@star Rid3]$ cat BugDriver.java
|public class BugDriver
|{
| public static void main ( String[] arguments)
| {
| System.out.println
| ( "(new Bug( 7)).bugSquared() == " + (new Bug( 7)).bugSquared() + '.');
| }
|}
|[kvnsmnsn@star Rid3]$ javac Bug.java
|[kvnsmnsn@star Rid3]$ javac BugDriver.java
|BugDriver.java: In class `BugDriver':
|BugDriver.java: In method `BugDriver.main(java.lang.String[])':
|BugDriver.java:6: Class `Bug' not found in type declaration.
| ( "(new Bug( 7)).bugSquared() == " + (new Bug( 7)).bugSquared() + '.');
| ^
|1 error
|[kvnsmnsn@star Rid3]$
`---------------------------------------------------------------------------
---
 
T

Thomas G. Marshall

Kevin Simonson coughed up:
Is there something about the differences between Java versions 1.3.1
and 1.4.2_04 that keeps me from declaring an object of one class when
I just got done compiling that class' definition?

Take a look at my code below. [...]


You've tried to enclose your examples in a kind of ascii art box. This
places a "|" in front of every line. Bad idea.

1. That character gets misinterpreted as a reply indent character (or
whatever they're /supposed/ to be called).

2. It makes it hard to cut and paste out your examples so that I or anyone
else can easily see if they compile and run ok on our systems.



....[thwack]...
 
M

Michael Borgwardt

Jj said:
do you have "." - the current directory in the class path ? try to add "."
in the classpath when you compile the second class.

Or better yet, don't set the classpath environment variable at all.
 
K

Kevin Simonson

=> do you have "." - the current directory in the class path ? try to add "."
=> in the classpath when you compile the second class.
=
=Or better yet, don't set the classpath environment variable at all.

I think both machines I ran that program on were Linux machines.
How do I go about finding out if the "classpath" variable is set, and
how to change it if it is?

---Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_

-------------------------------------------------------------------------------
nail:Ncl/Java_bash-2.05b$ hostname
nail.cs.byu.edu
nail:Ncl/Java_bash-2.05b$ java -version
java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)
nail:Ncl/Java_bash-2.05b$ cat Bug.java
public class Bug
{
int bug;

public Bug ( int bg)
{
bug = bg;
}

public int bugSquared ()
{
return bug * bug;
}
}
nail:Ncl/Java_bash-2.05b$ cat BugDriver.java
public class BugDriver
{
public static void main ( String[] arguments)
{
System.out.println
( "(new Bug( 7)).bugSquared() == " + (new Bug( 7)).bugSquared() + '.');
}
}
nail:Ncl/Java_bash-2.05b$ javac Bug.java
nail:Ncl/Java_bash-2.05b$ javac BugDriver.java
nail:Ncl/Java_bash-2.05b$ java BugDriver
(new Bug( 7)).bugSquared() == 49.
nail:Ncl/Java_bash-2.05b$
-------------------------------------------------------------------------------
[kvnsmnsn@star Rid3]$ hostname
star
[kvnsmnsn@star Rid3]$ java -version
java version "1.3.1"
jdkgcj 0.2.3 (http://www.arklinux.org/projects/jdkgcj)
gcj (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[kvnsmnsn@star Rid3]$ cat Bug.java
public class Bug
{
int bug;

public Bug ( int bg)
{
bug = bg;
}

public int bugSquared ()
{
return bug * bug;
}
}
[kvnsmnsn@star Rid3]$ cat BugDriver.java
public class BugDriver
{
public static void main ( String[] arguments)
{
System.out.println
( "(new Bug( 7)).bugSquared() == " + (new Bug( 7)).bugSquared() + '.');
}
}
[kvnsmnsn@star Rid3]$ javac Bug.java
[kvnsmnsn@star Rid3]$ javac BugDriver.java
BugDriver.java: In class `BugDriver':
BugDriver.java: In method `BugDriver.main(java.lang.String[])':
BugDriver.java:6: Class `Bug' not found in type declaration.
( "(new Bug( 7)).bugSquared() == " + (new Bug( 7)).bugSquared() + '.');
^
1 error
[kvnsmnsn@star Rid3]$
------------------------------------------------------------------------------
 
M

Michael Borgwardt

Kevin said:
=> do you have "." - the current directory in the class path ? try to add "."
=> in the classpath when you compile the second class.
=
=Or better yet, don't set the classpath environment variable at all.

I think both machines I ran that program on were Linux machines.
How do I go about finding out if the "classpath" variable is set, and
how to change it if it is?

echo $CLASSPATH

should tell you the content of the variable. As for where it's set, there
are many places, the most likely being the files /etc/profile, /etc/profile.local
and .bashrc (since you seem to be using bash) in your home directory.
 
J

John

You might try enclosing (new Bug( 7)).bugSquared() in parentheses:

System.out.println
( "(new Bug( 7)).bugSquared() == " + ((new Bug( 7)).bugSquared()) +
'.');

Also, the parenthese around (new Bug( 7)) before .bugSquared()
shouldn't be necessary.
 
K

Kevin Simonson

=> I think both machines I ran that program on were Linux machines.
=> How do I go about finding out if the "classpath" variable is set, and
=> how to change it if it is?
=
=echo $CLASSPATH
=
=should tell you the content of the variable. As for where it's set, there
=are many places, the most likely being the files /etc/profile, /etc/profile.local
=and .bashrc (since you seem to be using bash) in your home directory.

As you can see below, I tried "echo $CLASSPATH" on the same ma-
chine I was having the problem on, and <CLASSPATH> didn't appear to
have a value. I took a look in "/etc/profile" and ".bashrc", to no
avail. Note that my system doesn't appear to have a
"/etc/profile.local" file. Any more ideas as to why I can't declare
an object of class <Bug> immediately after compiling "Bug.java"?

---thanks,
Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_

----------------------------------------------------------------------

[kvnsmnsn@star Rid3]$ hostname
star
[kvnsmnsn@star Rid3]$ echo $CLASSPATH

[kvnsmnsn@star Rid3]$ ls -dF /etc/profile*
/etc/profile /etc/profile.d/
[kvnsmnsn@star Rid3]$ grep -i classp /etc/profile
[kvnsmnsn@star Rid3]$ grep -i classp ~/.bashrc
[kvnsmnsn@star Rid3]$
 
K

Kevin Simonson

(e-mail address removed) (John) wrote in message

=You might try enclosing (new Bug( 7)).bugSquared() in parentheses:
=
=System.out.println
= ( "(new Bug( 7)).bugSquared() == " + ((new Bug( 7)).bugSquared()) +
='.');
=
=Also, the parenthese around (new Bug( 7)) before .bugSquared()
=shouldn't be necessary.

John, I tried enclosing "(new Bug( 7)).bugSquared()" in parenthe-
ses, both with and without the parentheses around "(new Bug( 7))", and
neither one let my code compile. Any other ideas?

---thanks,
Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_

----------------------------------------------------------------------

[kvnsmnsn@star Rid3]$ hostname
star
[kvnsmnsn@star Rid3]$ cat Bug.java
public class Bug
{
int bug;

public Bug ( int bg)
{
bug = bg;
}

public int bugSquared ()
{
return bug * bug;
}
}
[kvnsmnsn@star Rid3]$ cat BugDriver.java
public class BugDriver
{
public static void main ( String[] arguments)
{
System.out.println
( "(new Bug( 7)).bugSquared() == " + ((new Bug( 7)).bugSquared()) + '.');
}
}
[kvnsmnsn@star Rid3]$ cat BugDriver2.java
public class BugDriver2
{
public static void main ( String[] arguments)
{
System.out.println
( "(new Bug( 7).bugSquared()) == " + (new Bug( 7).bugSquared()) + '.');
}
}
[kvnsmnsn@star Rid3]$ javac Bug.java
[kvnsmnsn@star Rid3]$ javac BugDriver.java
BugDriver.java: In class `BugDriver':
BugDriver.java: In method `BugDriver.main(java.lang.String[])':
BugDriver.java:6: Class `Bug' not found in type declaration.
( "(new Bug( 7)).bugSquared() == " + ((new Bug( 7)).bugSquared()) + '.'
);
^
1 error
[kvnsmnsn@star Rid3]$ javac BugDriver2.java
BugDriver2.java: In class `BugDriver2':
BugDriver2.java: In method `BugDriver2.main(java.lang.String[])':
BugDriver2.java:6: Class `Bug' not found in type declaration.
( "(new Bug( 7).bugSquared()) == " + (new Bug( 7).bugSquared()) + '.');
^
1 error
[kvnsmnsn@star Rid3]$
tack:kvnsmnsn/Ncl_bash-2.05b$
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,796
Messages
2,569,645
Members
45,371
Latest member
TroyHursey

Latest Threads

Top