Aroma 1: Arguments to Appl - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Aroma 1: Arguments to Appl

Description:

Aroma 1: Arguments to Appl* Special Topics: Java. Dr. Tim Margush ... This invokes the method main in the named class. main has one argument - an array of Strings ... – PowerPoint PPT presentation

Number of Views:65
Avg rating:3.0/5.0
Slides: 9
Provided by: timma87
Category:
Tags: appl | arguments | aroma

less

Transcript and Presenter's Notes

Title: Aroma 1: Arguments to Appl


1
Aroma 1 Arguments to Appl
  • Special Topics Java

Dr. Tim Margush Department of Mathematics and
Computer Science The University of Akron
2
Command Line Arguments
  • Used in applications
  • Command line always looks like this
  • java classname command line arguments
  • This invokes the method main in the named class
  • main has one argument - an array of Strings
  • words are parsed into array components

3
Application Main
  • public static void main ( String argv )
  • System.out.println(
  • "Number of arguments specified "
  • argv.length)
  • int j, sum 0
  • for (j0 jltargv.length j)
  • sum Integer.valueOf(argvj).intValue()
  • System.out.println("--"j"-gt"argvj"lt---")
  • System.out.println( "Sum of arguments is "
    sum)

4
Illustration argv
  • argv ref0___gt"first_word"
  • ref1___gt"second_word"
  • ref2___gt"third_word"
  • argv.length is 3

first_word
second_word
10
11
third_word
10
3
5
Type Conversion
  • Integer.valueOf(argvj).intValue()
  • class Integer contains a class method, valueOf
  • takes a String and constructs an Integer object
    with the value represented by the String
  • class Integer has an instance method, intValue
  • returns a primitive int whose value matches that
    of the Integer object

6
String Concatenation?
  • this concatenation ("--"j"-gt"argvj"lt---"
  • becomes new StringBuffer()
  • .append("--").append(j).append("-gt")
  • .append(argvj).append("lt---).toString()
  • Concatenation uses the StringBuffer class
  • StringBuffer has an append for most data types
  • method toString() converts the StringBuffer
    object back to a String expected by the print
    method

7
Applet Arguments
  • Applet tag can include named parameters
  • ltapplet code"ParamApplet" width525 height100gt
  • ltparam namemyName value"Johnny Appleseed"gt
  • ltparam nameBGColor value"008000"gt
  • ltparam name"FGColor" value"FFFFFF"gt
  • ltparam name"Font Size" value"64"gt
  • lt/appletgt

8
Applet Accessing Arguments
  • String sFontSize, sMyName
  • Integer iFontSize
  • sMyName getParameter ("myName")
  • if (sMyNamenull) sMyName"Mr. Dephault"
  • sFontSize getParameter ("Font Size")
  • if (sFontSizenull) sFontSize"32"
  • iFontSize Integer.valueOf(sFontSize).intValue()
Write a Comment
User Comments (0)
About PowerShow.com