0

I'm having a bit of trouble trying to run a java class on the command prompt. Its a very simple class and a friend of mine says it could be a problem with windows 8. Are there any suggestions. Here i'll show you the class and how I tried to compile it. I works fine in eclipse.

           package gmit;

           public class A {
             public static void main(String[] args) {
               System.out.println("hello");
             }
           }

In the command prompt I wrote C:\Users\eclipse\workspace\Oct1stcasting\src\gmit>

followed by - javac A.java

java A.class

I tested the class using type A.java
and the text from the class does come up. What am I doing wrong? Any help would be great.

1
  • 1
    to run class with java you should specify only class name, without .class Commented Oct 1, 2013 at 11:12

4 Answers 4

1

If it runs in an Eclipse project, but not from command line, you could try this:

C:\Users\eclipse\workspace\Oct1stcasting\bin\gmit>java A

Inside a project directory, Eclipse saves source codes in /src and bytecodes in /bin. Thus, if you simply want to run your bytecode from command line, changing directory to /bin might suffice.

Sign up to request clarification or add additional context in comments.

Comments

0

To compile

C:\Users\eclipse\workspace\Oct1stcasting\src\gmit>javac A.java

To run

C:\Users\eclipse\workspace\Oct1stcasting\src\gmit>java A

Don't append the .class extension while running the java program

Comments

0

Don’t add a .class suffix when using the java command.

Use java A or java -cp . A. The latter is required if the current directory is not implicitly used as class path.

Comments

0

Compilation:

C:\Users\eclipse\workspace\Oct1stcasting\src>javac gmit/A.java

Executing:

C:\Users\eclipse\workspace\Oct1stcasting\src>java gmit/A

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.