• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Command Prompt error- Can't run through compiler

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys, I literally just picked up the book last night to start learning Java. I am using Head First Java 2nd Edition. Part of the first chapter has me writing some simple coding.

However, I am having trouble getting the compiler to work. First off, it wont recognize any commands when I use javac. It only recognizes commands that begin with java, like "java -version"

But when I attempt to run this through the compiler using this command.

>java MyFirstApp.java

I get this error from command prompt (see attached)

java-help.png
[Thumbnail for java-help.png]
Command Prompt error
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like a classpath issue, make sure your classpaths are set correctly, if you did them manually it is pretty easy to miss a typo the first type you do it.
 
Zach Williams
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can it still be a classpath issue if I am able to issue the command "java -version" and it is able to display the correct version? I copied the path directly from the location of the /bin file so i dont think I have any typo's
 
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
1. No, it's not a CLASSPATH issue at all. It's a PATH issue.
2. You don't run a java source code file with java.exe. It has to be compiled with javac.exe.

Recommended reading:
http://download.oracle.com/javase/tutorial/getStarted/problems/index.html
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Zach Williams wrote:
But when I attempt to run this through the compiler using this command.

>java MyFirstApp.java

I get this error from command prompt



The JVM (java command) takes the name of the class to run. In this case, you are trying to run the "java" class, in the "MyFirstApp" package. Perhaps you meant...

> java MyFirstApp

Or if you are trying to compile, then you probably mean...

> javac MyFirstApp.java

Henry
 
Zach Williams
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my path is defined as

C:\Program Files (x86)\Java\jre6\bin

the location of my bin is

C:\Program Files (x86)\Java\jre6\bin

Javac is still coming up as not recognized as internal or external command...
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Zach Williams wrote:my path is defined as

C:\Program Files (x86)\Java\jre6\bin

the location of my bin is

C:\Program Files (x86)\Java\jre6\bin

Javac is still coming up as not recognized as internal or external command...



javac is not recognized because you never install the compiler. The JRE is only the runtime environment -- it doesn't include the compiler. See if you have a JDK installed, and if not, install one.

Henry
 
Zach Williams
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
great, thanks for your help!
 
when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic