• Post Reply Bookmark Topic Watch Topic
  • New Topic

Head First Java: javac is not recognized

 
Nadya Jawahir
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I've been trying to meet the requirements to continue with the book Head First Java (set path, install API etc) but I've been having some trouble.


When I open up a commandprompt I type in: 'java -version' it gives me the following code:

java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)



But when I open up commandprompt and I type in: 'javac -version' it gives me:

'javac' is not recognized as an internal or external command,
operable program or batch file.


I've followed everything in the following tutorial: https://coderanch.com/wiki/659740/create-Java-program I've tried reinstalling the JDK numerous times, turned my pc on and off numerous times as well but I still get the javac error.
The only difference is that I have a windows 10 system instead of windows 7, but I don't think that really matters, does it?

I hope someone can help me cause this is really hindering me from learning Java.

Thank you a lot in advance. :]
 
Henry Wong
author
Marshal
Posts: 22365
102
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
N Er-rabt wrote:
I've followed everything in the following tutorial: https://coderanch.com/wiki/659740/create-Java-program I've tried reinstalling the JDK numerous times, turned my pc on and off numerous times as well but I still get the javac error.


In the tutorial that you mentioned, there is a section regarding the PATH variable. If you did this part correctly, then should be able to access the javac command -- which is part of the JDK.

Additionally, when you ran the "java -version" command, it mentioned that it was part of the JRE. So, you are also not using the java command that is part of the JDK either. If you fix the PATH variable, this should be fixed too.

Henry
 
Nadya Jawahir
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
N Er-rabt wrote:
I've followed everything in the following tutorial: https://coderanch.com/wiki/659740/create-Java-program I've tried reinstalling the JDK numerous times, turned my pc on and off numerous times as well but I still get the javac error.


In the tutorial that you mentioned, there is a section regarding the PATH variable. If you did this part correctly, then should be able to access the javac command -- which is part of the JDK.

Additionally, when you ran the "java -version" command, it mentioned that it was part of the JRE. So, you are also not using the java command that is part of the JDK either. If you fix the PATH variable, this should be fixed too.

Henry



Thanks a lot for the fast reply!

I've reread the tutorial, went back to check the PATH variable on my pc and it seems as though like everything is set up correctly.. At least, that's what I think. I've made a screenshot. I hope you can look at it and see if there's anything that isn't set up correctly.

Screenshot:

Thank you in advance.
 
Nadya Jawahir
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
N Er-rabt wrote:
I've followed everything in the following tutorial: https://coderanch.com/wiki/659740/create-Java-program I've tried reinstalling the JDK numerous times, turned my pc on and off numerous times as well but I still get the javac error.


In the tutorial that you mentioned, there is a section regarding the PATH variable. If you did this part correctly, then should be able to access the javac command -- which is part of the JDK.

Additionally, when you ran the "java -version" command, it mentioned that it was part of the JRE. So, you are also not using the java command that is part of the JDK either. If you fix the PATH variable, this should be fixed too.

Henry


I set the PATH and JAVA HOME variable to C:\Program Files\Java\jdk1.8.0_112\bin and now it gives me:

java -version:
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)

javac -version:
javac 1.8.0_112

I think I've managed to fix it, right?


 
Nadya Jawahir
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
God..

I thought I fixed it so I went and tried to compile my ''Party.java'' file which you're supposed to do in the Head First Java book..

I gave the command prompt the following:

%javac Party.java

And the prompt gave me:

'%javac' is not recognized as an internal or external command,
operable program or batch file.

This is really strange cause when I give it:

javac -version

It does in fact give me:
javac 1.8.0_112

Okay now its even more complicated than before.. I'm lost.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65419
100
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't type in the %
 
Henry Wong
author
Marshal
Posts: 22365
102
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Don't type in the %


For Windows users, this seems to be a common stumbling block...

For users of Unix (and its variants), the % is the default/common command prompt for non-superusers. So, basically, Unix users know not to type %.

Henry 
 
Junilu Lacar
Sheriff
Posts: 9355
96
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nadya Jawahir wrote:
I gave the command prompt the following:
%javac Party.java

And the prompt gave me:
'%javac' is not recognized as an internal or external command
...
Okay now its even more complicated than before.. I'm lost.

On Linux/Unix systems, the command line prompt is often a "$" or "%", so when you see an instruction to type in something at the command line and it looks something like this:
Type in the following at the command prompt:

% javac MyProgram.java

The "%" is the Linux/Unix command line prompt and you shouldn't typed it in as part of the command, which Bear already told you. Since it appears you're working in Windows, the next time you see a command that starts with "$" or "%", just mentally translate it to "C:\>" so you won't get confused.
 
Luwdmke Whiskey
Greenhorn
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After you get rid of that % sign

create a new folder  name it what ever you like.

Then open your C:\ drive and cut or copy the new folder and paste it in there.

Open your command prompt type cd c:\ new folder name press enter which

should bring you to C:\New folder name> now after the prompt type javac (space) Party.java

and you should be able to compile your project.
 
Nadya Jawahir
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Don't type in the %


Henry Wong wrote:
Bear Bibeault wrote:Don't type in the %


For Windows users, this seems to be a common stumbling block...

For users of Unix (and its variants), the % is the default/common command prompt for non-superusers. So, basically, Unix users know not to type %.

Henry 


Junilu Lacar wrote:
Nadya Jawahir wrote:
I gave the command prompt the following:
%javac Party.java

And the prompt gave me:
'%javac' is not recognized as an internal or external command
...
Okay now its even more complicated than before.. I'm lost.

On Linux/Unix systems, the command line prompt is often a "$" or "%", so when you see an instruction to type in something at the command line and it looks something like this:
Type in the following at the command prompt:

% javac MyProgram.java

The "%" is the Linux/Unix command line prompt and you shouldn't typed it in as part of the command, which Bear already told you. Since it appears you're working in Windows, the next time you see a command that starts with "$" or "%", just mentally translate it to "C:\>" so you won't get confused.


Luwdmke Whiskey wrote:After you get rid of that % sign

create a new folder  name it what ever you like.

Then open your C:\ drive and cut or copy the new folder and paste it in there.

Open your command prompt type cd c:\ new folder name press enter which

should bring you to C:\New folder name> now after the prompt type javac (space) Party.java

and you should be able to compile your project.



Thank you a lot guys!

That managed to get me past the Javac error now I get:

javac: file not found: Party.java
Usage: javac <options> <source files>
use -help for a list of possible options

Which I'll try to figure out myself through the forums. I hope I can do it!
 
Nadya Jawahir
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fixed it all. You guys are a bunch of angels.

thanks!
 
Shibu Kurian
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nadya Jawahir wrote:I fixed it all. You guys are a bunch of angels.

thanks!


Few inputs that might help people on the configuration....

I kind of had the problem during my java learning days and did few R&D on the same and learned a lot...let me share them here...

Questions that i got answered after my R&D...

1. Why is java command being recognized but not javac, both being in the same folder?
2. What is the peculiarity of path variable and its significance in configuring Java?

I'll post my findings on this soon....
 
Campbell Ritchie
Sheriff
Posts: 52055
90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Party application is incomplete and cannot be executed without extra code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!