0

I just started Java. I was initially using NetBeans to code and it works. But my teacher is insisting that we use a text editor and run it through Powershell. I'm getting a "Could not find or load main class" error with this code.

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

When I run it on Netbeans, there are no errors, but I'm unable to run it on Powershell. Can someone tell me what's wrong and how I would fix it

user1730056
  • 623
  • 3
  • 11
  • 19

1 Answers1

0

I hope you are compiling the class using

javac a10.java and then running it by java a10--- Is it so

Look at this post for more info

Community
  • 1
  • 1
Extreme Coders
  • 3,441
  • 2
  • 39
  • 55
  • Hi, sorry I originally had the class as a10. I put .java hoping that might fix it. Going back to `public class a10{` did not make it work either. – user1730056 Nov 24 '12 at 04:07
  • a10.java is the correct source file name for a public class called a10. – Patricia Shanahan Nov 24 '12 at 04:16
  • First type javac a10.java -> This process is called compiling. It converts the java source code to a executable code. You can see a file a10.class created after this process. This file contains the executable code. Then run the compiled file by java a10 – Extreme Coders Nov 24 '12 at 04:31
  • the command javac is not recognized. do I have to download it? – user1730056 Nov 24 '12 at 04:43
  • I think you do not have Java development Kit(JDK) installed. Instead you have Java Runtime environment(JRE). If it is so then you must download and install jdk. Otherwise you cannot compile and run java programs – Extreme Coders Nov 24 '12 at 04:46
  • I have Java SE Development kit 7u9 – user1730056 Nov 24 '12 at 04:48
  • Weird, it appears to be in the JRE when I have downloaded and installed the jdk – user1730056 Nov 24 '12 at 04:51
  • Check this link how to use javac : http://stackoverflow.com/questions/7709041/javac-is-not-recognized-as-an-internal-or-external-command-operable-program-or – Extreme Coders Nov 24 '12 at 05:02
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/20026/discussion-between-algorithms-and-user1730056) – Extreme Coders Nov 24 '12 at 07:04