File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes how to compile and run java?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to compile and run java??" Watch "how to compile and run java??" New topic
Author

how to compile and run java??

KEVIN YANG
Greenhorn

Joined: Aug 13, 2003
Posts: 6
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
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
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

Joined: Aug 13, 2003
Posts: 6
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
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
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


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
KEVIN YANG
Greenhorn

Joined: Aug 13, 2003
Posts: 6
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

Joined: Nov 04, 2001
Posts: 1871
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

Joined: Nov 04, 2001
Posts: 1871
"javac -classpath .;c:\j2sdk1.4.1_02\lib\tools.jar A.java" is one statement on command prompt
regards
maulin
KEVIN YANG
Greenhorn

Joined: Aug 13, 2003
Posts: 6
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
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
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 ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

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.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
KEVIN YANG
Greenhorn

Joined: Aug 13, 2003
Posts: 6
Thanks everybody here to help me!!
KEVIN YANG
Greenhorn

Joined: Aug 13, 2003
Posts: 6
Success!!!
Thanks a lot everybody!!!

I am so exited, this is my first cup of java, it is so nice!!
I am enjoyed!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to compile and run java??
 
Similar Threads
How to access the method using the object
What IDE Should I use?
Compiling first JSP program
What IDE Should I use?
compiling first JSP program