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 4 of 4

Thread: Brand New/First Attempt

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Brand New/First Attempt

    Ok so I am doing the infamous Hello World App, here is the code:

    public class HelloApp
    {
    public static void main (String[] args)
    {
    System.out.println("Hello, World!");
    }
    }


    What I have done to my system, in the environment variables under system variables I added:
    C:\Program Files (x86)\Java\jdk1.7.0\bin to the Path

    From the command prompt I am able to compile the code with no errors (javac HelloApp.java)

    I am however not able to execute the code with java HelloApp, I get the following error:
    Error: Could not find or load main class HelloApp

    I am however able to execute the code by typing: java -cp . HelloApp
    Last edited by kevinco; August 14th, 2011 at 06:46 PM.


  2. #2
    Junior Member
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Brand New/First Attempt

    I have now created a folder on the desktop named "Java" and placed both the class file and the java file in it and copied the java.exe file and placed it in the folder and now I am able to execute the java file from the command prompt, so I'm thinking it definitely has something to do with the path to the java.exe but I edited the path

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Brand New/First Attempt

    No. You should not move the java or javac exe files. Leave them in the bin directory. Also you should not place any of your java files in the bin directory, you should have them in a separate directory somewhere else. So what is wrong with using java -cp . appname if it works?
    Improving the world one idiot at a time!

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Brand New/First Attempt

    Did you set the CLASSPATH environment variable?
    If you didn't have the . there, then you will need to use -cp . on your command line.

    Open a command prompt and enter SET to see what your environment variables are set to.
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

Similar Threads

  1. [PROJECT] JWebby: A brand new webserver
    By Verficon in forum Java Networking
    Replies: 2
    Last Post: March 7th, 2011, 11:49 AM
  2. Java dialog box is blank in 2nd attempt while using timer.
    By mocherla81 in forum AWT / Java Swing
    Replies: 1
    Last Post: January 17th, 2011, 09:49 AM
  3. Brand New
    By BigJoe in forum Member Introductions
    Replies: 1
    Last Post: December 27th, 2010, 01:26 PM
  4. [SOLVED] Brand Spanking New to Java...
    By forte in forum What's Wrong With My Code?
    Replies: 7
    Last Post: May 18th, 2010, 06:41 AM