LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 08-04-2003, 09:22 AM   #1
hackersapien
LQ Newbie
 
Registered: Jul 2003
Location: Nairobi
Distribution: Debian 4.0
Posts: 10

Rep: Reputation: 0
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
 
Old 08-04-2003, 09:58 AM   #2
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
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
 
Old 08-04-2003, 08:37 PM   #3
moeminhtun
Member
 
Registered: Dec 2002
Location: Singapore
Distribution: Fedora Core 6
Posts: 647

Rep: Reputation: 30
Yeap!

To run, Don't put ".java".
 
Old 08-05-2003, 01:14 AM   #4
hackersapien
LQ Newbie
 
Registered: Jul 2003
Location: Nairobi
Distribution: Debian 4.0
Posts: 10

Original Poster
Rep: Reputation: 0
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.
 
Old 08-05-2003, 01:41 AM   #5
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
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
 
Old 08-06-2003, 10:05 AM   #6
JeffHervouet
LQ Newbie
 
Registered: Aug 2003
Posts: 1

Rep: Reputation: 0
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

 
Old 08-06-2003, 10:34 AM   #7
moeminhtun
Member
 
Registered: Dec 2002
Location: Singapore
Distribution: Fedora Core 6
Posts: 647

Rep: Reputation: 30
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.
 
Old 08-07-2003, 02:37 AM   #8
hackersapien
LQ Newbie
 
Registered: Jul 2003
Location: Nairobi
Distribution: Debian 4.0
Posts: 10

Original Poster
Rep: Reputation: 0
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
 
Old 08-07-2003, 04:42 AM   #9
julienp
LQ Newbie
 
Registered: Aug 2003
Posts: 12

Rep: Reputation: 0
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
 
Old 08-07-2003, 06:42 AM   #10
acjt
Member
 
Registered: Dec 2002
Location: Australia
Distribution: Gentoo
Posts: 161

Rep: Reputation: 30
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Running a Java executable class from another executable class LUB997 Programming 22 07-24-2005 04:57 AM
Java Question on using your own class k1ll3r_x Programming 2 01-22-2005 10:11 AM
Compile Java - .class, .java, .jar ? woranl Programming 2 11-09-2004 10:12 PM
Installing Java running jar files jariep Red Hat 1 04-12-2004 11:11 AM
can't run java class files in linux JIV Programming 6 03-25-2003 01:20 AM


All times are GMT -5. The time now is 01:43 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration