Error with javac

I'm running NT4.0 with Explorer 4.0 and an ABSOLUTELY beginner to Java (although I've been a VC++ programmer for a while)

I installed Sun's Java Development Kit, I assume its the latest
version. It came on a CD in a book and supposedly the version was
released 12-98?I've NEVER programmed in Java.

I've got 2 questions:

1) I'm trying to compile an extremely simple application with "javac". This is the error message I get:

Exception in thread "main" java.lang.NoClassDefFoundError: sun/tools/javac/Main

This error seems odd to me. Is it looking for some sort of header type file located in a path sun/tools.../main? If so, how do I tell javac where this directory is? Put the location in my system path?

2) Java is similar looking to C/C++, yet the book says it uses a certain formatting which looks like completely bad style in C/C++.

class MyClass {
}

Instead of the readable way allowed in C/C++:

class MyClass
{
}

Since I haven't been able to compile a Java program yet I don't know, but can you place the bracket in the approperate place? Or does the compiler require it on the same line?

I guess the Java compiler development, at this point, is more concerned with real features, but anyone think the compiler developers will fix this problem? Is it intentional to quickly differentiate the code from C code?
[1486 byte] By [Steveam] at [2007-11-15 19:11:36]
# 1 Re: Error with javac
Well I don't know which sample u r trying. If u don't mind give the source or u can try this very simple program using...

> javac FirstClass.java
> java FirstClass

// FirstClass.java

public class FirstClass
{
public static void main( String arg[] )
{
System.out.println( "Hello world!" );
}
}

This program is supposed to give show 'Hello world!' when run.
Did it give u error?
And u can find out the version of JDK u r using by the command 'java -version'.

- UnicMan
http://members.tripod.com/unicman
unicman at 2007-11-10 3:01:57 >
# 2 Re: Error with javac
Thanks for the very complete post! I tried your sample, and it still gave me the same problem.

I had moved my javac.exe program to the directory with my source code because the path was screwed up. So I decided to use the original javac.exe program in the other directory.

That worked. So now I've removed the javac.exe copy and updated my system path.

Now I can get ".class" files, but I'm getting a similar problem now!

I go and run the .class file. This is what I type in Windows DOS:
java FirstClass

And I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: FirstClass

Do you know what this means?

Thanks
Steveam at 2007-11-10 3:02:49 >
# 3 Re: Error with javac
Try to clear the CLASSPATH environment variable or if u don't want to do that,
Try appending it with '.;'

For e.g.
set CLASSPATH=.;%CLASSPATH%

And then see if it works.

- UnicMan
http://members.tripod.com/unicman
unicman at 2007-11-10 3:03:51 >
# 4 Re: Error with javac
Sorry, forgot to tell you the version

java version "1.2"
Classic VM (build JDK-1.2-V, native threads)
Steveam at 2007-11-10 3:04:57 >
# 5 Re: Error with javac
I put the .; in the front of my CLASSPATH and I still get the same error. This is what my CLASSPATH looks like now:

.;C:\Program Files\PhotoDeluxe 2.0\AdobeConnectables;c:\jdk1.2\lib\tools.jar

Does this help at all?

Thanks
Steve
Steveam at 2007-11-10 3:05:56 >
# 6 Re: Error with javac
It is strange. It works fine on my machine.

Try clearing the CLASSPATH. Can u give me full error message (including the message specifying in which classes the error occured) ...

Exception in thread "main" java.lang.NoClassDefFoundError: FirstClass

- UnicMan
http://members.tripod.com/unicman
unicman at 2007-11-10 3:06:57 >
# 7 Re: Error with javac
Thanks!

I finally got your "Hello World!" to appear! That other application I had works now too.

The problem was fixed after I cleared the CLASSPATH. I am unfamiliar with what CLASSPATH is for, and now I'm a bit worried that my image scanning process won't work right. There was something in my CLASSPATH refering to software I installed when I installed my scanner.

I can't test my scanner right now because it isn't hooked up, but I'd rather have Java abilities now than a scanner!

Thanks for your help

Steve
Steveam at 2007-11-10 3:08:01 >
# 8 Re: Error with javac
That's nice.

Basically CLASSPATH variable is used to find out the directories in which the class-files should be searched. From JDK1.1 onwards u have to set CLASSPATH, only if u want to add ur directories (or zip/jar files) in list of directories for searching class-files. But for this u have to include the default zip/jar file containing JDK class-files also. Here r some files u need to include in CLASSPATH (alongwith its full path) ...

JDK1.0 classes: classes.zip
JDK1.1 classes: classes.zip
Swing for JDK1.1: swingall.jar
JDK1.2 classes: rt.jar, tools.jar

Additionally u have to specify '.;' for including 'current directory' in the CLASSPATH. So that the classes in ur current dir (where u might be working) will be found.

So I think u forgot to add the path for 'rt.jar'. Add the path in the CLASSPATH ...

set CLASSPATH=.;C:\Program Files\PhotoDeluxe 2.0\AdobeConnectables;c:\jdk1.2\lib\tools.jar;c:\jdk1.2\lib\rt.jar

And it should work.

- UnicMan
http://members.tripod.com/unicman
unicman at 2007-11-10 3:08:59 >