Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 05-30-2006, 06:37 PM   #1 (permalink)
 
Master Techie

Join Date: Mar 2004

Posts: 2,069

rookie1010

Default java noob question

Hello

I am trying to learn how to program in java.

i installed netbeans on my pc and i was wondering why i could not do a javac fro mthe command prompt?
rookie1010 is offline  
Old 05-30-2006, 08:12 PM   #2 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default

Did you install the JDK?
jaeusm is offline  
Old 06-01-2006, 04:29 PM   #3 (permalink)
 
Master Techie

Join Date: Mar 2004

Posts: 2,069

rookie1010

Default

thanks for the reply

by installing netbeans ide, have i not installed jdk,

i am running the java program in netbeans and they run ok, i thought that would mean that netbeans had automatically installed jdk to run java programs in the first place
rookie1010 is offline  
Old 06-01-2006, 05:02 PM   #4 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default

If the JDK is installed, you need to add the path to 'java' and 'javac' to your PATH environment variable. Otherwise, you'll have to add the path manually every time you call 'java' or 'javac' from the command line. For instance,

C:\Java\jdk1.5.0_02\bin\javac Class.java
jaeusm is offline  
Old 06-02-2006, 04:07 PM   #5 (permalink)
 
Master Techie

Join Date: Mar 2004

Posts: 2,069

rookie1010

Default

does installing netbeans mean that i have installed JDK?

how do i add java and javac to the PATH environment variable?

i have got 2 java folders on my c drive, the first one in porgram files and the second one in windows but neither have the jdk1.5.0_02 folder
the first one(progrm files/java) has j2re1.4.2_06 and jre1.5.0_01 folders and the second one(windows/java) has classes, packages and trustlib folder
rookie1010 is offline  
Old 06-03-2006, 12:18 AM   #6 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default

The Java Runtime Environment (JRE) does not include 'javac'. The JRE allows you to run java programs, but not compile them. 'javac' is in the JDK.

The JDK was previously referred to as the Java SDK. Maybe you have a j2sdk1.4.2_05 directory. If you do, 'javac' will be in the bin subdirectory. You could always just do a search for 'javac.exe' on your hard drive.
jaeusm is offline  
Old 06-03-2006, 06:33 AM   #7 (permalink)
 
Master Techie

Join Date: Mar 2004

Posts: 2,069

rookie1010

Default

thanks for the reply

i guess the runtime environment is the "java virtual machine"?

i found the javac.exe, it is present in the j2sdk1.4.2_04 directory,

will i have to compile all .java files from the j2sdk1.4.2_04/bin directory?

i guess intalling netbeans does not mean that i have installed the javac compiler, correct?

where can i add 'java' and 'javac' to the PATH environment variable.
rookie1010 is offline  
Old 06-03-2006, 06:09 PM   #8 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default

1. In Windows XP, right-click on 'My Computer' and select 'Properties'.
2. Click the 'Advanced' tab.
3. Click the 'Environment Variables' button at the bottom.
4. Select the 'Path' system variable in the list and click the edit button.
5. Add the full path you listed above (C:\j2sdk1.4.2_04\bin). All the different paths should be separated by semicolons.

You might need to reboot afterward.

As far as Netbeans goes (I don't know much about it because I don't use it), I would think that it was responsible for the installation of the SDK you found on your hard drive. Maybe it didn't add the installation to your path variable.
jaeusm is offline  
Old 06-03-2006, 07:24 PM   #9 (permalink)
 
Master Techie

Join Date: Mar 2004

Posts: 2,069

rookie1010

Default

thanks for the reply

is the runtime environment the "java virtual machine"?

i can get javac to work, and my hello world program compiles fine, however when i try to execute it using java hello.class command i get the following error message

exception in thread "main" java.lang.NoClassDefFoundError: hello/class

can you tell me if i need to include something else

my hello world program contains the following java code

public class hello
{
public static void main ( String[] args )
{
System.out.println("Hello World");
}
}

the program ran fine in the netbeans ide
rookie1010 is offline  
Old 06-04-2006, 01:05 AM   #10 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default

Drop the '.class' extension when running from the command line. For example, you should type:
Code:
java HelloWorld
And yes, the JVM is part of the JRE.
jaeusm is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On