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

Info icon This 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 ^ ^
Image of page 1

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

View Full Document Right 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(
Image of page 2
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern