LinuxQuestions.org
Help answer threads with 0 replies.
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 07-05-2003, 05:59 PM   #1
matt_w_lambert
Member
 
Registered: Jan 2003
Location: WA
Distribution: Red Hat 9.0, mandrake 9.2
Posts: 194

Rep: Reputation: 30
java interpreter


I am trying to learn Java I downloaded sdk and when i use
java /filename
it tells me exeption in thred "main" Java.lang.NoClassdeffounderror

Can sombody help me out
 
Old 07-05-2003, 06:17 PM   #2
inkedmn
LQ Newbie
 
Registered: Sep 2001
Location: Southern California, USA
Distribution: Debian unstable :)
Posts: 22

Rep: Reputation: 15
check your classpath and make sure you're leaving the ".class" off of the file when you run it. so, if your file is Hello.class, you'd do:
Code:
java Hello
oh, and you can try this to see if your classpath is screwed up...
again, assuming your java class file is called Hello.class, run this:
Code:
java -cp . Hello
that's basically saying "including the current directory in my classpath when trying to run this"
if that works, then the problem is with your classpath.

oh, and any java class you run directly must have a method with the following signature:
Code:
public static void main(String[] args) { <your code here>}
if you don't have a method that looks like that, you may want to reread chapter one of your tutorial
 
Old 07-07-2003, 06:02 AM   #3
devil_slayer
LQ Newbie
 
Registered: Jul 2003
Location: Warsaw, Poland
Distribution: Debian testing/unstable
Posts: 5

Rep: Reputation: 0
The hello world program in Java looks like this:

Code:
public class HelloWorld  //the name of the main class "must" be the same 
                                   //as the name of the file 
                                   //(eg. this file should be called HelloWorld.java)
{
  public static void main(String args[])
  {
    System.out.println("Hello world!");
  }
}
Since Java is completley object-oriented "everything" must be in a class. That's why you have to have a main class that has the same nae as the file it is being compiled in.

To run this code you first have to do: javac HelloWorld.java
And then you'll get a file called HelloWorld.class, which you may run by writing: java HelloWorld (with no extension!)
 
  


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
Where is the Python Interpreter? Chomper Programming 8 01-15-2005 09:56 PM
bad interpreter???? yenonn Programming 4 09-25-2004 05:21 AM
interpreter gr33ndata Programming 5 04-23-2004 11:10 AM
java compilator and interpreter ??? gooma Linux - Software 15 12-29-2003 11:44 AM
bad interpreter penzilsinc Linux - Newbie 5 06-26-2002 01:51 PM

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

All times are GMT -5. The time now is 10:19 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