LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 11-23-2006, 12:48 PM   #1
M$ISBS
Member
 
Registered: Aug 2003
Posts: 834

Rep: Reputation: 30
Java question


I installed the java JDK and went through a tutorial but when it came to do javac I get command not found. I searched my whole system several different ways and it seems I dont have javac. How do I get it?

I am using slackware 10.2

Thanks
 
Old 11-23-2006, 01:19 PM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by M$ISBS
I installed the java JDK and went through a tutorial but when it came to do javac I get command not found. I searched my whole system several different ways and it seems I dont have javac. How do I get it?
By installing the JDK, I guess you only installed the JRE (runtime).
 
Old 11-23-2006, 01:50 PM   #3
M$ISBS
Member
 
Registered: Aug 2003
Posts: 834

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by jlliagre
By installing the JDK, I guess you only installed the JRE (runtime).
The instructions said to install the JDK so I did, I also installed the JRE after.
 
Old 11-23-2006, 02:25 PM   #4
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
You should not need to download a separated JRE. The SDK already has a JRE. The error you are getting is most likely because you don't have java on your path. A quick search in this forum for Java Path will bring some threads. This question is very common and even I have answered it more than once. You could also search google.com for "java path linux" or even at Sun's site there is a tutorial about that.

I won't post any direct links, this is just a simple case of searching...
 
Old 11-23-2006, 02:49 PM   #5
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi, M$ISBS -

1. The "official" instructions for installing Sun Java are here:
http://java.sun.com/j2se/1.5.0/install-linux.html

2. I'll admit that that the instructions can be confusing if you've never done it before. Please feel free to post any follow-on questions to LQ.

3. In your posts, please try to be as SPECIFIC as possible.

For example, cut/paste the filename you're trying to extract (this would give a lot of information: it would tell us whether it's the JRE or the JDK, whether it's an .rpm or a .bin - or even whether it's Sun Java or "something else").

Please, too, cut/paste exact error messages you might be getting.

Good luck .. PSM
 
Old 11-23-2006, 04:29 PM   #6
M$ISBS
Member
 
Registered: Aug 2003
Posts: 834

Original Poster
Rep: Reputation: 30
Thanks for the replies. I found the file javac. I now have a new problem though. When I run java HelloWorldApp, I get these errors:


Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp/java

Does this look hard to fix?
I know nothing about java and am just starting out.
 
Old 11-23-2006, 04:44 PM   #7
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
could you please post the code? we'd be more than happy to help you.

oh, and don't let the mass error runtime code throw you off, Java likes doing that.

Last edited by indienick; 11-23-2006 at 04:45 PM.
 
Old 11-23-2006, 06:17 PM   #8
M$ISBS
Member
 
Registered: Aug 2003
Posts: 834

Original Poster
Rep: Reputation: 30
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
 
Old 11-23-2006, 07:09 PM   #9
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
is the name of the file HelloWorldApp.java?

edit: fixed typo

Last edited by nadroj; 11-23-2006 at 07:23 PM.
 
Old 11-23-2006, 07:17 PM   #10
M$ISBS
Member
 
Registered: Aug 2003
Posts: 834

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by nadroj
is the name of the file HellowWorldApp.java?
Without the w in hello, otherwise, yes.
 
Old 11-23-2006, 07:26 PM   #11
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
i made the same filename and pasted your code and tried it (on windows) and it compiled and ran without any messages.
when you use 'javac' to compile you include the '.java' in the filename, when you run it with 'java' you dont include any extension, just 'java HelloWorldApp', is this what your doing?
 
Old 11-23-2006, 07:52 PM   #12
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
hmm....I would try removing the compiled .class file
Code:
$ rm -f HelloWorldApp.class
, recompiling it
Code:
$ javac HelloWorldApp.java
, then running it
Code:
$ java HelloWorldApp
.

I hope it works
 
Old 11-23-2006, 09:39 PM   #13
Sepero
Member
 
Registered: Jul 2004
Location: Tampa, Florida, USA
Distribution: Ubuntu
Posts: 734
Blog Entries: 1

Rep: Reputation: 33
"Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp/java"

Interesting error message. I remember getting garbage messages like this whenever I would try to create .jar files.

I haven't programmed Java in a couple years now, but you might want to try putting "public" on your class:
public class HelloWorldApp {
 
Old 11-23-2006, 10:22 PM   #14
M$ISBS
Member
 
Registered: Aug 2003
Posts: 834

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by nadroj
i made the same filename and pasted your code and tried it (on windows) and it compiled and ran without any messages.
when you use 'javac' to compile you include the '.java' in the filename, when you run it with 'java' you dont include any extension, just 'java HelloWorldApp', is this what your doing?
nadroj:
Yes, thats exactly how I am doing it.

indienick:
I tried that and I get the same error messages as before.

I just tried something different. I logged in as root and tried it, but I had to put ./ in front of javac and java, the long list of errors went away but I still get:

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


Last edited by M$ISBS; 11-23-2006 at 10:27 PM.
 
Old 11-23-2006, 10:49 PM   #15
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
did you setup the environment variables properly? it should be in the documentation on the site that you downloaded it from
 
  


Reply



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
Java question Jongi SUSE / openSUSE 2 09-19-2005 01:07 PM
Java Question k1ll3r_x Programming 2 08-20-2005 08:10 PM
Java question biojayc Linux - Newbie 8 03-22-2005 03:42 PM
java question zaicheke Programming 5 02-15-2005 12:40 PM
Java Question k1ll3r_x Programming 3 11-13-2004 04:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:00 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration