Download presentation
Presentation is loading. Please wait.
Published byVeronica Booker Modified over 8 years ago
1
Computation as an Expressive Medium Lab 9: Java Mode, External Code, and.JAR signing Jason Alderman
2
You are going to be sick of me. Adding external code! Adding external code! Squirreled-away java-mode tips! Squirreled-away java-mode tips!.jar signing – not just for pottery celebrities anymore!.jar signing – not just for pottery celebrities anymore! Review of the code you didn't finish! Review of the code you didn't finish!
3
Hold up—what the heck is a.JAR? A.JAR file is a java applet. A.JAR file is a java applet. When you write a sketch in processing… When you write a sketch in processing… …it gets converted to a full-up.java file …it gets converted to a full-up.java file (See this in the Applet folder! Read it! Ponder!) (See this in the Applet folder! Read it! Ponder!) the.java file gets compiled into a.class the.java file gets compiled into a.class the.class gets compressed into a.jar the.class gets compressed into a.jar In fact, if you change the extension from.jar to.zip, you can unzip it and see the original.class!! In fact, if you change the extension from.jar to.zip, you can unzip it and see the original.class!!
4
Let's add us some external code You've just downloaded a java library off the amazing INTARWEB! You've just downloaded a java library off the amazing INTARWEB! toastmaker.jar toastmaker.jar You can do two things: You can do two things: Put it in Put it in …or, put it into (which, like files in data, gets exported) …or, put it into (which, like files in data, gets exported) processing-0091/libraries/toastmaker/library/toastmaker.jar /code/toastmaker.jar /code/toastmaker.jar
5
Adding (uncompiled) external code See that arrow on the left? See that arrow on the left? Click it, and choose Add Tab… Click it, and choose Add Tab… Give the new file a name and it adds another.pde in your sketch folder Give the new file a name and it adds another.pde in your sketch folder …or end the name with.java and it will add a full-up.java file in your sketch folder …or end the name with.java and it will add a full-up.java file in your sketch folder (Useful for when you have an uncompiled.java class that you want to add to your project!) (Useful for when you have an uncompiled.java class that you want to add to your project!)
6
Java-mode gotchas! First of all, as you've found, you don't need to go into java mode to use the import statement First of all, as you've found, you don't need to go into java mode to use the import statement If you do decide to use java mode, you have to write If you do decide to use java mode, you have to write public class Something extends PApplet { … public class Something extends PApplet { … This public is important! And it is ONLY necessary on the the class … extends PApplet This public is important! And it is ONLY necessary on the the class … extends PApplet
7
More Java-Mode Gotchas public class happy extends PApplet { // global vars void setup(){ … } void draw(){ … } void othermethod(){ … } class something{ … } } class somethingelse { // fields somethingelse(){ … } void method(){ … } void totallyawesome(){ … } } happy.pde somethingelse.pde The class code in somethingelse.pde The class code in somethingelse.pde Gets added to the end of the code inside public class happy before compiling Gets added to the end of the code inside public class happy before compiling Does NOT have a public in front of the class, that is, it's just plain class somethingelse { Does NOT have a public in front of the class, that is, it's just plain class somethingelse {
8
Even More Java-Mode Gotchas public class happy extends PApplet { // global vars yetanother varname; void setup(){ … } void draw(){ … } class something{ … } } public class yetanother { // fields public static void main blah blah… } happy.pde yetanother.java The class code in yetanother.java The class code in yetanother.java Can be any standard java.java file, pretty much Can be any standard java.java file, pretty much Can have public wherever the heck it wants it… (not true, but you get the picture) Can have public wherever the heck it wants it… (not true, but you get the picture)
9
Using Web crawling on Courseware So…now you've seen that the code in the Processing window extends PApplet. You can view Applets on the web, which is why they work (usually) seamlessly with the Courseware. So…now you've seen that the code in the Processing window extends PApplet. You can view Applets on the web, which is why they work (usually) seamlessly with the Courseware. HOWEVER, browsers have security problems when a Java applet tries to access other files at different sites. HOWEVER, browsers have security problems when a Java applet tries to access other files at different sites.
10
Using Web crawling on Courseware For instance, this call works both in Processing and on the Courseware (provided image1.jpg is in your data directory): For instance, this call works both in Processing and on the Courseware (provided image1.jpg is in your data directory): PImage im = loadImage(“image1.jpg”); PImage im = loadImage(“image1.jpg”); But this call works only in the Processing program, not online: But this call works only in the Processing program, not online: PImage im = loadImage(“http://idt.gatech.edu/~mateas/image1.jpg”); PImage im = loadImage(“http://idt.gatech.edu/~mateas/image1.jpg”);
11
Signing your jar file To allow browsers to control the security of your applet, you must sign it first. To allow browsers to control the security of your applet, you must sign it first. Two steps: Two steps: Create a keystore file. Create a keystore file. Sign your jar file. Sign your jar file. Before you can do this, you must either: Before you can do this, you must either: upload your jar file to your Steel account. upload your jar file to your Steel account. For the following commands, use a shell prompt. For the following commands, use a shell prompt. install the Java SDK on your machine. install the Java SDK on your machine. get to a command line in the directory of your jar. get to a command line in the directory of your jar.
12
Signing your jar file Create a keystore file. Run the following command: Create a keystore file. Run the following command: keytool -genkey -alias -keystore keytool -genkey -alias -keystore The “-keystore ” part is optional. It allows you to specify where the.keystore file will go. If you don’t specify, it will place it in your default system path. This should be fine for most applications. The “-keystore ” part is optional. It allows you to specify where the.keystore file will go. If you don’t specify, it will place it in your default system path. This should be fine for most applications. * Just substitute with a name for your key that you're generating…
13
Signing your jar file After you run keytool, it will prompt you for some things: After you run keytool, it will prompt you for some things: keystore password: this is used when signing your jars. keystore password: this is used when signing your jars. Name, Organizational Unit, blah blah: not very important, just provides viewers information on who they’re trusting. Name, Organizational Unit, blah blah: not very important, just provides viewers information on who they’re trusting. key password: also used when signing your jars. Not a problem to make it the same as the keystore password. key password: also used when signing your jars. Not a problem to make it the same as the keystore password.
14
Signing your jar file Sign your jar file. Run the following command: Sign your jar file. Run the following command: jarsigner -keystore jarsigner -keystore is just the file name of the jar. is just the file name of the jar. just needs to match the alias you used for the keystore. just needs to match the alias you used for the keystore. -keystore is also optional. The default will be the same location as keytool. -keystore is also optional. The default will be the same location as keytool. You will be prompted for your keystore password. You will be prompted for your keystore password.
15
Viewing the jar file The jar file is signed! Upload it to the courseware like you would normally. The jar file is signed! Upload it to the courseware like you would normally. When anyone loads the applet, a window will come up asking if they accept the certificate. Just click “Yes”, and the applet will load. When anyone loads the applet, a window will come up asking if they accept the certificate. Just click “Yes”, and the applet will load.
16
Unca' Mayhew's Debugging Tips Stack Trace: The indecipherable lines of red that pop up when an error occurs. Stack Trace: The indecipherable lines of red that pop up when an error occurs. This shows what methods were running in what classes when the program broke, as well as the line numbers in their java files. This shows what methods were running in what classes when the program broke, as well as the line numbers in their java files.
17
Unca' Mayhew's Debugging Tips Common errors, and what they mean: Common errors, and what they mean: ArrayOutOfBoundsException ArrayOutOfBoundsException You are trying to access an index in an array that doesn’t have that index. For example, thisArray[-1] or thisArray[6] in an array with length 6 (max index of 5). Check to make sure any for loops have the right conditions. You are trying to access an index in an array that doesn’t have that index. For example, thisArray[-1] or thisArray[6] in an array with length 6 (max index of 5). Check to make sure any for loops have the right conditions.
18
Unca' Mayhew's Debugging Tips Common errors, and what they mean: Common errors, and what they mean: NullPointerException NullPointerException You are trying to access an object that hasn’t been initialized, or is set to null. Remember that in addition to declaring a variable (telling the program this variable exists, has this type, and this name), you must initialize the variable (give it a value or point it at an object). You are trying to access an object that hasn’t been initialized, or is set to null. Remember that in addition to declaring a variable (telling the program this variable exists, has this type, and this name), you must initialize the variable (give it a value or point it at an object). String myString; // declares String variable. String myString; // declares String variable. myString = new String(); // sets variable to point to a String object. myString = new String(); // sets variable to point to a String object.
19
Unca' Mayhew's Debugging Tips Split up tasks into smaller methods. Processing will tell you which method the error occurred in, so the smaller they are, the closer you can pinpoint it. Split up tasks into smaller methods. Processing will tell you which method the error occurred in, so the smaller they are, the closer you can pinpoint it. Processing also gives you a line number. Not as useful when it doesn’t give you a way to scroll to that line, but you can copy and paste your code into another editor (NetBeans, even Dreamweaver) that does have a “go to line” function. Processing also gives you a line number. Not as useful when it doesn’t give you a way to scroll to that line, but you can copy and paste your code into another editor (NetBeans, even Dreamweaver) that does have a “go to line” function.
20
Unca' Mayhew's Debugging Tips Use “println” intelligently to try and figure out what’s wrong. You can use this to keep track of what variables are at different points in the program, or even just to tell you what methods the program is going into. Doing this can help give a sense as to the flow of what is happening in the program. Use “println” intelligently to try and figure out what’s wrong. You can use this to keep track of what variables are at different points in the program, or even just to tell you what methods the program is going into. Doing this can help give a sense as to the flow of what is happening in the program.
21
End of Slides Fun with htmlparser… Fun with htmlparser…
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.