Lec08 - String Processing.pdf - Unauthorized reproduction...

This preview shows page 1 - 6 out of 38 pages.

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.String ProcessingPeter Muturi ([email protected]ฺacฺke) has a non-transferable license touse this Student GuideฺUnauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
Java SE 7 Programming 8 - 2Copyright © 2012, Oracle and/or its affiliates. All rights reserved.ObjectivesAfter completing this lesson, you should be able to:Read data from the command lineSearch stringsParse stringsCreate strings by using a StringBuilderSearch strings by using regular expressionsParse strings by using regular expressionsReplace strings by using regular expressionsPeter Muturi ([email protected]ฺacฺke) has a non-transferable license touse this Student GuideฺUnauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
When a Java program is launched from a terminal window, you can provide the program with zero or more command-line arguments.These command-line arguments enable the user to specify the configuration information for the application. These arguments are strings: either stand-alone tokens (such as arg1) or quoted strings (such as "another arg").Java SE 7 Programming 8 - 3Copyright © 2012, Oracle and/or its affiliates. All rights reserved.Command-Line ArgumentsAny Java technology application can use command-line arguments.These string arguments are placed on the command line to launch the Java interpreter after the class name:java TestArgs arg1 arg2 "another arg"Each command-line argument is placed in the args array that is passed to the static main method:public static void main(String[] args)Peter Muturi ([email protected]ฺacฺke) has a non-transferable license touse this Student GuideฺUnauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
Command-line arguments are always passed to the main method as strings, regardless of their intended type. If an application requires command-line arguments other than type String(for example, numeric values), the application should convert the string arguments to their respective types using the wrapper classes, such as the Integer.parseIntmethod, which can be used to convert the string argument that represents the numeric integer to type int.Java SE 7 Programming 8 - 4Copyright © 2012, Oracle and/or its affiliates. All rights reserved.Command-Line Argumentspublic class TestArgs {public static void main(String[] args) {for ( int i = 0; i < args.length; i++ ) {System.out.println("args[" + i + "] is '" + args[i] + "'");}}}Example execution:java TestArgs "Ted Baxter" 45 100.25args[0] is 'Ted Baxter'args[1] is '45'args[2] is '100.25'Peter Muturi ([email protected]ฺacฺke) has a non-transferable license touse this Student GuideฺUnauthorized reproduction or distribution prohibitedฺ Copyright© 2013, Oracle and/or its affiliatesฺ
The benefit of a properties file is the ability to set values for your application externally. The properties file is typically read at the start of the application and is used for default values. But the

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture