"JAVAC is Not Recognized as an Internal or External Command"

New thread by request...

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 6386 Views - Last Post: 22 January 2010 - 03:16 PM Rate Topic: -----

#1 skailey   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 12-February 08

"JAVAC is Not Recognized as an Internal or External Command"

Post icon  Posted 22 January 2010 - 06:31 AM

I posted in an older thread and was asked to start a new one. I am getting this error trying to complie my HelloWorld.java code. I am a n00b to java and I am trying to start with some of the tutorials here in the forums. I have set my Path in System Variables to:

Quote

Path under System Variables:

lots of stuff here followed by ;C:\Program Files\Java\jdk1.6.0_18\bin


But I still get this error. I am only using Notepad++ right now to write the code instead of a compiler. It was suggested in a couple of places in this forum to do so... this way I am forced to learn the syntax and becoming familiar with it before using a program to do it for me.

Any suggestions on why I can't get this to work? :crazy:

Is This A Good Question/Topic? 0
  • +

Replies To: "JAVAC is Not Recognized as an Internal or External Command"

#2 SwiftStriker00   User is offline

  • No idea why my code works
  • member icon

Reputation: 440
  • View blog
  • Posts: 1,618
  • Joined: 25-December 08

Re: "JAVAC is Not Recognized as an Internal or External Command"

Posted 22 January 2010 - 06:42 AM

Are you sure you downloaded the SDK (not JRE) from Java and it is jdk1.6.0_18?
Also does javac -version give you anything?

This post has been edited by SwiftStriker00: 22 January 2010 - 06:43 AM

Was This Post Helpful? 0
  • +
  • -

#3 skailey   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 12-February 08

Re: "JAVAC is Not Recognized as an Internal or External Command"

Posted 22 January 2010 - 06:48 AM

View PostSwiftStriker00, on 22 Jan, 2010 - 05:42 AM, said:

Are you sure you downloaded the SDK (not JRE) from Java and it is jdk1.6.0_18?
Also does javac -version give you anything?


Yes. I downloaded the JDK and this is what version it gives me.

Quote

Microsoft Windows XP [Version 5.1.2600]
© Copyright 1985-2001 Microsoft Corp.

M:\>c:

C:\>javac -version
javac 1.6.0_18

C:\>

Was This Post Helpful? 0
  • +
  • -

#4 SwiftStriker00   User is offline

  • No idea why my code works
  • member icon

Reputation: 440
  • View blog
  • Posts: 1,618
  • Joined: 25-December 08

Re: "JAVAC is Not Recognized as an Internal or External Command"

Posted 22 January 2010 - 06:50 AM

Well javac is workin on your comp. Are you using the commands like this?

javac HelloWorld.java
java HelloWorld
Was This Post Helpful? 0
  • +
  • -

#5 chirag.jain18   User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 68
  • Joined: 14-December 09

Re: "JAVAC is Not Recognized as an Internal or External Command"

Posted 22 January 2010 - 06:55 AM

If javac is working,as it is giving you the version, you should not get the error"JAVAC is Not Recognized as an Internal or External Command", which you have written in heading of the post.
Was This Post Helpful? 0
  • +
  • -

#6 skailey   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 12-February 08

Re: "JAVAC is Not Recognized as an Internal or External Command"

Posted 22 January 2010 - 07:01 AM

View Postchirag.jain18, on 22 Jan, 2010 - 05:55 AM, said:

If javac is working,as it is giving you the version, you should not get the error"JAVAC is Not Recognized as an Internal or External Command", which you have written in heading of the post.


I was getting that error, but now it seems to be working? Now, when I type:

javac HelloWorld.java

I get:

Quote

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

C:\>


I am trying to post my issue as best as possible. I tried not to start a new thread, instead, I did a search for the answer first. Then, I was directed to start a new thread. That is what I did. I am not sure what changed from last night when I installed JDK and was getting an error to this morning, but I was getting the error. Please remember, I am completely new to java and I am trying to teach myself. I am sorry if I am not posting correctly... I will try to make sure I do better. I can change the title of this if it works better. Thanks!
Was This Post Helpful? 0
  • +
  • -

#7 chirag.jain18   User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 68
  • Joined: 14-December 09

Re: "JAVAC is Not Recognized as an Internal or External Command"

Posted 22 January 2010 - 07:07 AM

javac HelloWorld.java

is your java file in C drive? where have you plaved your java file? Go to that path and then run the command.
Was This Post Helpful? 0
  • +
  • -

#8 SwiftStriker00   User is offline

  • No idea why my code works
  • member icon

Reputation: 440
  • View blog
  • Posts: 1,618
  • Joined: 25-December 08

Re: "JAVAC is Not Recognized as an Internal or External Command"

Posted 22 January 2010 - 07:12 AM

View Postchirag.jain18, on 22 Jan, 2010 - 08:07 AM, said:

javac HelloWorld.java

is your java file in C drive? where have you plaved your java file? Go to that path and then run the command.


chirag.jain18 is right, are you navigating the command prompt to the right directory of your java file?
That will give you the javac: File Not found error.
Was This Post Helpful? 0
  • +
  • -

#9 skailey   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 12-February 08

Re: "JAVAC is Not Recognized as an Internal or External Command"

Posted 22 January 2010 - 07:15 AM

View Postchirag.jain18, on 22 Jan, 2010 - 06:07 AM, said:

javac HelloWorld.java

is your java file in C drive? where have you plaved your java file? Go to that path and then run the command.


Yes, it is on the C drive at: C:\Program Files\Java\jdk1.6.0_18\javac\Src

I thought I was simply supposed to be able to type in the command without going to that path. Anyway... I did that and now I have several errors, which makes me believe my script is wrong.


Quote

C:\Program Files\Java\jdk1.6.0_18\javac\Src>javac HelloWorld.java
HelloWorld.java:3: ')' expected
public static void mad (String args{})
^
HelloWorld.java:3: illegal start of type
public static void mad (String args{})
^
HelloWorld.java:3: ';' expected
public static void mad (String args{})
^
HelloWorld.java:5: <identifier> expected
System.out.println("Hello World");
^
HelloWorld.java:5: illegal start of type
System.out.println("Hello World");
^
HelloWorld.java:7: class, interface, or enum expected
}
^
6 errors

C:\Program Files\Java\jdk1.6.0_18\javac\Src>


I was trying to follow the tutorial in the tutorial forum. This is my code in the .java file:

public class HelloWorld{
	public static void mad (String args{})
	{
		System.out.println("Hello World"); 
	}
}

Was This Post Helpful? 0
  • +
  • -

#10 SwiftStriker00   User is offline

  • No idea why my code works
  • member icon

Reputation: 440
  • View blog
  • Posts: 1,618
  • Joined: 25-December 08

Re: "JAVAC is Not Recognized as an Internal or External Command"

Posted 22 January 2010 - 07:17 AM

public class HelloWorld{
	public static void main (String args[]) //not brases and its main not mad
	{
		System.out.println("Hello World"); 
	}
}



you had 2 errors on your main method declaration, however if you have any further java questions create a new thread as they are not related to this current topic
Was This Post Helpful? 0
  • +
  • -

#11 chirag.jain18   User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 68
  • Joined: 14-December 09

Re: "JAVAC is Not Recognized as an Internal or External Command"

Posted 22 January 2010 - 07:19 AM

public class HelloWorld{
	public static void mad (String args{})
	{
		System.out.println("Hello World"); 
	}
}


change it to

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


and go to a good tutorial site:

http://java.sun.com/.../tutorial/java/
http://www.java2s.co...CatalogJava.htm
Was This Post Helpful? 0
  • +
  • -

#12 skailey   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 12-February 08

Re: "JAVAC is Not Recognized as an Internal or External Command"

Posted 22 January 2010 - 07:25 AM

View Postchirag.jain18, on 22 Jan, 2010 - 06:19 AM, said:

public class HelloWorld{
	public static void mad (String args{})
	{
		System.out.println("Hello World"); 
	}
}


change it to

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


and go to a good tutorial site:

http://java.sun.com/.../tutorial/java/
http://www.java2s.co...CatalogJava.htm


Thank you both. It has created the CLASS file in the same directory, but now I get exceptions when I try to run java HelloWorld. I will save that for another thread if I can't figure it out on my own. I appreciate the patience and help. I will also check out these threads... I appreciate the direction.
Was This Post Helpful? 0
  • +
  • -

#13 SwiftStriker00   User is offline

  • No idea why my code works
  • member icon

Reputation: 440
  • View blog
  • Posts: 1,618
  • Joined: 25-December 08

Re: "JAVAC is Not Recognized as an Internal or External Command"

Posted 22 January 2010 - 07:27 AM

in the directory of the class file you shouldnt add .class, it should look like this:

java HelloWorld
Was This Post Helpful? 0
  • +
  • -

#14 skailey   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 12-February 08

Re: "JAVAC is Not Recognized as an Internal or External Command"

Posted 22 January 2010 - 07:32 AM

View PostSwiftStriker00, on 22 Jan, 2010 - 06:27 AM, said:

in the directory of the class file you shouldnt add .class, it should look like this:

java HelloWorld


Yes sir. I did that... this is what I get:


Quote

C:\Program Files\Java\jdk1.6.0_18\javac\Src>java HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: HelloWorld. Program will exit.

C:\Program Files\Java\jdk1.6.0_18\javac\Src>

Was This Post Helpful? 0
  • +
  • -

#15 SwiftStriker00   User is offline

  • No idea why my code works
  • member icon

Reputation: 440
  • View blog
  • Posts: 1,618
  • Joined: 25-December 08

Re: "JAVAC is Not Recognized as an Internal or External Command"

Posted 22 January 2010 - 07:38 AM

The name of your file and the name of your class need to be the same

since in the code you typed: ...class HelloWorld...., you need to call the java & class file HelloWorld.java and HelloWorld.class

This post has been edited by SwiftStriker00: 22 January 2010 - 07:39 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2