• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to compile args[ ]?  RSS feed

 
PETER CARTER
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class Foo {
public void main( String[] args ) {
System.out.println( �Hello� + args[0] );
}
}

How to compile it ?
 
PETER CARTER
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class Foo {
public static void main( String[] args ) {
System.out.println( �Hello� + args[0] );
}
}
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First install a J2SDK, which you can download from Sun.

http://java.sun.com

After saving the example code in a file name Foo.java, the command to compile it is

javac Foo.java

Note: It appears that you're using double-quote characters as created by some fancy word processors, such as Microsoft Word. To compile, you'll need to replace those with plain old " characters, as created by plain text editors like Notepad.
[ September 12, 2004: Message edited by: Dirk Schreckmann ]
 
Marilyn de Queiroz
Sheriff
Posts: 9080
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
args[0] is a string you pass in on the command line when you run the program after it is compiled. Are you getting an error when you type

javac Foo.java

??

If so, what is it?

When you run the program, you need to pass in an argument -- something like

java Foo Peter
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!