Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Difference in Compilation output of Java program, When trying to run with 'Intellij IDE' and 'Terminal'

Actually, I was excuting a perticular program, as shown in Picture below…

1st Case : Running the same.java file with default Run option in Intellij IDE

–> Gives the correct output ( you can see in pic )

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

2nd Case : Running the same.java file with command javac same.java in Terminal

error: cannot find symbol
        anotherClass.main(new String[]{"aditya"});  
        ^  
  symbol:   variable anotherClass 
  location: class same

enter image description here

Why Is that Issue…
As of I know In java by default the "java.lang" and the "current working directory" packages are by default imported…

>Solution :

When you run code from IDE, the IDE compiles all the classes in your project. When you run code from the command prompt, YOU must compile all the necessary classes. In this case, you didn’t compile anotherClass.

Here is a link on how to compile multiple files from command line: https://docs.oracle.com/en/java/javase/13/docs/specs/man/javac.html. Go down to the section "Example of Compiling Multiple Source Files"

As a side note, use proper naming conventions. The industry-accepted naming convention for classes is "CamelCase".

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading