wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Help with running my first program. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with running my first program." Watch "Help with running my first program." New topic
Author

Help with running my first program.

Saumya Purkayastha
Greenhorn

Joined: Mar 27, 2010
Posts: 23
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
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

What happens if you call "javac" in stead of "% javac" ?


OCUP UML fundamental and ITIL foundation
youtube channel
Saumya Purkayastha
Greenhorn

Joined: Mar 27, 2010
Posts: 23
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!

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Does your path include the location of your javac program?

(Why would you try typing in a "%"? What OS are you using? Do you know how to use that OS?)
Manish Sahni
Ranch Hand

Joined: Sep 09, 2009
Posts: 41

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: 37953
    
  22
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
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...

Regs,
Saumya...
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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
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.



[Thumbnail for screenshot.jpg]

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You should spell "System.out.println" correctly: upper vs. lower case matters in Java.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please don't attach screenshots for showing us text, just copy and paste the text.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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
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.



[Thumbnail for screenshot2.jpg]

pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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
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.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Make sure you don't substitute a capital i ("I") for a lower-case L ("l"). It's println, not printIn.

The Javadocs are your friend--you can check this kind of thing yourself.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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
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
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");
}
}
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Those are upper-case "I". We keep telling you that's wrong.
Saumya Purkayastha
Greenhorn

Joined: Mar 27, 2010
Posts: 23
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.
Saumya Purkayastha
Greenhorn

Joined: Mar 27, 2010
Posts: 23
extremely sorry. I got it.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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
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.

I dont know wats the problem.

Help me out!!!

I can send you the attachments if you want.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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
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.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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
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.



[Thumbnail for screenshot3.jpg]

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

So you've compiled it--what's the problem?

And come on--learn how to use your operating system: cutting and pasting is easy. Explore a little. Figure it out. Stop posting images of text.
Saumya Purkayastha
Greenhorn

Joined: Mar 27, 2010
Posts: 23
Hey David,

Thanks for the reply. I think my program is already compiled because the .class file is automatically created. But where do I see the output?

And although it is not related to java it would be great if you could help me with copying and pasting from Command Prompt. I was not able to do it.

I want to see the output. Please help me out with this.

If I see the output I will open a bottle of beer and celebrate.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You could try *running* it now.
Saumya Purkayastha
Greenhorn

Joined: Mar 27, 2010
Posts: 23
How do I run it?
Saumya Purkayastha
Greenhorn

Joined: Mar 27, 2010
Posts: 23
Thanks to to all the ppl for replying.

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?

Help me out or I wont stop banging my head.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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
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.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Congratulations!
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

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.

No need to bug David.

How to copy from Windows Command Prompt


luck, db
There are no new questions, but there may be new answers.
Saumya Purkayastha
Greenhorn

Joined: Mar 27, 2010
Posts: 23
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
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.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Saumya Purkayastha wrote:Just completed half of it. Will complete it in 2 more days.

Take your time: rushing through it will not allow the brain time needed to actually *learn* Java.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Help with running my first program.
 
Similar Threads
newbie question
Running Java Programs from the command prompt
Classpath Problems
classpath in java
Just Learning Java