• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Help with running my first program.

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 2662
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens if you call "javac" in stead of "% javac" ?
 
Saumya Purkayastha
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?)
 
Ranch Hand
Posts: 41
Netscape Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Marshal
Posts: 80775
489
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
screenshot.jpg
[Thumbnail for screenshot.jpg]
Screenshot of error message and procedure followed.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should spell "System.out.println" correctly: upper vs. lower case matters in Java.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't attach screenshots for showing us text, just copy and paste the text.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
screenshot2.jpg
[Thumbnail for screenshot2.jpg]
New Error Message.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Watch that you don't substitute a capital "i" for a lower case "L"

it's println not printIn
 
Saumya Purkayastha
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And I'll repeat: do NOT post images to show textual information; copy and paste the text.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those are upper-case "I". We keep telling you that's wrong.
 
Saumya Purkayastha
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
extremely sorry. I got it.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Isn't this the same problem you had the first time? Your path is not correct.
 
Saumya Purkayastha
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
screenshot3.jpg
[Thumbnail for screenshot3.jpg]
Small screenshot of Command Prompt.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could try *running* it now.
 
Saumya Purkayastha
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I run it?
 
Saumya Purkayastha
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Congratulations!
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Saumya Purkayastha
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic