-1

I wrote a normal ''Hello World!'' code in gedit and compile it. İt runs perfect in linux terminal. I tried to run it in Windows 8.1 cmd but it didn't work. When I write ''java Muz'' , it says:

Error: Could not find or load main class Muz.

What should I do???

(I'm new at java btw!)

Ugur Aydın
  • 5
  • 1
  • 1
  • 5
  • You need to compile it first with `javac`. – RaminS Jun 22 '16 at 16:11
  • I already compile it with javac. İt works in linux. But not in windows cmd. Should I need to javac it in cmd again? – Ugur Aydın Jun 22 '16 at 16:14
  • Make sure you write the name of the class and not the name of the file (if they aren't the same) when you write `java`. – RaminS Jun 22 '16 at 16:15
  • you have a problem with the package.... you need to navigate to the ritgth location to start the app – ΦXocę 웃 Пepeúpa ツ Jun 22 '16 at 16:16
  • You should post a complete question. If your problem is running a Java class from the command line, you should post at least the location of the file, the package name of your java class and the command you are using. – David SN Jun 22 '16 at 16:17

1 Answers1

3

I think that this question was already answered here: How do I run a Java program from the command line on Windows? and the sorce is here: http://www.skylit.com/javamethods/faqs/javaindos.html

For this example your file is in C:\mywork\

Type

C:\> cd \mywork

This makes C:\mywork the current directory.

C:\mywork> dir

This displays the directory contents. You should see HelloWorld.java among the files.

C:\mywork> set path=%path%;C:\Program Files\Java\jdk1.8.0_51\bin

(use the JDK folder for the version installed on your system). This tells the system where to find JDK programs.

C:\mywork> javac HelloWorld.java

This runs javac.exe, the compiler. You should see nothing but the next system prompt...

C:\mywork> dir

javac has created the HelloWorld.class file. You should see HelloWorld.java and HelloWorld.class among the files.

C:\mywork> java HelloWorld

This runs the Java interpreter. You should see the program output:

Hello, World!

If the system cannot find javac, check the set path command. If javac runs but you get errors, check your Java text. If the program compiles but you get an exception, check the spelling and capitalization in the file name and the class name and the java HelloWorld command. Java is case-sensitive!

Community
  • 1
  • 1
szania04
  • 111
  • 4
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/12777031) – Gennadii Saprykin Jun 22 '16 at 17:00
  • @GennadiiSaprykin ok, You're right I've already edited it! :D – szania04 Jun 22 '16 at 17:11