Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Text Pad help

 
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!



 
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
 
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
 
Rancher
Posts: 3571
39
  • 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
^
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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
 
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic