• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Running Java in the command prompt

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!

I'm currently having an issue with running java in my command prompt on Windows! I had to reinstall java and the eclipse IDE on my PC today as I was having issues running JavaFX in eclipse (now resolved yay) but I'm now having another problem     previously I edited the environment path variables which worked with the previous install (I was using JDK13 at the time) but trying this again has been unsuccessful, I'm now using Java 8 as recommended by other students on my course to use an earlier version.

I'm able to use the command javac to compile the java files, however I receive the error message when trying to run with java Codes.java etc:
Error: Could not find or load main class Codes.java

I have tried this with some of the codes which ran perfectly fine before the reinstall (they are all quite basic, like string printing and some calculations so can't imagine there's a syntax issue with a different java version) but even the HelloWorld is producing the same error but will still compile? I am very confused :'(

Any help or advice is appreciated!
Capture.JPG
[Thumbnail for Capture.JPG]
Command lines in windows
 
Sheriff
Posts: 27451
88
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rona Plant wrote:I'm able to use the command javac to compile the java files, however I receive the error message when trying to run with java Codes.java etc:



To compile the Codes class you type "javac Codes.java" but then to run it you type "java Codes".
 
Rona Plant
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OMG Thank you, it was that simple I can't believe I got myself into such a tiff over this :')

It's all good now, cheers!
 
Sheriff
Posts: 17316
299
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Running Java programs the way you tried wasn't supported until recently so while Java 13 would have executed that command without any problems, Java 8 still required you to run the compiler, javac, first.
 
Marshal
Posts: 76854
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junilu Lacar wrote:. . . Java 13 would have executed that command without any problems . . .

It's not quite that simple; you must have all your code in the one file XYZ.java, and you mustn't have an XYZ.class file, and there are probably other restrictions I have forgotten about.
 
Junilu Lacar
Sheriff
Posts: 17316
299
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Based on OP's confusion and inferring from what was posted, running the program directly probably worked before Java 13 was replaced by Java 8. But you're right about there being restrictions.
 
Do not meddle in the affairs of dragons - for you are crunchy and good with ketchup. Crunchy tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic