Results 1 to 6 of 6
  1. #1
    tomelk31 is offline Member
    Join Date
    Jul 2011
    Posts
    4
    Rep Power
    0

    Default Need help with my first program

    I have just finished my first year at Uni and one of my modules next year is Java so i thought i would get a head start and learn the basics now.

    I have download the latest version of the development java environment. I am starting with Hello World program.

    Java Code:
    class Hello
    {
    	public static void main ( String[] args )
    	{
    		System.out.println( "Hello World!" ) ;
    	}
    }
    The program complies using javac in the command prompt and creates the file Hello.class but then when I try and run the program via
    Java Code:
    java Hello
    .

    Then the following message comes up and I don't know why.



    Thank you to anyone that can help me!

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,648
    Blog Entries
    7
    Rep Power
    21

    Default

    Does it help if you do:

    Java Code:
    java -cp . Hello
    (assuming that a file Hello.class exists in the current working directory).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,556
    Rep Power
    25

    Default

    Also could you do enter a dir command to show the files in the Java folder.

  4. #4
    tomelk31 is offline Member
    Join Date
    Jul 2011
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Does it help if you do:

    Java Code:
    java -cp . Hello
    (assuming that a file Hello.class exists in the current working directory).

    kind regards,

    Jos

    That worked. But could explain what is doing? Thanks

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    It specifies the class path to look in for the file. You can set this in your environment variables to always look at certain paths, some people don't like to do this and prefer to use the -cp flag.

    One dot "." refers to the current working directory.
    Last edited by sunde887; 07-07-2011 at 10:24 PM.

  6. #6
    tomelk31 is offline Member
    Join Date
    Jul 2011
    Posts
    4
    Rep Power
    0

Similar Threads

  1. Replies: 2
    Last Post: 04-02-2011, 12:57 PM
  2. Replies: 13
    Last Post: 03-22-2011, 06:49 AM
  3. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •