I am extremely new to Java. I tried to run the first java program but was unable to do so. I am using a windows Vista Os and when I run the % javac followed by the path of my first java application called MyFirstApp.java it shows an error saying:- Cannot find %. I have installed the Java JDK 1.6 and the path is as follows:- C:\Program Files\Java\jdk1.6.0_18\bin. Please let me know how to solve this problem which I have encountered and how to run my first java program without using ECLIPSE or NetBeans.
Thanks and Regards, Saumya Purkayastha - Sam
Specialist - Internet Marketing
What happens if you call "javac" in stead of "% javac" ?
OCUP UML fundamental
ITIL foundation
Saumya Purkayastha
Greenhorn
Joined: Mar 27, 2010
Posts: 23
posted
0
I have tried all the three below:-
javac
% javac
%javac
None of them work,
Following is the exception in the respective cases in run:-
Windows cannot find the file "javac". Make sure that you typed the name correctly and then try again.
Windows cannot find the file "%". Make sure that you typed the name correctly and then try again.
Windows cannot find the file "%javac". Make sure that you typed the name correctly and then try again.
The following are the excetions when I try this in command prompt:-
'javac' is not recognized as an internal or external command, operable program or batch file.
'%' is not recognized as an internal or external command, operable program or batch file.
'%javac' is not recognized as an internal or external command, operable program or batch file.
This is despite me setting the environment variable path to the bin in the jdk installed folder.
I also tried to set the path in command prompt but with no success.
I will be happy if you can save me from this so that I can start off with my first Hello world program!
Dear Soumya,
These are the basics step to run your java program. You need to ensure that you should take these points into consideration
1. Your file name and the class name should be same if you are a beginner.
2. Go to command prompt and type cd\
3. then write cd<space>the path of your file where it is saved
4. then write set path=jdk/bin path
5. write javac filename.java
6. write java filename
let me know for any other queries...
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
4
posted
0
If you are getting the "not recognised" error, you will find more details and a link to the solution here.
And welcome to JavaRanch
Saumya Purkayastha
Greenhorn
Joined: Mar 27, 2010
Posts: 23
posted
0
Dear Manish,
I have followed all the steps that you have mentioned and I have also changed the path in the system environment variables to the bin folder in the installed jdk. But still I am not able to do it. And also the class name and file name are the same.
Hi Anyone,
Please help me with this..Does anyone have a comprehensive list of reasons why a person may not be able to run his first Hello World program using a text editor and command prompt with jdk installed. I think many of you might have faced this problems. Please share your experiences...
Please TellTheDetails. What's your current path? What's your classpath? How *exactly* are you trying to run it? From what directory are you running it?
Saumya Purkayastha
Greenhorn
Joined: Mar 27, 2010
Posts: 23
posted
0
Hey Guys,
Thanks I have solved it.
We are suppose to go the bin directory inside jdk in command prompt and then run javac followed by the complete path of the .java file. I was going to the bin directory whereas I was specifying it in the command line.
Thanks to every1 who answered. Each of your answers were very helpful to learn something new.
But Now The Problem is still not solved!
If you remember my intention is to run my first program successfully. But I am not able to run it. The following is the code written in the file MyFirstApp.java
public class MyFirstApp{
public static void main (String[] args) {
system.out.printIn("I Rule!");
system.out.printIn("The World");
}
}
The following error is thrown by the command prompt:-
2 errors in the lines 3 and 4 with the same error message - package system does not exist.
which package should I include for the sop to work properly.
I am also attaching a screenshot of my work for your reference.
Please help me to successfully run my first java application.
Please don't attach screenshots for showing us text, just copy and paste the text.
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
posted
0
Saumya Purkayastha wrote:
public class MyFirstApp{
public static void main (String[] args) {
system.out.printIn("I Rule!");
system.out.printIn("The World");
}
}
which package should I include for the sop to work properly.
No package. It's "System", not "system".
edit: late as usual.
Saumya Purkayastha
Greenhorn
Joined: Mar 27, 2010
Posts: 23
posted
0
Hey David/ Pete,
Thanks for the update, I did the same as you told, but still the code does not get compiled. This time a different error message is being thrown.
Sorry David I am inserting the small screenshot as I cannot copy from Command Prompt and am not feeling like typing the error message here.
Please help me out with this.
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
posted
0
Watch that you don't substitute a capital "i" for a lower case "L"
it's println not printIn
Saumya Purkayastha
Greenhorn
Joined: Mar 27, 2010
Posts: 23
posted
0
Hey Pete,
I did not do that. I checked it once again after you told me but it throws the same error message.
There are two error messages(both same) in the lines 3 and 4:-
cannot find symbol
symbol : method printIn(java.land.String)
location: class java.io.PrintStream
Also note there is a small arrow at the bottom of the dot between out and printIn in both statements.
Is there anyone who can help me out with the above specific error?
I am going mad now as I could not compile my first program and I am trying this since almost 5 hours now.
And I'll repeat: do NOT post images to show textual information; copy and paste the text.
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
posted
0
Saumya Purkayastha wrote:I did not do that. I checked it once again after you told me but it throws the same error message.
I'll believe it when I see the code. Please post your latest bit of code here (with code tags).
Also note there is a small arrow at the bottom of the dot between out and printIn in both statements.
I'm mainly noticing that even in here you have it written as "printIn", not "println". Note that it stands for print-line, hence the need for the L not the i.
Is there anyone who can help me out with the above specific error?
I'm trying, I'm trying.
I am going mad now as I could not compile my first program and I am trying this since almost 5 hours now.
Easy partner, else you get so frustrated you can't think straight. Much luck!
Saumya Purkayastha
Greenhorn
Joined: Mar 27, 2010
Posts: 23
posted
0
Below is the latest code:-
This is lower case L - l
This is upper case i - I
The difference is clearly visible above and in the below code PrintIn contains upper case I(i) not lower case L(l). I think this is not the reason and the below code is directly copied from the notepad.
public class MyFirstApp{
public static void main (String[] args) {
System.out.printIn("I Rule!");
System.out.printIn("The World");
}
}
Those are upper-case "I". We keep telling you that's wrong.
Saumya Purkayastha
Greenhorn
Joined: Mar 27, 2010
Posts: 23
posted
0
David Newton wrote:And I'll repeat: do NOT post images to show textual information; copy and paste the text.
Dear David,
Could you tell me a way how you can copy and paste from the Command Prompt? If there is a way I would surely do so. Anyways thanks for the advise, will try to follow it whenever possible. I know that server space costs Java Ranch and these guys are really doing a good job.
Upper-left of window title bar dropdown. Or set "quick edit" mode so all command prompts allow copying by default w/o having to do it manually each time.
Saumya Purkayastha
Greenhorn
Joined: Mar 27, 2010
Posts: 23
posted
0
Thanks a lot David and Pete.
I was doing silly mistakes which I could not even find in books. Thanks for correcting me.
But now when I run the program it does not give any output!
public class MyFirstApp{
public static void main (String[] args) {
System.out.println("I Rule!");
System.out.println("The World");
}
}
When can I see that I Rule! The World appearing in my command prompt?
In between an error message was being shown:-
javac: file not found
But I have given the exact path to the file and previously it was taking but now the compiler is not at all responding.
Isn't this the same problem you had the first time? Your path is not correct.
Saumya Purkayastha
Greenhorn
Joined: Mar 27, 2010
Posts: 23
posted
0
No this is not the same problem. Last time the Command Prompt was not able to identify the command javac because I was not in the bin directory. This time it is not showing any error message but going to the next line in the same directory. There is no response from the compiler through the command prompt. Please suggest me a solution to this.
I have no idea what you're saying. It would make more sense to cut and paste the actual output you're getting, otherwise we're just guessing.
Saumya Purkayastha
Greenhorn
Joined: Mar 27, 2010
Posts: 23
posted
0
Hey David,
I tried to explain but as I guess I am not clear enough. I will therefore again attach a small part of a screenshot of the command prompt about how it is acting. Once you have a look at it you will know. And dont worry I will delete all attachments once i am able to run my program.
I was not able to compile my simple application, the code of which you will find above.
But now I am able to compile it from command prompt. I came to know this as a .class file is automatically generated.
But the issue is still not solved. I want to see the output. Where do I see the output? When I click on the .java file it asks which application to use to open it?
Do you have access to the web? Can you search for a Java tutorial? How is it that you know how to compile a Java program but not run one?
Saumya Purkayastha
Greenhorn
Joined: Mar 27, 2010
Posts: 23
posted
0
Yippy I did it. Thanks to David, Pete and all above who have given me their helping hands. I am able to see the output. Here goes my beer. I will have a great weekend now!!
But I did not still get how to copy from Command Prompt. Anyways thats a different topic all together. I will bug up David later about this.
Thanks and Regards,
Have A Nice Time.
Saumya Purkayastha wrote:But I did not still get how to copy from Command Prompt. Anyways thats a different topic all together. I will bug up David later about this.
luck, db
There are no new questions, but there may be new answers.
Saumya Purkayastha
Greenhorn
Joined: Mar 27, 2010
Posts: 23
posted
0
Thanks Darryl,
I was just kidding! I got all the answers and was able to run my 1st program and 2nd program successfully. I was thinking of getting out of Java yesterday, but I started loving Java now. Thanks to Java Ranchers, Java Ranch and Head First Java which is an awesome book. Just completed half of it. Will complete it in 2 more days. So expect a lot of questions from me in the coming week.
Cheers!
A K Kumar
Greenhorn
Joined: Mar 28, 2010
Posts: 1
posted
0
i also have the same problem. i am able to compile my program but could not see it's output. could you please tell me how to see the output of a java program.