Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Netbeans vs. reality conflict

  1. #1
    Member
    Join Date
    Jul 2013
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Netbeans vs. reality conflict

    Greetings folks. Here's one of those questions that seems to have been asked a million different times in a million different ways by a million different people, but none of those answers seems to be relevant to me.

    Ok, so I am just starting out with Java, using the Oracle Java tutorials. I used Netbeans IDE to create the simple HelloWorldApp program, compiled it to a .class file, and then it works fine in Netbeans using the Run command there, but I wanted to see if it would work from the command line (because not everyone's going to have Netbeans but they still might want to run my program). Surprise surprise, it didn't work.

    So now I will provide all the pertinent data. First, the program code:

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package helloworldapp;
     
    /**
     *
     * @author //my name deleted
     */
    public class HelloWorldApp {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            System.out.println("Hello World!");
        }
    }

    Screenshot of error:

    Java-error.jpg

    There you go lol. Thanks in advance!

    -summit45


  2. #2
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: Netbeans vs. reality conflict

    try
    HelloWorldApp instead of helloworldapp

  3. #3
    Member
    Join Date
    Jul 2013
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Netbeans vs. reality conflict

    Quote Originally Posted by derekxec View Post
    try
    HelloWorldApp instead of helloworldapp
    I have, multiple times, and it doesn't work. Same result.

    -summit45

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Netbeans vs. reality conflict

    Ditch the IDE (eg Netbeans) for the moment and start from the beginning - compile and run all via the command line.
    See Lesson: The "Hello World!" Application (The Java™ Tutorials > Getting Started) for the appropriate OS instructions
    The class you posted is contained within a package, which is an important topic in and of itself, but makes compiling and running code more complex for someone trying to learn topics that need to be learned beforehand.

  5. #5
    Member
    Join Date
    Jul 2013
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Netbeans vs. reality conflict

    Quote Originally Posted by copeg View Post
    Ditch the IDE (eg Netbeans) for the moment and start from the beginning - compile and run all via the command line.
    See Lesson: The "Hello World!" Application (The Java™ Tutorials > Getting Started) for the appropriate OS instructions
    The class you posted is contained within a package, which is an important topic in and of itself, but makes compiling and running code more complex for someone trying to learn topics that need to be learned beforehand.
    Well, I appreciate that, but I'd rather understand why this isn't working when there is no legitimate reason why it shouldn't be.

    -summit45

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Netbeans vs. reality conflict

    There is a legitimate reason. Saying there isn't because you don't understand it or don't want to take the advice given is a bit odd.

    As copeg said, your source code specifies that it is in a package. The use of packages adds complexity - especially to working from the command line - not typically introduced at the HelloWorld level. To address that complexity, back up a directory level, to "classes", and type:

    java helloworldapp\HelloWorldApp

    Good luck!

  7. #7
    Member
    Join Date
    Jul 2013
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Netbeans vs. reality conflict

    Quote Originally Posted by GregBrannon View Post
    There is a legitimate reason. Saying there isn't because you don't understand it or don't want to take the advice given is a bit odd.
    There is always a "real" reason, if you will, why any bug exists. The legitimacy of it is an opinion. I find it silly for a program executor to be this finicky.

    As copeg said, your source code specifies that it is in a package. The use of packages adds complexity - especially to working from the command line - not typically introduced at the HelloWorld level. To address that complexity, back up a directory level, to "classes", and type:

    java helloworldapp\HelloWorldApp
    Tried. I've tried it before because I found this same suggestion on a Google search, except "java helloworldapp.HelloWorldApp" (in my case) was/would have been recommended. Tried again now with a slash instead. Same error.

    -summit45

  8. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Netbeans vs. reality conflict

    Then something else is going on. As you've (kind of) said, this isn't that hard, but the steps to compile and run a Java program have to be done exactly right with the files in their proper places. IDEs do things behind the scenes that, until the user understands the steps well, may make it difficult to pick up where they've left off and complete the necessary steps correctly.

    I know you've already pooh-poohed copeg's suggestion as non-productive, but I recommend you reconsider. Take the same HelloWorld program, first without the package declaration, and a simple programmer's editor like NotePad+ or even Geany, and get it running from the command line. Once you've mastered the simplest case, well documented in tutorials all over the web, put the same source file in a package, note the differences in the resulting directory structure (or not), and get that running from the command line using the right commands correctly applied, perhaps one or a variation of one of those you've already tried.

    It's a good exercise, and you should be a bit smarter and more confident in the whole compile/run process once you're done. You might even learn a simple programmer's editor well enough to become confident in its use and recognize that the skill is an attractive alternative to firing up one of the large IDEs which can be more trouble than they're worth sometimes.

    Good luck and please keep us posted.

  9. #9
    Member
    Join Date
    Jul 2013
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Netbeans vs. reality conflict

    Quote Originally Posted by GregBrannon View Post
    I know you've already pooh-poohed copeg's suggestion as non-productive, but I recommend you reconsider.
    That's a harsh way to put it. I didn't "pooh-pooh" it. I understand it, and I understand it may be useful to drop the IDE and learn the command line better, but I just was hoping to get an answer about what is actually going on rather than only "just drop it and do this instead."

    But apparently the error is too complicated for even the experts of Java Forum to understand. Which is why I say, it's illegitimate.

    Well, I'll give the command line way I try then I suppose. Thanks for the advice.

    -summit45

  10. #10
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Netbeans vs. reality conflict

    To correctly invoke packaged classes from the command-line:

    1. Navigate to the "root" directory of your program (a.k.a. the directory where packages are located in).

    For example, say I have the following directory structure:
    C:/my_project/bin/helloworldapp/HelloWorldApp.class

    I would want my working directory to be C:/my_project/bin.
    cd C:/my_project/bin

    2. Invoke one of these:

    java helloworldapp.HelloWorldApp
    java helloworldapp/HelloWorldApp

    Note very carefully that the second example uses a forward slash (/), not a backslash (\) as is common for Windows paths. Also note that all names are case sensitive. That means these calls will all fail:

    java Helloworldapp.HelloWorldApp
     
    java helloworldapp/helloworldapp
     
    java HelloWorldApp.helloworldapp
     
    java helloworldapp\HelloWorldApp
     
    cd helloworldapp
    java HelloWorldApp

    Very subtle differences for humans, but are completely different for the computer.

    If this fails, it's very likely that the location of the class file isn't where you/we think it is. In this case, you'll need to search through your directory structure to find where HelloWorldApp.class is located, and make sure it is inside a folder named helloworldapp (again, case sensitive).

    Yeah, it's complicated and it can get much worse which is why IDE's and build managers were created to begin with. Trying to use an IDE with the command-line is asking for all this complexity to be dumped on you always (often times in quite obscure ways), where-as with notepad you get to pick and choose what complexity you're ready for.

  11. The Following User Says Thank You to helloworld922 For This Useful Post:

    GregBrannon (July 24th, 2013)

  12. #11
    Member
    Join Date
    Jul 2013
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Netbeans vs. reality conflict

    Thank you, helloworld! That did it. Which is strange because I thought I tried that before, but maybe I got the capitalization wrong.

    Much obliged.

    -summit45

Similar Threads

  1. NetBeans help please!
    By JuLiAnc in forum AWT / Java Swing
    Replies: 4
    Last Post: January 9th, 2012, 06:16 AM
  2. Netbeans 6.8
    By selmaky in forum Java IDEs
    Replies: 1
    Last Post: May 14th, 2011, 03:08 PM
  3. New to NetBeans
    By _lithium_ in forum Java IDEs
    Replies: 0
    Last Post: March 1st, 2011, 08:48 PM
  4. Netbeans help
    By [Kyle] in forum Java IDEs
    Replies: 2
    Last Post: September 20th, 2009, 06:32 PM
  5. Replies: 3
    Last Post: May 8th, 2009, 01:27 PM