This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Help with my first project hello world Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with my first project hello world" Watch "Help with my first project hello world" New topic
Author

Help with my first project hello world

saif kazi
Greenhorn

Joined: Jul 21, 2012
Posts: 5
hello
when i was compiling my first program it end me with this error



here is my java script

Joe Ridener
Ranch Hand

Joined: Jul 16, 2012
Posts: 86
Did you set your Environment Variables???

Did you use the javac command to compile it into bytecode before the java MyFirst statement??? You should have a MyFirst.class file sitting right next to your MyFirst.java file if you did this correctly.

To set the Environment Vars you open the start menu and right click on my computer ..from there go to properties. Open properties and click the advanced tab (this should work on all Vista 7 and XP). Scroll down find the variable that is Path or PATH. It is a semi-colon separated list. Each entry is terminated with a semi-colon and before you add a new path you must place a ; before your next entry which will be to the bin folder located in your jdk. The bin folder should contain such applications such as jar, javac, java and so forth. The last folder should be bin\ and the first should be C:\ in this string that is added to Path.

The second thing you may have done wrong (by the sounds of it this is the case) you must first type

javac MyFirst.java <enter>
java MyFirst <enter>
and it should run.

Also make sure that the current directory of the command line is where your .java file is located. For example, if your command line looks like this

C:\Documents and Settings\Joe\Desktop >

My HelloWorld.java file must be placed on my Desktop...otherwise it will not find it. You can use the cd command (cd = Change Directory), you can right click on the command line or it's shortcut icon and go to properties and change the path that it is pointing to for good (ask and Ill tell you exactly how to do this). Or you can simply place the file in the appropriate directory that it is pointing to.



saif kazi
Greenhorn

Joined: Jul 21, 2012
Posts: 5
hey
there is MyFirst.class in folder and i tred the sam

javac MyFirst.java <enter>
java MyFirst <enter>

but no luck
saif kazi
Greenhorn

Joined: Jul 21, 2012
Posts: 5
You might try the file manipulation tools at Aspose.

what it is can you explain in detail
Rameshwar Soni
Ranch Hand

Joined: Feb 03, 2011
Posts: 247
@saif --------please do not post your same question on multiple forums. If your are doing so please include a link in your question stating "i had posted on this forum and so.........."
here
Joe Ridener
Ranch Hand

Joined: Jul 16, 2012
Posts: 86
Ok when you copied and pasted your code onto this forum did you include all the syntax that is on the file?? The reason that I ask is if you used an editor, the editor will often add the snippet 'package MyFirstPackage;' at the top of the file. In this case the command line would output the error Main class not found.

Second question is did you compile your own MyFirst.class file from the command line using the javac command??? Because if you did then it is a syntax error contained within the MyFirst.java file (becuase that means that your variables and everything else is set correctly) and I cannot find any syntax errors in your code.
saif kazi
Greenhorn

Joined: Jul 21, 2012
Posts: 5
Rameshwar Soni wrote:@saif --------please do not post your same question on multiple forums. If your are doing so please include a link in your question stating "i had posted on this forum and so.........."
here


ok i will take care next time
saif kazi
Greenhorn

Joined: Jul 21, 2012
Posts: 5
Joe Ridener wrote:Ok when you copied and pasted your code onto this forum did you include all the syntax that is on the file?? The reason that I ask is if you used an editor, the editor will often add the snippet 'package MyFirstPackage;' at the top of the file. In this case the command line would output the error Main class not found.

Second question is did you compile your own MyFirst.class file from the command line using the javac command??? Because if you did then it is a syntax error contained within the MyFirst.java file (becuase that means that your variables and everything else is set correctly) and I cannot find any syntax errors in your code.


i didnt get you properly about syntax and about second question My MyFirst.class i compile it using the javac command
Rameshwar Soni
Ranch Hand

Joined: Feb 03, 2011
Posts: 247
saif kazi wrote:

here is my java script



This is Java and not JavaScript. Try this Difference between Java and Java script
Joe Ridener
Ranch Hand

Joined: Jul 16, 2012
Posts: 86
I think you might not have installed your JRE ( Java Runtime Environment). Do you have your JRE installed ??? If not click here webpage

Other wise make sure that the class name

public class MyFirst//<----class name
{

public static void main(String[] args)
{
System.out.println("Hello World!!!");
}


}

matches the file name ( so that it appears like so... MyFirst.java while sitting the directory). The class name must match the file name. The file will of course have the .java on the end of it.
BalaMurali dhar
Ranch Hand

Joined: Apr 14, 2012
Posts: 60
you have not set the classpath properly
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
BalaMurali dhar wrote:you have not set the classpath properly
It is usually not a good idea to set the classpath. If there is a classpath already set, that can cause the file to be missed. There is an easy way to test thatthe -cp . bit changes the classpath back to . for current folder. If that sorts it out, tell us, and also tell us what you get when you inspect your classpath.
Rameshwar Soni
Ranch Hand

Joined: Feb 03, 2011
Posts: 247
@Campbell------The OP has already got his problem solved. It is here
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
Thank you for noticing: OP please note it is discourteous to people on both forums not to take notice of this.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Help with my first project hello world
 
Similar Threads
Java problem: Could not find or load class
stack overflow error
please help me to resolve this
Problem with sourceforge project
Class Path error Help