Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with my first project hello world

 
saif kazi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello
when i was compiling my first program it end me with this error



here is my java script

 
Joe Ridener
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might try the file manipulation tools at Aspose.

what it is can you explain in detail
 
Rameshwar Soni
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you have not set the classpath properly
 
Campbell Ritchie
Sheriff
Posts: 48394
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Campbell------The OP has already got his problem solved. It is here
 
Campbell Ritchie
Sheriff
Posts: 48394
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for noticing: OP please note it is discourteous to people on both forums not to take notice of this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic