Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi am new to java.I want to know all the steps to get my first java program running.I have installed jdk6.0 and i am using noted as text editor. Following are the steps m doing:
1. Create a source file in notepad
2. then i go to cmd and go to the directory where i have saved my file.
3. Then type D:\>java -cp . HelloWorldApp and enter.
It comes up with an error: couldnot find or load main class HelloWorldApp.

Can anyone help??
Posted

HI,

Instead of using notepad you can use Eclipse IDE or Netbean IDE for running java progam.


Thanks
R.Karthik
http://www.indiumsoft.com/core-qa-offerings/test-automation"
 
Share this answer
 
v2
Comments
TorstenH. 10-Oct-14 8:09am    
+5!

https://www.eclipse.org/downloads/
Create the java source file HelloWorldApp.java:
C#
import java.io.*;

public class HelloWorldApp {
    public static void main (String[] args) {
        System.out.println("hello world");
    }
}


Run your command line tool:
XML
javac HelloWorldApp.java
java HelloWorldApp


Result:
hello world
 
Share this answer
 
v2
When you get error
SQL
couldnot find or load main class HelloWorldApp.


The Actual issue is it cannot find the class you have compiled.

This also can happen if your class name is different than you are trying to run. Many times we save the file with name that is different from class name. and then try to run the name of file than the class.

Here is what you can do:

1) Traverse till the path in command prompt where your HelloWorldApp.java file is saved. For example, Mine is at path "D:/JAVA_PROJECT/HelloWorldApp.java"

I will traverse till "D:/JAVA_PROJECT/" in command prompt will look like this

D:\JAVA_PROJECT


2) Type command to compile your code to create class (Remember, You should save your file with the name of your class, because compilation will always happen with JAVA CLASS NAME)


D:\JAVA_PROJECT\javac HelloWorldApp.java

After that hit enter

Now if you will go to the folder where you have saved your HelloWorldApp.java, you will see a file HelloWorldApp.java, this is your main class for which you are getting error
couldnot find or load main class HelloWorldApp.


Now if you follow thrid step, you will see the output of your class

3) D:\JAVA_PROJECT\java HelloWorldApp

Hit enter and bang!! there will be your output.


Other answers are quite better than mine.. But i thought i should provide information about the error you are getting.

I hope this will help
 
Share this answer
 
Did you compile?

If you do it on the command line (which is absolutely not recommended cause it's just making things complicated):

http://docs.oracle.com/javame/dev-tools/jme-sdk-3.0-mac/UserGuide-html/z400007747176.html[^]
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900