Click to See Complete Forum and Search --> : Help Me With Java!
I have just downloaded java and I do not know what to do. My web tutorial says to: -
Ok enough explanation, lets start coding! This is the most basic of programs and all programming tutorials and courses I've seen seem to start with it.
Fire up your text editor and enter the code listed below and save it as HelloWorld.java.
public class HelloWorld {
public static void main (String [] args) {
System.out.println("Hello World!!!");
}
}
After saving this file open an ms-dos command box (Start->Run->command.com should do the trick, on newer versions of Windows try cmd.exe) or a *NIX terminal and change to the directory where you saved the source file. To compile a java source file we use javac, the java compiler. So to compile out HelloWorld.java program execute the following statement: javac HelloWorld.java. If you copied the code exactly right as shown above the compiler won't say a thing and you'll just end up with a new command prompt. This is good!!! Now to run your program use the java interpreter (java.exe) by executing java HelloWorld. The computer now reads your file and should print "Hello World!!!" before leaving you at a fresh command prompt.
I did this but my prompt says: -
'javac' is not an internal or external file
How do I do it?
buntine
01-29-2005, 10:02 AM
This means that the Java Compiler (javac) cannot be found. Its probably because you havent set a path variable pointing to it.
You can just provide the entire path to the javac program. eg C:\\j2sdk1.4.1\bin\javac
Regards.
ray326
01-29-2005, 01:12 PM
Note that javac is in the JDK, not the JRE. You have to download and install the full developer's kit, not just the runtime.
How do you set a path varible? It gets boring typing the whole thing out. When I try and do:-
C:\j2sdk1.4.2_07\bin\javac HelloWorld.java
it says
error: cannot read: HelloWorld.javaI have typed the code exactly as it is in my first thread
I am using JDK.:D :D :D :D :D
ray326
01-29-2005, 01:28 PM
Originally posted by Hiya
How do you set a path varible? It gets boring typing the whole thing out. When I try and do:-
C:\j2sdk1.4.2_07\bin\javac HelloWorld.java
it says
I have typed the code exactly as it is in my first thread When you do that are you in the directory with HelloWorld.java?
PATH=%PATH%;C:\j2sdk1.4.2_07\bin
Khalid Ali
01-30-2005, 09:16 AM
there are 2 possibilities when setting up the variables/path and classpath.
1. If you are using windows <2000 (95 to ME)
1.A
then open up autoexec.bat file it resides in your C:\ folder.
1.B
it typically already have some paths set, what you need to do is locate the following line
set PATH=%PATH%;
1.C
type the following text one line above of the path statement
set JAVA_HOME=C:\j2sdk1.4.2_07
1.D
Now look at the PATH statement if it is present, it may have some other values following %PATH%.
1.E
Now towards the end of the PATH statement append the following values.I am guessing
that [C:\j2sdk1.4.2_07]is your correct path where you have your JDK installed. your
path statement should look like this after you make changes to it.
set PATH=%PATH%;%JAVA_HOME%\bin;%JAVA_HOME%\lib
1.F
The above should take care of your path setup now locate an entry that may look like the one
below
set CLASSPATH=%CLASSPATH%;.;
1.G
if it doesn't exist create one just like the above do not forget to append a . (dot
character followed by a semi col(;)character.
I hope the above helps you take care of setting Java path for win 95,98 and ME.
-----------------------------------------------------
2.Starting from windows >2000 and above you change these values using a
QUI tool for persistent path settings.Following are instructions for windows 2000
and its the same for windows XP as well. This tutorial presumes that these
variables have not been created on your system already.
2.A
Click on Start>Settings>Control Panel>System (its a little icon with a pc monitor )
2.B
This will bring up System Properties window,locate a tab with the caption Advance and
click on it.
2.C
From the Advance screen click on button with caption Environment Variables. There are
2 section in the next screen. Top Section for the user that you are logged in as and the lower section
is for the Complete System.We want to work with the User variables.... section only.
2.D
Click on New button and enter these 2 values, for
Variable Name = JAVA_HOME and for
Variable Value = C:\j2sdk1.4.2_07 then click Ok
2.E
Click on New button again and enter these 2 values, for
Variable Name = PATH and for
Variable Value = %PATH%;%JAVA_HOME%\bin;%JAVA_HOME%\lib then click Ok
2.F
When you are up to this point try compiling and running your program if does not work
then you will need to amend the classpath value as follows.
Click on New button again and enter these 2 values, for
Variable Name = CLASSPATH and for
Variable Value = %CLASSPATH%;.; then click Ok
You are all set. click ok to close all windows and go to DOS prompt to test your setting. One word of caution
here is that in win2k if you make any changes to your environment variables and you already have a dos
window open, then to reflect the most currently made changes you will need to open a new session of dos window.
To find out why you may want to write an email to Bill Gates.:D
I just hope it helps you and others. Environment variables are nothing but a pre executed command that lets
windows know where a particular program resides so that one can use that program with equal ease from anywhere
in the windows directory structure. (its just like a short cut that you create in windows).
Note To The Seasoned Readers:
Have I overlooked anything? Please let me know. Thanks
It works now, thanks to "C:\j2sdk1.4.2_07\bin\javac".