• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to compile and run java??

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, friends,
i am just a very beginer, please don't laugh at me,i am using a windows 98, and want compile and run a java program, so what commands i shoud type to compile and run a java program, is that should be done in some specific directory or path? i don't know nothing about it so quite need your help, thanks very much!!
Kevin
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi kevin
sure. one who laughs at others never learns and here we are to learn.
i 'll try my way...
steps:
1. consider we have A.java as,
class A {
public static void main(String[] s) {
System.out.println("Hello World!");
}
}
2. we have it in directory C:\java\programs
3. we have to make sure that we have PATH environment variable set properly so we can run "javac" (which is a compiler for java program) from anywhere. ie. if we have java 1.4.1_02 installed in directory,
c:\j2sdk1.4.1_02 then we must have "c:\j2sdk1.4.1_02\bin" in the PATH variable. now, how to set PATH var?
3.1 as u r on win 98, go to autoexec.bat you have on ur system,
3.2 u might already see PATH variable there getting set to something
3.3 append at the end of it ";c:\j2sdk1.4.1_02\bin;" if you have PATH variable already in the autoexec.bat otherwise just write,
SET PATH=c:\j2sdk1.4.1_02\bin;
3.4 save autoexec.bat file
3.5 execute it to make sure it works for you in the command prompt. i hope you already know how to execute a batch file
4. now, coming to the original problem,
4.1 try to compile your java program as,
c:\java\programs>javac -classpath .;c:\j2sdk1.4.1_02\lib\tools.jar A.java
that should work.
Here, you see -classpath switch? you can also set CLASSPATH env variable just the way you did PATH var in autoexec.bat file to be,
SET CLASSPATH=.;c:\j2sdk1.4.1_02\lib\tools.jar
if you don't want to use -classpath switch (basically its like pre-configuring things).
try to see if this works for you.
on win 98 u might have to reboot computer to apply autoexec.bat settings to all command prompt window u open ...
regards
maulin
 
KEVIN YANG
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, Maulin,
thank you very much for your quik help, now i am installing the j2sdk1.4.1_02 and tring to figure out how to set up my classpath variable, there might be more problem coming to me, but i will try my best, thank you very much for your encourage!!
Kevin
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sun's tutorial "Your fisrt Cop O Coffee" is one of the best for these questions
http://java.sun.com/docs/books/tutorial/getStarted/cupojava/index.html
 
KEVIN YANG
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, Maulin,
Sorry for bother you again! Can you also tell me how to excute a autoexec.bat file? and "c:\java\programs>javac -classpath .;c:\j2sdk1.4.1_02\lib\tools.jar A.java" is one statement or two statement? and i like to use a classpath variable, if i use a classpath variable, how shoud i compile my Java program?
thank you very much!
Kevin
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just to be on safe side, reboot ur comp. because even if u execute autoexec.bat from one terminal window it wont affect other terminal window if u open one.
but anyways, assuming u've autoexec.bat in, c:\systems u can do following,
c:\systems>bat autoexec.bat OR
c:\systems>autoexec.bat OR
c:\systems>autoexec
all shd work..
regards
maulin
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"javac -classpath .;c:\j2sdk1.4.1_02\lib\tools.jar A.java" is one statement on command prompt
regards
maulin
 
KEVIN YANG
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, Maulin,
I stored my j2sdk1.4.2\bin in C:\Program Files\j2sdk_nb\j2sdk1.4.2\bin,
but after i set my autoexec.bat as SET PATH=C:\Program Files\j2sdk_nb\j2sdk1.4.2\bin and run it, it always say too many parameters,is there any problems in the statement?
Regards
Kevin
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, you should probably use PATH=%PATH%;C:\pathToYourJavaExecutable instead of just PATH=C:\pathToYourJavaExecutable

Second, I suggest that you try
SET PATH=%PATH%;C:\Progra~1\j2sdk_nb\j2sdk1.4.2\bin
replacing the "Program Files" part with "Progra~1" and see if that helps.

In my opinion it is always best to reboot after you change your autoexec.bat file.
[ August 13, 2003: Message edited by: Marilyn de Queiroz ]
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It should also be possible to use quotes; i.e.:
SET PATH=%PATH%;"C:\Program Files\j2sdk_nb\j2sdk1.4.2\bin"
The problem, BTW, is that it is complaining about the space in "Program Files"; it thinks that it is another parameter. The quotes should group everything into one parameter.
 
KEVIN YANG
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everybody here to help me!!
 
KEVIN YANG
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Success!!!
Thanks a lot everybody!!!

I am so exited, this is my first cup of java, it is so nice!!
I am enjoyed!!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic