r/learnjava • • Jun 18 '21

Relearning java after years of not programming after college. I can compile fine in my IDE but not Command Prompt

So I am using a recommended tutorial by John Purcell and noticed right away he is using Eclipse which is to resource heavy for me so I am using NetBeans, then I also noticed what should be in the introduction of using a command prompt and notepad+ like my professor thought is missing. So I had to reteach myself how to use the command prompt for java. I do all that get the could not find or load main class error. I go set the paths in environmental variables. For some reason only 1 file will properly compile in command prompt after that. I can copy and paste the code into a new project properly rename it then when I try to type in java and " insert program name" after compiling it in javac it won't load. I could see if nothing I program worked in the command prompt it would be a simple path issue but 1 program thats in the same exact folder as the others works. I am five minutes from just being a IDE noob at this point because this is 2 days of Could not find or load main class issues now. The IDE finds it fine this didn't happen when I used to program years ago I just can not make sense of this. !!!! Update !!!!! I figured out the problem really stupid I didn't notice been making projects with ant and I don't think thats what I was using 6 years ago. It adds a line that says package followed by the name of my class/file name. I deleted the line that said package and it works in command prompt. I should have from the beginning just opened up the java file that worked in notepad and looked for differences.

54 Upvotes

14 comments sorted by

View all comments

1

u/Niyaz_Ahamed_0109 Jun 19 '21

This is old technique but it will workout with all the aspects properly.

Without using IDE, we can able to run the Java programming by using command prompt, before that you must ensure the JDK and JRE not is Local Disk C: place that both folders in some other Local Disk. The reason behind it, some of the System file can't able to modify in Local Disk C:.

Set the path in command prompt to that specific Local disk where you place the both folders. Then start compiling the Java programming. You may write program in Notepad++ and compile that Java file in Command prompt is possible. Want to learn more Java Programming you can contact Java Training institutes and there are lot of options in Online free websites like Github, Javatutorial, and etc.