Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8370017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:48:26+00:00 2026-06-09T13:48:26+00:00

Running basic java programs from commands line is a 3 steps process: Write code:

  • 0

Running basic java programs from commands line is a 3 steps process:

  1. Write code:

    public class HelloWorld {
    public static void main(String[] args) {
    System.out.println(“Hello, World”);
    }
    }

  2. Compile by javac HellWorld.java which would check for errors & generate HelloWorld.class file.

  3. run code by giving the class name –> java HelloWorld

Now,
I am curious to know why:

java HelloWorld works but when we give fullpath of the classfile, it throws an error

$ java HelloWorld.class 
Error: Could not find or load main class HelloWorld.class

What does it make a difference if we give just the classname Vs classname with file-extension?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:48:27+00:00Added an answer on June 9, 2026 at 1:48 pm

    What does it make a difference if we give just the classname Vs classname with file-extension?

    The argument you give to the java binary isn’t meant to be a filename. It’s meant to be a class name. So in particular, if you’re trying to start a class called Baz in package foo.bar you would run:

    java foo.bar.Baz
    

    So similarly, if you try to run java HelloWorld.class it’s as if you’re trying to run a class called class in a package HelloWorld, which is incorrect.

    Basically, you shouldn’t view the argument as a filename – you should view it as a fully-qualified class name. Heck there may not even be a simple Baz.class file on the file system – it may be hidden away within a jar file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running a basic GWT application in IntelliJ, below is my code public
I want to move a long-running process in an Java EE application from synchronous
I have a basic web application written in Java, running on a tomcat on
I have some very basic SignalR code running on the js client: var conn
My goal is to run SVN commands from java for one of my requirements,
Having a very basic issue with running tests in a Java Play 2.0 app.
Okay, so I've been running a Java/Jersey webservice on Tomcat with basic authentication which
When running a java applet that I made (a basic little number-guessing game), whenever
Having a very basic problem here building/running a Java skeleton to make use of
I'm running a basic Java wrapper for a C++ BSD socket client. I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.