Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

how to use the compiler

  Asked By: Aysel    Date: Oct 04    Category: Java    Views: 854
  

I have a brief knowledge of visual basic.
Now I bought a book two days ago with a title
"Teach Yourself Java in 21 Days"
now I have started this book and the first exercise Hello World
The problem is I do not understand how to use the compiler.

This is what I have done in notepad.

Class HelloWorld{
public static vooid main (String args(]) {
System.out.printIn("Hello World!");
}
}

Share: 

 

10 Answers Found

 
Answer #1    Answered By: Brandon Tucker     Answered On: Oct 04

You'll just go on command line and you'll have to execute the following command
javac HelloWorld // for compilation
java HelloWorld // for execution
but make sure you are in the dir where your class  is located and jvm is
installed.

 
Answer #2    Answered By: Al Allen     Answered On: Oct 04

Save ur program as "HelloWorld.java"
and save it in the directory where u have installed jdk.
like C:\jdk1.3\bin
save it in the bin folder.
Go to the Dos prompt and change ur directory to this bin folder
now type javac HelloWorld.java
C:\jdk1.3\bin>javac Helloworld.java
this will compile the program and make the byte code for this,after
successful compilation u will get a file named HelloWorld.class
now type java  HelloWorld to run ur program
C:\jdk1.3\bin\java Helloworld
this should work
Assuming C:\jdk1.3 is the path where u have installed java

Better option is:
save the file in any folder u like
for eg
C:\programs\java
now here u have to specify the path of ur java compiler
set PATH=C:\jdk1.3\bin;
now
C:\programs\java>javac HelloWorld.java
then
C:\programs\java>java HelloWorld.java.


just make sure u write "public static  void main  (String args[])"
and not public static vooid main (String args(])

 
Answer #3    Answered By: Viola Hanson     Answered On: Oct 04

Java is case Sensitive and better write the code with full attention as one
typing mistake can stop ur code from working.

 
Answer #4    Answered By: Arthur Cole     Answered On: Oct 04

please put this code in c:\\jdk1.3\\bin
compile this code
javac HelloWorld.java
java HelloWorld

 
Answer #5    Answered By: Jim Williamson     Answered On: Oct 04

I get it now.
Just have one more question I am unclear on how to specify the path
It works if I put it in the C:\jdk1.1.8\bin folder.
but I have made my own folder C:\Java and am not sure
what to put in my MS-DOS PROMPT for the path.

And I guess I should not make typing mistakes like
vooid instead of void.

 
Answer #6    Answered By: Sherri Parker     Answered On: Oct 04

Run the below statement in command prompt and compile & execute java
files.
set PATH=%PATH%c:\jdk1.1.8\bin;

 
Answer #7    Answered By: Rachel Barnes     Answered On: Oct 04

One thing you should do is :

Write the path in the autoexec.bat file.

for e.g. path=d:\jdk1.3\bin;d:\jdk1.3\lib

here, d: is where your jdk1.3 is installed. use your own version of jdk.

Thus, put the path of the jdk for both the bin and the lib and then save
autoexec.bat file. and close it.

Run the autoexec.bat file at the command prompt by giving the command "autoexec"
at the root. and then try running your HelloWorld program. It must run.

If you encounter a problem  that your compiler  throws the error like "javac is
not the internal command.... " or something similar to it, then try running the
autoexec.bat file everytime you open the new command prompt...

try thins and let me know if it works... according to me it should...

 
Answer #8    Answered By: Julio Morgan     Answered On: Oct 04

You can also set the PATH variable by following way
Settings--> Control Panel -->System -->Advanced -->Environment Variables
-->System Variables -->Path -->Edit-->Add the path to java  BIN directory
also along with the previous content.

By doing this you need not run the batch file or set PATH everytime you run
java program.

 
Answer #9    Answered By: Opal Alexander     Answered On: Oct 04

u have to instal (jdk) first

then u have to add the path: <jdk home>/bin to Path

inviroment variable in windows or unix as u have
then from the path u save the file *.java in write:

javac filename.java then press Enter.

this will comile the program

if u wanna run it u have to write:

java filename then press enter

Have anice cup of Java

 
Answer #10    Answered By: Coleman Smith     Answered On: Oct 04

1st you have the word vooid this should be void.
2nd you need to down load JDK from the Sun's Java site.
I would down load a program called JGrasp I find this one works OK.

 
Didn't find what you were looking for? Find more on how to use the compiler Or get search suggestion and latest updates.




Tagged: