appletviewer
? (Note: “One runs in a
browser and the other doesn’t” isn’t a good answer.)
Applets run via appletviewer
don’t have the Internet capabilities
that are available in a broswer (p. 33).
The answers, approximately verbatim, in no particular order, and with comments in italic:
The appletviewer is faster because it doesn't have to deal with the execution overhead of a the browser.
The principal execution-time difference between running an applet in a browser & using appletviewer is the appletviewer is faster - it runs the Java code directly.1
1: It's not clear what “runs the Java code directly” means, whether it means “executes Java directly without translation to bytecode” or perhaps “translates Java to native code”, but in any case, both the appletviewer and plug-in run JVMs and interpret bytecode.
When using appletviewer you aren't able to use certain aspects of the applet such as buttons.2 Only in a browser do you get full functionality.
2: HTML buttons presumably, rather than Java GUI buttons.
The main difference is that applet viewer is part of the JVM, and is written by Sun, whereas your Browser is running a plug-in3 which then passes the instructions to the JVM.4 appletviewer should be faster. Also with applet viewer, there will be a no chance that an interaction with the browser could cause your program to behave differently.
3: Also written by Sun, unless you've replaced the plug-in.
4: The plug-in is a JVM; no need to pass bytecode elsewhere.
Using the applet viewer, it will only show the applet. For example, you cannot click on links. When an applet is running in a browser, you are able to click on links. To see how an applet works with the Internet, you must run it in a browser.
An applet in a browser is embedded in HTML and can only be accessed in that way.5 Using an appletviewer allows that program to run independently of any extra cost.
5: True, but that's also true of the appletviewer, although the HTML can be faked (see p. 519 in the text).
Since an applet runs in a broswer it6 uses the JVM and alows it7 to run better (more effectively). Because applets are made to run in browsers they perform better8 this way. But with an applet viewer it’s9 no longer in the environment it was designed for.
6: Which it: the applet or the browser?
7: Which it: the applet, the browser, or the JVM?
8: Better how: faster execution, or with more features, or both? Or something else?
9: Which it: the applet, the browser, the JVM, or the applet viewer?
for (String s: args) { ... }
could cause a compilation
error. Give two ways to fix the error if it occurs.
This is an example of the Iterable
interface, used to provide
more abstract sequential access.
for (i = 0; i < args.length; i++) {...}
.
p. 22
The answers, approximately verbatim, in no particular order, and with comments in italic:
The type String
should have a lower lowercase s1 and
“args
” should be followed by a set of brackets
[]
.2
1: Initial-cap for classes is a convention; the compiler won't choke if it's not followed.
2: Empty brackets are used in type or variable declarations; here
args
is being used as a value.
If a compilation error occurs a debugger could be used to find out the problem & correct it.3
3: True, but correct it how?
You could declare the string first, then try to initialize it with
variables such as String s; s = args;
4 or declare String as a
static, so that when you try to initialize it, the compiler is
ready.5
4: Does this match the context in which the problem occurred? That is, within a for statement?
5: You're getting colder.
If the “String” is typed “string” (lowercase s) this could cause a problem.6 All classes in Java are case sensitive.7 The first letter must be capitalized. Also, the class may not be found.8 If this is the case, check the classpath environment.9 If it set, unset it.
6: Indeed it could, but is that the case here?
7: All names in Java are case sensitive. There aren't too many contexts in which it makes sense to say that classes are case sensitive.
8: Possible but unlikely; String
is a basic part of java.lang
.
If the compiler can't find java.lang
, there's more serious problems around
than just a for statement.
9: java.lang
classes are basic enough to be accessible without
the classpath.
1. add “[]
” after args
& delete “s:
”
(String args[]
).10 I don't know. I'm assuming String s: args
is C++.11
Guess #2: Change line to (String [] args)
.12
10: That's a valid declaration for args
, but that's not what's going
on here.
11: Is that what the problem says?
12: This is the same as the first answer; in declarations array brackets may appear after the type or the variable.
13: Always answer every question. Writing almost any answer will score some points; writing nothing can only score 0.
This page last modified on 2 February 2009. |