| Navigation
|
|
|
| User Tools
|
|
|
| Site Statistics
|
|
|
Currently 0 registered users and 3 guests browsing.
29 articles available for viewing.
1317491 total page hits.
Welcome to our newest registered user, choonchan!
|
|
|
Other Languages -> Java
Compiling and Executing Your Java Program
- by Coolio on 05/24/06, 9:45PM CEST (1430 Views)
Compiling the source code
In order to convert your Java code into a program it needs to be compiled. First you must save the source code with the same name as you gave it in the class declaration, with the extension ‘.java’. In the case of this program the name will be HelloWorld.java. It should be noted that this is case sensitive.
Then, to compile the program you should locate the working directory of the code through the console/terminal window and in it type:
javac HelloWorld.java
If your program is named something else replace HelloWorld with the relevant name. If there are no syntax errors in your program you should get a successful compilation message. If you have broken any syntax rules it will do its best to provide a meaningful error message to try to steer you towards the problem.
A common error is the following:
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
This problem usually indicates your classpath has not been set correctly – it cannot find the .class file of your program. This can usually be amended by typing:
set CLASSPATH=
which will set the classpath to the current directory.
Executing the program
Once the source code has successfully compiled it will have created a file with the same name but with a .class extension. This is your program and to execute it you need to type:
java HelloWorld
If the commands javac and java appear not to be recognised check the article on "Prerequisites for Java Programming".
Hopefully by now you should have been able to create and execute your first program in java, more tutorials will follow shortly.
Seen this article somewhere else? Report it for plagiarism!
Noticed an error in this article? Tell us what's wrong!
View Comments for this Article
Comments
Comment by choonchan on 08/10/10, 3:44AM CEST
21hGWS [a href="http://thsuocgnfwoa.com/"]thsuocgnfwoa[/a], [url=http://inywieqnzieo.com/]inywieqnzieo[/url], [link=http://ehgybbaizxmi.com/]ehgybbaizxmi[/link], http://beiecavjqbxp.com/
|
| Comment by lymanknap on 08/07/10, 1:16AM CEST
Qvpgq5 [a href="http://ltjwyimgcnsp.com/"]ltjwyimgcnsp[/a], [url=http://metosqfhpwre.com/]metosqfhpwre[/url], [link=http://tiqabgguaspe.com/]tiqabgguaspe[/link], http://ttxtkxzwcrdv.com/
|
|
Want to add a comment? Register a free account or Login if you already have one.
|
|
All content on this site is property of www.juxtaposing.com. Do not copy anything on this site without prior written permission of the site owner.
|
|
| © Copyright 2006 www.juxtaposing.com
|
|