This week's book giveaway is in the Web Services forum.
We're giving away four copies of Microservices in Action and have Morgan Bruce & Paulo A. Pereira on-line!
See this thread for details.
Win a copy of Microservices in Action this week in the Web Services forum!

Saumya Purkayastha

+ Follow
since Mar 27, 2010
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Saumya Purkayastha

Hey Campbell,

I have not saved my files in the installation directory. I have saved them in a directory called java which I created in the desktop.

Please check the path above. The installation directory is in program files which is required to call the javac compiler.
8 years ago
I have compiled and successfully ran 5 programs as of now. The common thing in all the programs were that the entire program was inside a single class. But now as I have moved to the further chapters I am finding programs with more than 1 class. What do I do in this case? Should I write all the programs in a single .java file or should I save them as different .java files? How do I actually compile these in Command Prompt?

Can anyone explain this to me?
8 years ago
Hi Mr. Kumar,

Yesterday I was in your situation and I know how much it hurts. Check the notes below which I made for you. If you are able to compile your program, it means you have set your environment variables right. Now its pretty easy to run your program. However I am sending you the complete procedure for compiling and running your program. If you read the entire thread you would have got everything. Anyways I will make it easy for you.


JDK for compilation - C:\Program Files\Java\jdk1.6.0_18\bin
Path of file - C:\Users\Sony\Desktop\java
filename -

To compile the application.
First command in Command prompt:-
cd C:\Program Files\Java\jdk1.6.0_18\bin

Next command in command prompt(to compile) being in this directory:-
javac C:\Users\Sony\Desktop\java\

A .class file gets generated.

To run the file:-
Next command in command prompt:-
cd C:\Users\Sony\Desktop\java

Next command in command prompt(to run) being in this directory:-
java infinite

The above command is java followed by the name of the .class file which is generated.

If your class is a public class the class name and .java file name need to be the same.

If you do not specify public this requirement is ruled out.

Lemme know if you are still facing any problem.
8 years ago
If you know the answer please let me know rather than asking me to test. This is a request because it will be helpful for the community other than me. I have tested as per your recommendations and found the following results:-

I created a simple program and tried to use different access specifiers for the class definition. Below are the results:-

Public - In this case the class name has to be same as the filename.
Not specified anything - The filename and class name need not match.
Protected - It does not allow me to use this.
Private - It does not allow me to use this.

This is my 4th program and so I dont know the reason to why this is happening. I am sure I will find this either in this forum soon or in my future days of studying java.

I have great expectations from this forum. Gimme a satisfactory answer.
8 years ago
Is this restriction only for Public class?

If so why is this restriction not there for non-public classes in Java specification?

Sorry if I am too inquisitive. Beginners often want to know "why?"
8 years ago
I was trying to run a program - which was not working, when I changed the filename to is same as the public class name), it started working.

I got the below error:-

1 error

C:\Program Files\Java\jdk1.6.0_18\bin>javac C:\Users\Sony\Desktop\java\
C:\Users\Sony\Desktop\java\ class PhraseOMatic is public, should be declared in a file named
public class PhraseOMatic {

Why is it that in a public class we have to name the .java file exactly as the class name.

I was able to compile this program after I changed the file name from to

I have noticed that if we do not specify the class as public, the file name can be totally different from the class name.
8 years ago
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.

8 years ago
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.
8 years ago
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.
8 years ago
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.
8 years ago
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.
8 years ago
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.
8 years ago
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.
8 years ago
extremely sorry. I got it.
8 years ago