LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   java interpreter (https://www.linuxquestions.org/questions/programming-9/java-interpreter-70361/)

matt_w_lambert 07-05-2003 05:59 PM

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

inkedmn 07-05-2003 06:17 PM

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 :)

devil_slayer 07-07-2003 06:02 AM

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!)


All times are GMT -5. The time now is 08:29 AM.