Implement on UH UNIX using the command line interface The command line is the line at the prompt on the UNIX shell Commands Text editor: emacs Program.java Compiler: javac Program.java Interpreter: java Program A demo will be given in class © 2006 William AlbrittonĪrguments (strings) entered on the command line can be accessed in your Java program args is an array of Strings public static void main(String args) Corresponds to the words listed after the name of the Java program Below is I/O for program Repeat.java java Repeat one two three args is the String "one" args is the String "two" args is the String "three" © 2006 William Albrittonġ3 Command line & IDEs See file Repeat.java UHUNIX commands Pass an array to a method Return an array from a method © 2007 William Albrittonġ0 Class Exercise 1 See Exercise1.java What’s the output of the program?
![jgrasp command line jgrasp command line](https://courses.cs.washington.edu/courses/cse142/17sp/images/jgrasp2.png)
Jgrasp command line code#
More questions on this? Write loops to do the following: Make an array of these elements: 1,2,3,4,5 Multiply each element by 10 Assign each element to 100 © 2006 William Albrittonģ Common Bug For reference variables, have to initialize them to a specific object, or else… Since reference variables are initialized to null, can easily throw a NullPointerException String stooges = new String Integer length = stooges.length() //bug Correct way: stooges = new String("Larry") Integer length = stooges.length() © 2006 William AlbrittonĤ Common Bug II Determining the length of a String and an array are different Arrays use the public data field length String stooges = new String Integer arrayLength = stooges.length Strings use the method length() String stooges = new String stooges = new String("Larry") Integer strLength=stooges.length() See Stooges.java © 2006 William Albrittonĥ Array Parameters Syntax for a method call that passes an array as the actual parameter method(arrayName) Just use the name of the array (no brackets) Syntax for a method definition that passes an array as the formal parameter public static ReturnType method(DataType parameter) © 2007 William Albrittonĩ Example Code See ArraysAndMethods.java This program shows how to: © 2006 William AlbrittonĢ Array Review See code at ArrayExercise.java Who would pay for a message sent to nobody in particular?" David Sarnoff's associates in response to his urgings for investment in the radio in the 1920s.
![jgrasp command line jgrasp command line](https://images.slideplayer.com/17/5312857/slides/slide_3.jpg)
ICS 111: Introduction to Computer Science I William Albritton Information and Computer Sciences Department at the University of Hawai‘i at Mānoa "The wireless music box has no imaginable commercial value. Presentation on theme: "Command Line Arguments"- Presentation transcript: