Command Line Arguments

Command Line Arguments - String args ) In BlueJ: When we...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Command Line Arguments Command-line arguments = strings that follow the name of the application program on the command line when the program is executed. Example: Suppose you have a program called FileCopy that copies one file to another. To compile this program, you might type the following command: javac FileCopy.java To run this program, you then type: java FileCopy oldFile.txt newFile.txt ^ ^
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
args[0] args[1] Note: The command line arguments are Strings - they are passed to the main method of your program in the String array called args. Recall the main method header: public static void main(
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: String args ) In BlueJ: When we execute the main() method of our program, we include our command line arguments inside double quotes, and the list of command line arguments should be enclosed in braces. For example, {"oldFile.txt", "newFile.txt"}. Example: Write a program that takes some number of Strings on the command line, and prints them to the screen. Example: Write a program that takes one or more integers on the command line and prints their sum to the screen. Example: Write a program that takes a file name on the command line, and prints the first line from that file to the screen....
View Full Document

This note was uploaded on 02/24/2010 for the course C S 305j taught by Professor Staff during the Spring '08 term at University of Texas.

Page1 / 3

Command Line Arguments - String args ) In BlueJ: When we...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online