-
Problems regarding "Hello, World!"
Hello, I have some small problems with running my first Java program through MSDOS. As a student starting a Computer Science course this October,I have been asked to familiarise myself with the language before the course begins.
To begin with I downloaded the JDK Beta 2 here. I then followed this tutorial, also from the Sun site here.
Now the problems initially occur when, after saving the code above as HelloWorldApp.java and then attempting to compile it in the command prompt window. I get an error message stating "javac is not a recognized external or internal command..."
I have found a way around this by creating an env.bat file with the following:
Code:
SET JAVA_HOME=C:\Program Files\Java\jdk1.6.0
SET PATH=%PATH%;%JAVA_HOME%\bin
However surely I am not required to run env.bat each time I attempt to compile my program?
-----
The second problem then occurs after compiling the program and creating the corresponding .class file. After attempting to run the completed file I recieve another error message "Exception in thread "main" java.lang.NoClassDefFoundError:".
Again I can get around this using:
Code:
java -cp . HelloWorldApp
However, again this cannot be the correct way to go about running my program?
Any help is much appreciated, as I have only just began to learn the language.
-
I have installed JDK1.4 into c drive so I have written follwing command in system variable Path
C:\Jdk1.4\bin
After setting variable restart your computer.
Now you can compile and run program from yor directroy.
After writing source compile it using follwing command
javac fileName.java
Create HTML file for your applet writing this code in body tag.
<APPLET CODE="FileName.class" WIDTH=150 HEIGHT=25>
</APPLET>
Type following on command prompt
appletviewer Hello.html
I hope this may help you.
rathorek
-
rathorek - I think he's asking about a console app, not necessarily an applet, and I would assume an entry level CSC course will begin with console apps.
Lloyd9 - If you are using MSDOS only, put those commands in autoexec.bat, and restart your machine. They will load everytime the machine restarts so you don't have to run env.bat every time.
Alternatively, if you are running Windows rather than just MSDOS, you can set the environment variables without a batch file. Open the System widget in your control panel, click the advanced tab, and click the 'Environment Variables' button. You can use that interface to add JAVA_HOME and modify your path statement to include \bin.
Good luck, and feel free to PM me if you have any further install questions.
-
Where did you install java to, if its the c drive then I usually, do this in my console
path =c:\jdk1.5.0_06\bin
javac test.java
java test
If that doesnt work you may have a problem with your enviroment variables. Check your computers eviroment variables.
Similar Threads
-
By jlopes151 in forum Database
Replies: 1
Last Post: 11-21-2005, 04:32 AM
-
By Sandra in forum VB Classic
Replies: 0
Last Post: 07-19-2002, 01:41 AM
-
Replies: 2
Last Post: 05-29-2002, 01:38 PM
-
Replies: 0
Last Post: 10-04-2000, 04:05 AM
-
By Mike Jewson in forum Java
Replies: 0
Last Post: 06-01-2000, 12:32 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks