Lecture 25
Java Beyond DrJava Announcements for This Lecture
This Week Next Week
• Reading: Chapter 16 • Submit a course evaluation • Assignment A6 graded . Will get an e-mail for this . Mean: 86.8, Median: 90 . Part of the “participation . Mean: 10.5h, Median: 10h grade” (e.g. clicker grade) th • No new lab this week • Final, May 10 9:00-11:30 . Review posted later this week . Turn in lab from last week . Work on assignment A7 • Conflict with Final Exam? . e.g. > 2 finals in 24 hours • Assignment A7 due Saturday . Submit conflicts on CMS Announcements for This Lecture
This Week Next Week
• Reading: Chapter 16 • SubmitReview asessions course nextevaluation week • Assignment A6 graded . WillStill lining get an up e-mail times for this . Mean: 86.8, Median: 90 . Part3 sessions/day of the “participation in 1 hour slots . Mean: 10.5h, Median: 10h . Monday,grade” (e.g. Tuesday clicker 1-4 grade) . Either Sundayth or Wednesday • No new lab this week • Final, May 10 9:00-11:30 • Topics. Review posted posted Thursday later this week . Turn in lab from last week . Work on assignment A7 • Conflict with Final Exam? . e.g. > 2 finals in 24 hours • Assignment A7 due Saturday . Submit conflicts on CMS Steganography Observation message • Most you preferred end /** terminates markers to using length … • But few cons to length * Format: ## message ## . Only requires two pixels */ (e.g. <= 999,999) public ImageProcessor { . Hard part: conversion … • Markers okay if not printable } . Non-printable chars: <= 32 . Or 3-digits numbers > 255 • Bad if marker is in message Tried to “hide” your source code . reveal will terminate early
05/01/12 Beyond DrJava 4 Java Outside the Interactions Pane
• Every Java program is either an application or an applet. public class C { • Application: class with a … special static method (main) public static void main(String[] args) { • Run the application by // top method to invoke invoking this method … . Interactions pane } . OS command line … . Double-clicking on it? }
The parameter, an array of Strings, is used to pass information to the program
05/01/12 Beyond DrJava 5 Executing Java from Command Line
Java Code Command Line public class C { > cd
Can type in Interactions page
05/01/12 Beyond DrJava 6 “Simplest” Java Application public class Simple { public static void main(String[] args) { System.out.println(“Hello World”) } }
Execute with “java Simple”
05/01/12 Beyond DrJava 7 Writing a Java Application: Classic Way
edits the javac C.java .java file
Text Editor Command Line
java C
Command Line
05/01/12 Beyond DrJava 8 Applications: A Slightly Harder Way
Eclipse IDE The standard Java IDE :
05/01/12 Beyond DrJava 9 To Use an IDE or Not?
Advantages Disadvantages
• Organize all your classes • Overwhelming! . MVC needs multiple classes . Organize them as a “Project” • Auto-generated code . GUI design . API auto-completion • Sometimes you just want a • Interactive debugging single, simple class . Breakpoints . No Projects . Variable watches . No “workspaces”
05/01/12 Beyond DrJava 10 Java JAR Files
• Goal: “double-clickable” app • JAR: Java Archive File . Compressed file collection . Similar to a ZIP file . Except it can be executed • Jar files contain • manifest: noun . All the necessary class files . list of passengers . Any image or sound files . invoice of cargo . Any other necessary files • Identifies the class with main . A manifest file . Might have more than one
05/01/12 Beyond DrJava 11 Executing a Java File
• Double-click it! • Command line
• Supported in most OSs • Type: . But error if no manifest java -jar
05/01/12 Beyond DrJava 12 Creating a JAR File
1. Navigate to the directory that contains the .class files. 2. Create a text file x.mf with one line (ending in a line-feed): Main-class:
Create anything else? Manifest name of name of file expands to name manifest file to create all the .class files File
05/01/12 Beyond DrJava 13 Inspecting JAR File Contents
• List files in a Jar file: > jar tf acm.jar acm/graphics/ jar -tf images.jar acm/graphics/G3DRect.class acm/graphics/ArcRenderer.class acm/graphics/GArc.class acm/graphics/GMouseEvent.class File acm/graphics/GCanvasListener.class type (list) acm/graphics/GCanvas.class name of the acm/graphics/GCompound.class jar file acm/graphics/GIterator.class acm/graphics/GContainer.class acm/graphics/GDimension.class acm/graphics/GFillable.class …
05/01/12 Beyond DrJava 14 Applets vs. Applications public class C { • Applet: Java program public static void main(String[] args) { run in a web browser …} . Needs an html page } application import javax.swing.*; Four inherited procedures: public class A extends JApplet { • called to initialize public void init() { … } • called to start processing public void start() { …} • called to stop processing public void stop() { … } public void destroy() { … } • called to destroy resources (just before killing the applet) } applet
05/01/12 Beyond DrJava 15 TemperatureConverter Example
Application Latest Version Applet can be both!
private void initAsApplication() { JFrame frame = public void init() { new JFrame("Temperature Converter"); getContentPane().add(view); frame.setDefaultCloseOperation( } JFrame.EXIT_ON_CLOSE ); frame.getContentPane().add(view); public void start() { /* Do nothing */ } frame.pack(); public void stop() { /* Do nothing */ } frame.setVisible(true); } public void destroy() { /* Do nothing */ }
05/01/12 Beyond DrJava 16 An Applet HTML Page
tags
This is an Applet!