Computing.Net > Forums > Programming > java code problem

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

java code problem

Reply to Message Icon

Name: hye345
Date: January 13, 2005 at 22:40:34 Pacific
OS: windows xp home edition w
CPU/Ram: 2.53 ghz, 512 ram
Comment:

i type the following code in java:

public class Book
{
public static void main(String [0] args)
public static void main(String [1] args)
{
System.out.println("Title: " + args[0]);
System.out.println("Author: " + args[1]);
}
}

in the command line, i type java book "Green eggs and ham" "dr seusse"

it wont compile, and im in the rite directory. what am i doing wrong?



Sponsored Link
Ads by Google

Response Number 1
Name: bamakhrama
Date: January 14, 2005 at 01:36:55 Pacific
Reply:

Hi,
1) you can NOT have 2 main functions ins the same program.
2) No need to specify the length of the args[] array. It will be set automatically by the OS.
Here is the working code:

public class Book

{

public static void main(String[] args)

{

System.out.println("Title: " + args[0]);

System.out.println("Author: " + args[1]);

}

}

--
mohameda@ieee.org


0

Response Number 2
Name: hye345
Date: January 14, 2005 at 15:58:48 Pacific
Reply:

what would i have to type into a command line for it to show up?


0

Response Number 3
Name: hye345
Date: January 14, 2005 at 16:04:00 Pacific
Reply:

i type java book "green eggs and ham" "dr seusse" and it says expeption in thread "main" java.lang.NoClassDefFoundError: book


0

Response Number 4
Name: hye345
Date: January 14, 2005 at 18:02:03 Pacific
Reply:

it worked. thx.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


PHP simple file WTF Java sql server procedure...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: java code problem

beginner Java GUI problem www.computing.net/answers/programming/beginner-java-gui-problem/1912.html

test java code online www.computing.net/answers/programming/test-java-code-online/12093.html

How EXE java compiler in Java Code? www.computing.net/answers/programming/how-exe-java-compiler-in-java-code/2492.html