*
The moose likes Beginning Java and the fly likes Java Beginner Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Beginner" Watch "Java Beginner" New topic
Author

Java Beginner

Sumit Rai
Greenhorn

Joined: Jan 24, 2011
Posts: 5

Hi, i am Sumit and am really very new to java n related programming language but not completely... I ve studied C and C++ n now m very eager to understand the logic and thrill of java.... I downloaded and installed Jdk1.6 as suggested in the sites i followed(site dont remember).. I have the following difficulties while compiling the traditional "HelloWorld" program...

1. javac is not recognised as an internal or external command... [ I solved this problem ]

- My DOS command goes like this :
C:\Program Files\Java\jdk1.6.0_23\bin>javac HelloWorld.java

2. but now it shows some error in creating .class extension.... It says this :

HelloWorld.java:1: error while writing HelloWorld: HelloWorld.class (access is denied)
public class HelloWorld {
^
1 error

3. And what does the symbol "^" means below the letter "c" of class ?

If someone could really help me I would really appreciate it and will always be thanked to him...
Please....... I know this isn't a very big problem.....I ve many big problems to face than this...
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

Sumit Rai wrote:1. javac is not recognised as an internal or external command... [ I solved this problem ]

You can also add the JDK's bin folder to your PATH variable. You can use our search if you don't know how to. It's a question that has shown up multiple times already.

My DOS command goes like this :
C:\Program Files\Java\jdk1.6.0_23\bin>javac HelloWorld.java

I highly discourage putting your source files in your JDK's folder or any of its sub folders. Create a dedicated folder for all your development work, with sub folders for each project. For instance, C:\Projects will hold all projects. Inside you have folder HelloWorld which is where the HelloWorld.java file should go. If you've set the PATH correctly, you can just type "javac HelloWorld.java" from this folder.

2. but now it shows some error in creating .class extension.... It says this :

HelloWorld.java:1: error while writing HelloWorld: HelloWorld.class (access is denied)

You're probably using Windows Vista or Windows 7. User Access Control is blocking the writing of files to most of the Program Files folder and its sub folders without confirmation. Unfortunately, javac doesn't ask for confirmation but fails instead.

By putting your files in the dedicated folder and making sure you have write-rights on it, you should get rid of this error.

public class HelloWorld {
^
1 error

3. And what does the symbol "^" means below the letter "c" of class ?

It's an indicator that shows where in your line the error occurs. Usually, like when you have a syntax error, it's very helpful, but in this case it's not.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Navneet Singh
Greenhorn

Joined: Aug 19, 2007
Posts: 29

It would be better if you could post your program. You can create environment variable in your system property which will evade the problem of always going to the path of java bin directory.


SCJP 1.4
SCWCD
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40034
    
  28
Welcome to the Ranch

Don't edit your post; if somebody has answered it, the altered post makes the reply look like nonsense. The word are am not n, and not n.
Sumit Rai
Greenhorn

Joined: Jan 24, 2011
Posts: 5
Navneet Singh wrote:It would be better if you could post your program. You can create environment variable in your system property which will evade the problem of always going to the path of java bin directory.


My Program is :
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello, World");
}

}

- ENVIRONMENT VARIABLES !!! Oh !!! how can i do that "creating environment variables in my system property........ ". I went in there but donno wat to do???
Navneet Singh
Greenhorn

Joined: Aug 19, 2007
Posts: 29

setting up environment variable (on windows)
go to start-My Computer (right click) - go to properties - go to 'Advanced' tab - click on 'Environment Variables' - you will find two sections (one is 'user variables for My Computer' and the other is 'System Variables') - in 'System Variables' section click on 'New' - type 'variable name' as 'JAVA_HOME' and 'variable value' as 'path till java_bin directory' - click on 'OK' - then inside 'system variables' section double click on 'path' as variable(it should be there) - then edit that section and go to the end of it and then type : ';%JAVA_HOME%'

Now you java is set in environment variable. Now exit all your command prompt. Open fresh/new command prompt and write 'javac -version'- it will give you the version. It means it is properly installed in your environment variable.

Your code looks right, try this option and check.
Sumit Rai
Greenhorn

Joined: Jan 24, 2011
Posts: 5
Navneet Singh wrote:setting up environment variable (on windows)
go to start-My Computer (right click) - go to properties - go to 'Advanced' tab - click on 'Environment Variables' - you will find two sections (one is 'user variables for My Computer' and the other is 'System Variables') - in 'System Variables' section click on 'New' - type 'variable name' as 'JAVA_HOME' and 'variable value' as 'path till java_bin directory' - click on 'OK' - then inside 'system variables' section double click on 'path' as variable(it should be there) - then edit that section and go to the end of it and then type : ';%JAVA_HOME%'

Now you java is set in environment variable. Now exit all your command prompt. Open fresh/new command prompt and write 'javac -version'- it will give you the version. It means it is properly installed in your environment variable.

Your code looks right, try this option and check.


1. I did all that what you told.... but my bin is in C:\Program files\Java\jdk\bin

2. And when I am trying for C:\javac -version
it say " javac is not recognised as an internal or external command".

3. By default when I open my Dos prompt , the path is like this : C:\Users\Sumit>


But when I tried java -version in the path as mentioned in 1., it works properly..
So my doubt is that wether you asked me to go through the path 1. or just direct path 2.
Sumit Rai
Greenhorn

Joined: Jan 24, 2011
Posts: 5
Rob Spoor wrote:
Sumit Rai wrote:1. javac is not recognised as an internal or external command... [ I solved this problem ]

You can also add the JDK's bin folder to your PATH variable. You can use our search if you don't know how to. It's a question that has shown up multiple times already.

My DOS command goes like this :
C:\Program Files\Java\jdk1.6.0_23\bin>javac HelloWorld.java

I highly discourage putting your source files in your JDK's folder or any of its sub folders. Create a dedicated folder for all your development work, with sub folders for each project. For instance, C:\Projects will hold all projects. Inside you have folder HelloWorld which is where the HelloWorld.java file should go. If you've set the PATH correctly, you can just type "javac HelloWorld.java" from this folder.

2. but now it shows some error in creating .class extension.... It says this :

HelloWorld.java:1: error while writing HelloWorld: HelloWorld.class (access is denied)

You're probably using Windows Vista or Windows 7. User Access Control is blocking the writing of files to most of the Program Files folder and its sub folders without confirmation. Unfortunately, javac doesn't ask for confirmation but fails instead.

By putting your files in the dedicated folder and making sure you have write-rights on it, you should get rid of this error.

public class HelloWorld {
^
1 error

3. And what does the symbol "^" means below the letter "c" of class ?

It's an indicator that shows where in your line the error occurs. Usually, like when you have a syntax error, it's very helpful, but in this case it's not.


But i still have the same error....
sir, was i supposed to create a dedicated forlder inside bin itself and compile or just directly in C:\ directory n compile....

1. If I directly give path as C:\Jprojects // which is the folder I have created..
It says same " javac not recognised...".

2. but even when i created a folder inside bin and again tried to compile, the path being
C:\Program files\java\jdk\bin\Jprojects\HelloWorld>javac HelloWorld.java
i still get the same error....











Navneet Singh
Greenhorn

Joined: Aug 19, 2007
Posts: 29

why you are typing 'c:/javac -version' write only javac -version in your command prompt.
or lastly you could try following approach:

set classpath=.;c:/ur_path_for_java_till_bin
and then type 'javac -version' likewise you can do it...
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

Sumit Rai wrote: 1. If I directly give path as C:\Jprojects // which is the folder I have created..
It says same " javac not recognised...".

Because your PATH is still not setup correctly.

2. but even when i created a folder inside bin and again tried to compile, the path being
C:\Program files\java\jdk\bin\Jprojects\HelloWorld>javac HelloWorld.java
i still get the same error....

That's because you're still using a folder inside the JDK folder. I clearly said
Rob Spoor wrote:I highly discourage putting your source files in your JDK's folder or any of its sub folders. Create a dedicated folder for all your development work, with sub folders for each project. For instance, C:\Projects will hold all projects.
Sumit Rai
Greenhorn

Joined: Jan 24, 2011
Posts: 5
Rob Spoor wrote:
Sumit Rai wrote: 1. If I directly give path as C:\Jprojects // which is the folder I have created..
It says same " javac not recognised...".

Because your PATH is still not setup correctly.

2. but even when i created a folder inside bin and again tried to compile, the path being
C:\Program files\java\jdk\bin\Jprojects\HelloWorld>javac HelloWorld.java
i still get the same error....

That's because you're still using a folder inside the JDK folder. I clearly said
Rob Spoor wrote:I highly discourage putting your source files in your JDK's folder or any of its sub folders. Create a dedicated folder for all your development work, with sub folders for each project. For instance, C:\Projects will hold all projects.


Sir, i created the folder directly in my C drive. And sub folders to keep my program.java as you directed. But my jdk bin is in c->program files\java\jdk\bin .
The sub folder "Jprojects" I have created is in C drive where Program files is present....
I am unable to access .java files because "javac is not recognised" in Jprojects... but if i give the path till bin and compile .java file using javac, it doesnt show javac error but other one I have told you about....
Does that mean there is something wrong with the installation.... I re-download everything and installed but still unable to compile....
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

C:\Program files\java\jdk\bin\Jprojects\HelloWorld>javac HelloWorld.java

That's your Java path. So that's still inside the Program Files directory. Windows is really annoying with files and folders in that folder. Have you already used C:\Projects like I suggested? If that works you can always rename it / move it to a location where Windows is not being a pain in the behind about.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40034
    
  28
Agree with Rob about not putting your work into Program Files. I suggest you write the following when you open your command line
mkdir javaWork
cd javaWork
. . . and every time you want that folder you can write
cd javaWork
As for setting your PATH, there are several ways to do it, one of which is in our FAQ.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Beginner