Need help running my java program | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Need help running my java program

I am trying to run my program to test it in my PC's cmd. I used javac command to compile it and it made a .class file in my folder. When I type, "java program" it says, "Error: Could not find or load main class program."

14th Dec 2018, 4:30 PM
Dustin James Locey
Dustin James Locey - avatar
12 Answers
+ 7
Try dir command in the folder where you called your program. Does it show the compiled program.class file? If not check which package you declared on top of your java file and move to that folder to run the .class file. (Alternatively you can add this folder to the CLASSPATH as mentioned by Rishi Anand)
14th Dec 2018, 7:29 PM
Tashi N
Tashi N - avatar
+ 2
Then you must be doing typo while typing class name. I guess the first letter of your class name is in uppercase javac Program.java java Program
14th Dec 2018, 5:25 PM
Rishi Anand
Rishi Anand - avatar
+ 2
Then the problem must be in Environment Variables Check whether you had properly specified PATH and CLASSPATH or not. At last if this also won't work then better re-install java in your system
14th Dec 2018, 7:00 PM
Rishi Anand
Rishi Anand - avatar
+ 1
Yes, and yes, my class is Program. Same as the name. And what do you mean with the third one?
14th Dec 2018, 4:45 PM
Dustin James Locey
Dustin James Locey - avatar
+ 1
I'm a beginner
14th Dec 2018, 4:45 PM
Dustin James Locey
Dustin James Locey - avatar
+ 1
I typed that in
14th Dec 2018, 4:48 PM
Dustin James Locey
Dustin James Locey - avatar
+ 1
That's when I got that error
14th Dec 2018, 4:49 PM
Dustin James Locey
Dustin James Locey - avatar
+ 1
I dont have any typos. I'll post the code, just a sec.
14th Dec 2018, 6:03 PM
Dustin James Locey
Dustin James Locey - avatar
14th Dec 2018, 6:04 PM
Dustin James Locey
Dustin James Locey - avatar
+ 1
I updated the Path with the directories to jdk and jre. But I wasnt told to update classpath
14th Dec 2018, 7:03 PM
Dustin James Locey
Dustin James Locey - avatar
+ 1
So, I add the folder my .java and .class are in to classpath?
14th Dec 2018, 7:42 PM
Dustin James Locey
Dustin James Locey - avatar
+ 1
Hello?
16th Dec 2018, 5:17 AM
Dustin James Locey
Dustin James Locey - avatar