Solved

Problems with "Hello World" example

Posted on 2004-10-04
7
245 Views
Last Modified: 2010-03-31
I have this program:
****************************
class hello
{
   public static void main(String args[])
   {
      System.out.println("Hello World!");
   }
}
****************************
I saved this program to my hard disk as "hello.java", then I run "javac hello.java". After this I use: "java hello"  and I get this message: Exception in thread "main" java.NoClassDefFoundError: hello"

What do I have to add to my program, how do I compile it ???


0
Comment
Question by:probine
7 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 12215960
Try this:

java -classpath . hello
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12215965
set classpath=%classpath%;.
0
 

Author Comment

by:probine
ID: 12216043
I am going from the beginning, because it did not work:

1. I have installed Java under my "d:". It looks like "d:\Java"
2. When I compile the "hello.java" I do this:

- I move to the d:\Java folder, so I get this path:

D:\Java\bin>javac d:\Java\programs\hello.java

D:\Java\bin>java -classpath . hello

It doesn't work.

How do I register the path to javac and hava, so I do not have to always type the full path and how do I run this program ???
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 86

Accepted Solution

by:
CEHJ earned 50 total points
ID: 12216060
java -classpath d:\Java\programs hello
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12216084
You need to put the java bin directory on your path. Look up 'Environment variable' in Windows help
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12216118
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12216204
8-)
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Checkbox and ListView in Android Layout 4 67
tomcat not starting 6 45
hibernate example issues from command prompt 10 42
Java: The Public Class Main 4 17
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question