Top.Mail.Ru
November 16th, 2005 - Java developers — LiveJournal
? ?

Java developers

November 16th, 2005
Image

09:48 am - Imagelemmywinks30 - confusion...

Can someone tell me why variable x is incremented in example 1 but not changed in example 2?

1.
class GFC403 {
private static int x=1;
static void m1(int i) {x++; i++;}
public static void main (String[] args) {
int y=3; m1(y);
System.out.println(x + "," + y);
}}

prints 2,3

2.
class GFC404 {
private static int x=1;
static void m1(int x, int y) {x++; y++;}
public static void main (String[] args) {
int y=3; m1(x, y);
System.out.println(x + "," + y);
}}

prints 1,3
 

10:42 am - Imagejava_newbie

Hi,

Maybe you know where is the source of the problem.

I have created a java project.

Into the project there is a class, that uses classes from Lib.jar library.

To run the application I used the following command:

java -cp .;c:\MyFolder\Lib.jar com.mypackage.TheMainApplication

When I ran this project using a bunch of compiled *.class files (as is shown above) all worked fine.

But.

When I create jar file from these *.class files, (let's say: myapp.jar) and run it using command:

java -cp .;c:\MyFolder\Lib.jar -jar myapp.jar

all worked fine, until my code runs that class, that refers to Lib.jar file.

I get the following exception:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/package/SomeExternalClass

I completely do not understand. Why, when I ran this code as class files I do not get this exception, but when I create jar file I get this error.

Please help.

Thank you.
Powered by LiveJournal.com
Image