943,837 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 122021
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 27th, 2004
0

Compile Java

Expand Post »
how do I compile and run a java program?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JavaBean is offline Offline
1 posts
since Jul 2004
Jul 27th, 2004
0

Re: Compile Java

to compile i believe you would run javac file.java and it should compile and to run it you would just use java file.class
and that should do it i believe you will have to locate these 2 files on your system javac and java i but not sure. this is of course if you are just running a command line program and not an applet
http://www.iam.ubc.ca/guides/javatut....1/stepbystep/

i have always just used text pad to do all my java stuff in cause you can set it up to compile and run your program
Team Colleague
Reputation Points: 36
Solved Threads: 2
PFO Founder
big_k105 is offline Offline
308 posts
since May 2003
Jul 28th, 2004
0

Re: Compile Java

This link may help you to understand how to compile and run java programs.
The only thing is I cant find which windows operating system its for, probably windows 98, 2000. However it can be easily adapted to windows xp!

LINK
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rickste_r is offline Offline
16 posts
since Jul 2004
Oct 20th, 2006
0

Re: Compile Java

Ok, so I found two lcations of this javac and every time i click on either one of them a window flashes by and disappears? How the heck are you supposed to run javac? How do you compile? The link doesn't help. It assumes you know how to compile. Sorry, I'm new to Java and I just wanna learn how to compile.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Barbank is offline Offline
5 posts
since Oct 2006
Oct 20th, 2006
0

Re: Compile Java

open your command prompt.
Change your directory to wherever your programs are...
Eg if they are in C:\java, then:
cd c:\java ENTER
Then javac fileName.java ENTER
That line compiles it, and creates a .class file,
Next... to execute the program...
java fileName.java ENTER

If you used an IDE like netbeans 5.0 or something else, you don't have to bother with this, but they can be confusing to start with, so I recommend just playing with notepad and command prompt till you get the hang of basic java.
Reputation Points: 20
Solved Threads: 4
Junior Poster
cms271828 is offline Offline
123 posts
since Oct 2006
Oct 20th, 2006
0

Re: Compile Java

OK, I got as far as getting into the C:\java folder, but there is no javac found so it stops there. I'm sorry. I'm a total newb here.

I ran the code javac MyFirstApp.java ENTER like you said, and I get an error saying it's not a command. HELP!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Barbank is offline Offline
5 posts
since Oct 2006
Oct 20th, 2006
0

Re: Compile Java

I made a little error above,,,
you just need to do java fileName to execute.

Ok, try this...
cd c:\java ENTER
SET CLASSPATH= ENTER
javac fileName.java ENTER
java fileName ENTER

That might work, but your JDK needs to be set up correctly, the command prompt needs to know the path to the JDK, you can do this by modifying the AUTOEXEC.BAT file.
Let me know how it goes with the commands I mentioned first.
Reputation Points: 20
Solved Threads: 4
Junior Poster
cms271828 is offline Offline
123 posts
since Oct 2006
Oct 20th, 2006
0

Re: Compile Java

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Compaq_Administrator>cd C:\java

C:\java>SET CLASSPATH=

C:\java>javac HelloWorldApp.java
'javac' is not recognized as an internal or external command,
operable program or batch file.

C:\java>java HelloWorldApp.java
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp/java

C:\java>java HelloWorldApp
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp

Still nothing. The official javasun site had a different way of resetting the path though. I don't understand either way...heh
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Barbank is offline Offline
5 posts
since Oct 2006
Oct 20th, 2006
0

Re: Compile Java

Post the code your trying to compile, the last couple lines in your last post look to be issues with your code
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JaksLax is offline Offline
21 posts
since Sep 2006
Oct 20th, 2006
0

Re: Compile Java

Java Syntax (Toggle Plain Text)
  1. /**
  2.  * The HelloWorldApp class implements an application that
  3.  * simply prints "Hello World!" to standard output.
  4.  */
  5. class HelloWorldApp {
  6. public static void main(String[] args) {
  7. System.out.println("Hello World!"); // Display the string.
  8. }
  9. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Barbank is offline Offline
5 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in Java Forum Timeline: Simple substring help!
Next Thread in Java Forum Timeline: IllegalArgument Exception in xjc





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC