Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
Due to network maintenance being performed by our provider, LQ will be down starting at 05:01 AM UTC. The exact duration of the downtime isn't currently known. We apologize for the inconvenience.
|
 |
08-04-2003, 09:22 AM
|
#1
|
|
LQ Newbie
Registered: Jul 2003
Location: Nairobi
Distribution: Debian 4.0
Posts: 10
Rep:
|
Running Java Class Files
Hi!Guys,
I downloaded the latest Java SDK and installed it in my /usr/downloads folder without any problems.When I make my java file I compile it without any problems but when I try to run it with the java HelloWorld.java command I get a "class not found" error what could be the problem.
Anybody got any ideas post them here
|
|
|
|
08-04-2003, 09:58 AM
|
#2
|
|
Senior Member
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120
Rep:
|
Easy mistake to make when starting out
compile the program
javac HelloWorld.java
to actually run the program
java HelloWorld
You won't need to worry about classpath or anything for now as long you run it from the actual directory it was compiled in
|
|
|
|
08-04-2003, 08:37 PM
|
#3
|
|
Member
Registered: Dec 2002
Location: Singapore
Distribution: Fedora Core 6
Posts: 647
Rep:
|
Yeap!
To run, Don't put ".java".
|
|
|
|
08-05-2003, 01:14 AM
|
#4
|
|
LQ Newbie
Registered: Jul 2003
Location: Nairobi
Distribution: Debian 4.0
Posts: 10
Original Poster
Rep:
|
I know that to run a java class you don't put ".java" I've already programmed in java but in the windows environment.I'm guessing that the class cannot be found coz even in windows when try running a class file that doesn't exist you get an error that goes like this:
"Exception in thread "main" java.lang.NoClassDefFoundError:"
which is the error I'm getting yet the class file exists in my Linux environment.
Got any ideas,post them here.
|
|
|
|
08-05-2003, 01:41 AM
|
#5
|
|
Senior Member
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120
Rep:
|
Only thing I can think of if you are in the same directory and have compiled it okay is you have named the actual filename.java differently from the class that it holds
ie. you've saved it as MyClass.java
when the actual class has been defined as
public myclass
{
}
sort of thing, or named it something completely different
|
|
|
|
08-06-2003, 10:05 AM
|
#6
|
|
LQ Newbie
Registered: Aug 2003
Posts: 1
Rep:
|
Hi all
How do I know what version of Java is installed on my Red Hat 8 ?
How do I replace it with a newer version (what do i remove, what variable do I change, how to install the new sdk and where will it be on the HDA)
I have tried to import the awt class, it compiles.
But if I import swing, this can t be found.
Thanks

|
|
|
|
08-06-2003, 10:34 AM
|
#7
|
|
Member
Registered: Dec 2002
Location: Singapore
Distribution: Fedora Core 6
Posts: 647
Rep:
|
To check Java version, type
java -version
To remove java.
How did you installed? RPM or self-extracting.
If rpm, just use the normal rpm uninstall method.
If self-extraction, just delete the directory, that's it.
I recommand you use self-extraction package.
You can choose to download rpm or self-extraction on the sun website.
It's easier and it can easily put the directory wherever you want, just as a standalone. And give the PATH to the "YourJDKDirectory/bin".
And it can easily co-exist with several version. You don't need to remove the old version. Just put the new one beside and change the PATH, that's it.
To import swing, swing is in the "javax" package. Not in the "java" package.
Like this.
import javax.swing.*
Last edited by moeminhtun; 08-06-2003 at 10:38 AM.
|
|
|
|
08-07-2003, 02:37 AM
|
#8
|
|
LQ Newbie
Registered: Jul 2003
Location: Nairobi
Distribution: Debian 4.0
Posts: 10
Original Poster
Rep:
|
Hi!,
I know that in windows you set the environment variable so that you can compile and run java apps from any directory,Can the same thing be done in Linux?
If it can like share it with guys like me who are trying to shake off the addiction to windows
Cheers
|
|
|
|
08-07-2003, 04:42 AM
|
#9
|
|
LQ Newbie
Registered: Aug 2003
Posts: 12
Rep:
|
You have to set your PATH env. variable to include the Java binaries. To see your current path type "echo $PATH" in a terminal, to add Java, type "export PATH=$PATH:/your/path/to/java/bin" or add the line to your ~/.bashrc
|
|
|
|
08-07-2003, 06:42 AM
|
#10
|
|
Member
Registered: Dec 2002
Location: Australia
Distribution: Gentoo
Posts: 161
Rep:
|
You should also make sure that you have your $CLASSPATH variable set before you run, and that this contains the path to both the java classes (rt.jar) and to your own classes.
Remember compiling and running apps depend on different environment variables.
$PATH simply lets you execute the java binaries from any location, however $CLASSPATH tells the Java VM where to look for the classes to execute.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 07:08 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|