DOC PREVIEW
Duke CPS 108 - Applets and Applications

This preview shows page 1-2-3-4-5 out of 16 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Software Design15.1Applets and Applicationsz Application run by user, double-clickable/command-line¾ No restrictions on access, reads files, URLS, …¾ GUI applications typically include a JFrame• Has title, menus, closeable, resizeablez Applet is downloaded via the web¾ Runs in browser, not trusted (but see policy later)¾ Can't read files on local machine (but see policy)¾ Can't be resized within browser¾ Uses jar file to get all classes at once• Alternative? Establish several connections to serverSoftware Design15.2Developing Applets and Applicationsz Create a JPanel with the guts of the GUI/logic¾ What will be in the content pane of both deployments¾ Makes GUI very simple, see code examples¾ Use JPanel in both Applet and Applicationz Test with application first, easier to read files/resources¾ Migrate to Applet, test first with appletviewer¾ Migrate to web, may need to clear cache/reloadz Ideally first cleanly into OOGA architecture¾ Gui isn't the view, what about interfaces?Software Design15.3Packages, JAR files, deploymenthttp://java.sun.com/docs/books/tutorial/jar/basics/index.htmlz Java packages correspond semantically to modules (related classes) and syntactically to a directory structure¾ Class names correspond to file names¾ Package names correspond to directories¾ Related classes belong together, easier to develop, easier to deploy¾ Leverage default/package access, use properties of protected which is subclass and package accessSoftware Design15.4Packages, javac, java, javadocz In moderately big programs packages are essential¾ Can’t easily live in a directory with 50 .java files¾ Can’t easily co-exist in such a directory¾ Harder to use tools like Make and Antz Each of javac, java, javadoc is slightly different with packages, all must co-exist with CLASSPATH¾ File system vs. compiler vs. runtime¾ Source of confusion and problems¾ IDEs can manage Make/CLASSPATH issuesSoftware Design15.5CLASSPATH and related conceptsz The default CLASSPATH is . current directory¾ Works fine with default/unnamed packages¾ Will not work with named packagesz Set CLASSPATH to directory in which packages live also include current dir¾ setenv CLASSPATH "~ola:."¾ setenv CLASSPATH "`pwd`:."¾ On windows machines change registry variable, separator is semi-colon rather than colonz All problems are CLASSPATH problemsSoftware Design15.6More package detailsz To compile¾ Can cd into directory and type javac *.java¾ Can also type javac ooga/*.java from one level up¾ If CLASSPATH isn't set, the second won't workz To run¾ java ooga.TicTac will work, you must specify the "real" name of the class being used.¾ Reading files requires full-paths or run from directory in which file livesz To document¾ http://java.sun.com/j2se/javadoc/faq.html¾ Don't need to use –sourcepath, but can¾ javadoc –d doc ooga ooga.timer ooga.game …Software Design15.7javadoc for packagesz See the javadoc faq http://java.sun.com/j2se/javadoc/faq.html¾ For each package create a package.html file• Not in /** */ javadoc format, strictly html• First sentence after <body> is main description; a sentence ends with a period.• The package.html file should provide complete instructions on how to use the package. All programmer documentation should be accessible or part of this file, e.g., in the file or linked to the file¾ Use the {@link foo.bar bar} tag appropriately.• See the FAQ, or the source for the elan package onlinez You may want to keep .java and .class files separate, see sourcepath and classpath as commandline args to javaSoftware Design15.8From JITs to Deoptimizationz JITs compile bytecodes when first executed¾ If we can cache translated code we can avoid re-translating the same bytecode sequence¾ Spend time compiling things that aren’t frequently executed (optimistic optimization?)¾ Errors indicate “compiled code” rather than line numberz Sun’s HotSpot VM uses a different strategy for performance¾ Adaptive compilation: save time over JIT, compile “hotspots” rather than everything, uses less memory, starts program faster, http://java.sun.com/products/hotspot/¾ No method inlining, but uses dynamic deoptimization• Program loads new subclass, compiled code invalid, so …?z What does the class loader do?Software Design15.9Loading .class filesz The bytecode verifier “proves theorems” about the bytecodes being loaded into the JVM¾ These bytecodes may come from a non-Java source, e.g., compile Ada into bytecodes (why?)z This verification is a static analysis of properties such as:¾ .class file format (including magic number 0xCAFEBABE)¾ Methods/instances used properly, parameters correct¾ Stack doesn’t underflow/overflowz Verification is done by the JVM, not changeable¾ Contrast ClassLoader, which is changeable, can modify classes before they’re loaded into the JVMhttp://securingjava.comhttp://java.sun.com/sfaq/verifier.htmlSoftware Design15.10The ClassLoaderz The “boot strap” loader is built-in to the JVM¾ Sometimes called the “default” loader, but it’s not extensible or customizable the way other loaders are¾ Loads classes from the platform on which the JVM runs (what are loader and JVM written in?)z Applet class loader, RMI class loader, user loaders¾ Load .class files from URLs, from other areas of platform on which JVM runs¾ A class knows how it was loaded and new instances will use the same loaderz Why implement a custom loader?¾ Work at Duke with JOIESoftware Design15.11Applications and Appletsz An applet is a program delivered via the web¾ security issues, sandbox model¾ where does code/images/etc come from? How is it delivered?¾ what browsers support JDK1.2 out-of-the box?¾ Use IE/Netscape with plugin, use Opera as is, use appletviewer for debugging, testingz Possible to wrap up lots of classes in a .jar file¾ java archive, similar to a tar file, possible to include .class files, .au, .gif, etc, so all code transferred at onceSoftware Design15.12Running an Appletz An applet has an init() method¾ similar to constructor, called only once, when the applet is first loadedz An applet has a start() method¾ called each time the applet becomes “active”, run the first time, or revisited e.g., via the back button in a browserz An applet has a stop() method¾ called when applet is invisible, e.g., user scrolls or goes to another web pagez other methods in an applet¾ destroy, getAppletInfo, getParameterInfoz Applet


View Full Document

Duke CPS 108 - Applets and Applications

Download Applets and Applications
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Applets and Applications and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Applets and Applications 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?