1

Since 2 days now I am trying to run the simplest program and I can't. I run my programs from Windows cmd prompt.

Program:

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

Saved the source code as Bla.java. Compiled the program with javac Bla.java --> Bla.class created. Tried to run the program with java Bla.class I get the error: "Could not find or load main class Bla.class"

I am not a complete newbie with java

1. I have configured my path and my classpath variable (Exact values below). Path: %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\wbem;C:\Python27;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Skype\Phone;C:\mysql\bin;C:\Program Files (x86)\Microsoft SDKs\Azure\CLI\wbin;C:\Program Files\Java\jdk1.8.0_144\bin

CLASSPATH: .;C:\Program Files\Java\jre1.8.0_144\lib;

2. my program doesn't belong to any package and doesn't call any package

I call everything from my command line. I tried uninstalling and reinstalling java developer kit.Every time I get the same error. This is not the first time I have installed java or run a program in java but I haven't written something in a long time. What am I doing wrong?

Thanks

DevDio
  • 1,525
  • 1
  • 18
  • 26
papeneri
  • 37
  • 4
  • visit [What does “Could not find or load main class” mean?](https://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean) for help. – Yousaf Oct 08 '17 at 11:16
  • 1
    You need to run your program with `java Bla` instead of `java Bla.class`. – Thomas Fritsch Oct 08 '17 at 16:51

1 Answers1

0

Assuming your working directory containes Bla.class, and your CLASSPATH contains a "." (among others), java should be able to find it.

However, you should call it without ".class", like this: java Bla. Otherwise, java will think you want to call a class called "class" in package "Bla".

jurez
  • 4,436
  • 2
  • 12
  • 20