• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Text Pad help

 
khoa tran
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all!

I'm currently using textpad 7 and I am having some problems running a script. I'm trying to run the basic

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

}

At first I didn't have the compile and run commands but I fixed that. When I compile it, it generates a .java file no problem. When I run it however it states:

Error: could not find or load main class hello
press any key to continue.

I noticed textpad didn't generate a .class file. I attempted to do it manually with the cmd prompt. I used cd to browse to the directory my hello.java file was in. I then typed in:

javac hello.java

I received this error:

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

my JDK and textapd 7 is installed properly and I don't know where to go from here.

Please help!



 
Aj Prieto
Ranch Hand
Posts: 75
Android Chrome Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you set your PATH variable?

http://docs.oracle.com/javase/tutorial/essential/environment/paths.html
 
khoa tran
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, in the path variable I have

C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\; C:\Program Files\Java\jdk1.7.0_25\bin

I wasn't sure what the old path was so I put in a ; to separate the two. Does that not work the way I think it does?
 
khoa tran
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to run the code again, I noticed now that when I compile I get the error

C:\Users\Jonsen\Desktop\College\hello.java:1: error: class HelloWorld is public, should be declared in a file named HelloWorld.java
public class HelloWorld
^
1 error

Tool completed with exit code 1
 
Charles D. Ward
Ranch Hand
Posts: 99
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shouldn't your file name match your class name? I think that error message is very clear.
 
khoa tran
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Charles D. Ward wrote:Shouldn't your file name match your class name? I think that error message is very clear.

You're right I fixed that now. It puts out this error

javac: file not found: C:\Users\Jonsen\Desktop\College\hello.java
Usage: javac <options> <source files>
use -help for a list of possible options

Tool completed with exit code 2
 
Mike Simmons
Ranch Hand
Posts: 3041
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ummm... are you still typing

javac hello.java

?

Try replacing it with

javac Hello.java
 
khoa tran
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class HelloWorld
{
public static void main (String[] args)
{
System.out.println("Hello World!");
}

}

I found my problem it was the capital on line 1 HelloWorld
^
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a public class named HelloWorld, then you should save that in a file named HelloWorld.java. Not: hello.java, Hello.java, helloworld.java or anything else. The name of the source file should be exactly the same as the name of the public class that it contains. Note that case matters for Java, even though filenames are not case-sensitive according to Windows.

Compile it from the command line with:

javac HelloWorld.java

You should then have a file named HelloWorld.class. Run it with:

java HelloWorld
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic