Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

runing .class

 
Greenhorn
Posts: 3
Android Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a hello world code in wordpad and saved it as MyFirstApp.java. I compiled it with javac and got MyFirstApp.class. When I do

java C:\Users\user\Documents\Java\Projects\MyFirstApp.class

or

cd C:\Users\user\Documents\Java\Projects
java MyFirstApp.class

I get "Could not find or load main class MyFirstApp.class"
 
Sheriff
Posts: 7108
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

You just need to leave off the ".class" suffix and it should work.
 
Prince Banga
Greenhorn
Posts: 3
Android Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:Welcome to the Ranch.

You just need to leave off the ".class" suffix and it should work.



thanks
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not just a matter of leaving the ".class" filename extension off.

The java command takes a class name, not a filename.

If you would do: java C:\Users\user\Documents\Java\Projects\MyFirstApp then it would still not work, because C:\Users\user\Documents\Java\Projects\MyFirstApp is not a class name.
 
The problems of the world fade way as you eat a piece of pie. This tiny ad has never known problems:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic