Getting Started Help....

Hi everyone......

I just downloaded the jdk, and messed things up a bit. I had to add the correct path to the PATH variable, and after I did that I found I couldn't run the compiled code, getting the NoClassDefFound error. I've made sure there's nothing in CLASSPATH.

Before I messed with the PATH variable, however, I could run my first itsy betsy teeny weeny "Hello World" program.

Thanks to anyone who can help this noob! I really appreciate it! :)

In the meantime, I'm frustrated as I want to get going. :(

[545 byte] By [GodivaGirla] at [2007-10-2 4:47:37]
# 1
http://www.jcreator.com/download.htmi think this will help you out. it's a pain in the a** to deal with the path everytime, so why not just download a free IDE where you can just type in your code, press compile and get your programs to run. hope this helps.
LINNYCa at 2007-7-16 0:52:24 > top of Java-index,Java Essentials,New To Java...
# 2

Set the PATH using #5 of this document:

http://java.sun.com/j2se/1.5.0/install-windows.html

Make sure you don't have a CLASSPATH environment variable set.

Make sure that you have a file (produced by javac) with the name

<classname>.class

Change to the directory that contains the class file and use this command:

java -cp . <classname> Mind the period and surrounding spaces.

My suggestion:

Learn to compile and run programs, and use the classpath, from the commandline first, before you use a development tool. Otherwise you'll be facing the same problems later when you want to run programs without the aid of the tool.

ChuckBinga at 2007-7-16 0:52:24 > top of Java-index,Java Essentials,New To Java...
# 3
thanks LINNYC....and, actually, I was going to get Eclipse, but I thought I'd get started on the command line before dealing with an IDE, and I figure, since I ran into problems, I should at least learn what I'm doing and how to deal with it!
GodivaGirla at 2007-7-16 0:52:24 > top of Java-index,Java Essentials,New To Java...
# 4

Hi,

the compiled code, getting the NoClassDefFound error.

On 2 conditions this problem would occur.

One is the class name might be different from the file name. For example, your class name could be

class HelloWorld { ... } , but the file name saved could be helloWorld.java. When executing java helloWorld, you would get NoClassDefFound Error, 'coz at the runtime, your java would look for any .class files with the name helloWorld.class. But actual .class file name is HelloWorld.class, so you would get NoClassDefFoundErrror : helloWorld

Next is when you are using package, you should know how to execute a .class file with the package name. If you dont know how to execute a .class file with a package name, you would get this NoClassDefFound Error.

In case if there is a problem in setting JDK path, you would not be able to compile itself. Just type this in your command prompt...

PATH=C:\j2sdk1.4.2_09\bin;%PATH%

and type javac filename.java

and java filename

ensure the class name and the file name saved are sync..

FebTena at 2007-7-16 0:52:24 > top of Java-index,Java Essentials,New To Java...
# 5

Verify your java installation by going to a command prompt and typing:

java -version

You should see the following:

java version "1.5.0_05"

Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)

Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)

Now type the following into any directory and into the file: Hello.java:

public class Hello {

public static void main(String[] args) {

System.out.println("Hello world");

}

}

Make sure the case for Hello is strictly followed.

Next compile your code:

javac Hello.java

Then run your code:

java Hello

If this doesn't work, then remove the CLASSPATH variable from your environment, close your command prompt, and then start it again. Oh, and make sure your path variable is set to get to your JDK's bin directory before anything else - that helps.

I just did all of this on my new system and it worked fine. Tell me your results after following these instructions.

st.murphya at 2007-7-16 0:52:24 > top of Java-index,Java Essentials,New To Java...
# 6

Thanks......and yes, I wanted to learn on command line for the purpose you mention...and to understand.

I had already done everything in your post up to:

<b>java -cp . <classname> </b>

I had been using the command without the '-cp' option. When using that option, it said that it was an invalid option and it couldn't create the java virtual machine.

Now, as I said before...before I added the path to the environmental variable PATH, I could run the program. After....no more. And, I have made sure time and again CLASSPATH is not set.

I do appreciate everyone's help!

GodivaGirla at 2007-7-16 0:52:24 > top of Java-index,Java Essentials,New To Java...
# 7
St. Murphy....I am doing all that and am still getting the error. (I have the latest version, just having installed it today)Perhaps I set the PATH variable wrong? Cause it worked fine before I messed with that!
GodivaGirla at 2007-7-16 0:52:24 > top of Java-index,Java Essentials,New To Java...
# 8

> Thanks......and yes, I wanted to learn on command

> line for the purpose you mention...and to

> understand.

>

> I had already done everything in your post up to:

>

> <b>java -cp . <classname> </b>

>

> I had been using the command without the '-cp'

> option. When using that option, it said that it was

> an invalid option and it couldn't create the java

> virtual machine.

>

> Now, as I said before...before I added the path to

> the environmental variable PATH, I could run the

> program. After....no more. And, I have made sure time

> and again CLASSPATH is not set.

>

> I do appreciate everyone's help!

Please copy and post the command that you use and the exact error message you got.

And verify that when you issued the command, the prompt was showing the directory that contains the class file.

ChuckBinga at 2007-7-16 0:52:24 > top of Java-index,Java Essentials,New To Java...
# 9

> > Thanks......and yes, I wanted to learn on command

> > line for the purpose you mention...and to

> > understand.

> >

> > I had already done everything in your post up to:

> >

> > <b>java -cp . <classname> </b>

> >

> > I had been using the command without the '-cp'

> > option. When using that option, it said that it

> was

> > an invalid option and it couldn't create the java

> > virtual machine.

> >

> > Now, as I said before...before I added the path to

> > the environmental variable PATH, I could run the

> > program. After....no more. And, I have made sure

> time

> > and again CLASSPATH is not set.

> >

> > I do appreciate everyone's help!

>

> Please copy and post the command that you use

> and the exact error message you got.

>

> And verify that when you issued the command, the

> prompt was showing the directory that contains the

> class file.

Well,

1) I didn't see the 'Quote Original' Button.....apologies

2) I see my stupid stupid mistake. I was typing in 'java HelloWorld.java'

(sigh)

but thanks to all who gave their time....again, I appreciate it.

I feel pretty ashamed here....

GodivaGirla at 2007-7-16 0:52:24 > top of Java-index,Java Essentials,New To Java...
# 10
No worries. That mistake is common and happens to most. Have fun coding!
st.murphya at 2007-7-16 0:52:24 > top of Java-index,Java Essentials,New To Java...