Running Applications from the Command Line Flashcards
To compile a program from the command line you need to use the
j_______ command to compile a source file and the
j_______ command to run the program.
javac
java
Instructions
1) Write your program in the n________.
2) Save your program on the desktop.
You must use the class name, e.g. HelloWorld
followed by .java (this is the Java f____ e___________)
HelloWorld.java
3) Open Command Prompt, change the address to Desktop. So, type:
cd Desktop
4) To compile your program to b______ code type:
javac HelloWorld.Java
5) To run your program type:
java HelloWorld
notepad
file extension
byte
Jar Files
JAR stands for J_____ AR_____
A JAR file has the extension .jar and is simply a c________________ file.
A JAR file is used for aggregating many files into one.
.Jar is the only format that handles audio and image files as well as c______ files
Jar ARchive
compressed file (like a zip Folder)
class
How to create JAR Files
Most IDEs provide a means of creating JAR files but JAR files can also be created from the c________ p__________ with the jar.exe tool.
command prompt
Try and Catch
The ‘try’ statement allows you to define a block of code to be tested for errors while it is being e___________.
The catch statement allows you to define a block of code to be executed if an e______ occurs in the try block.
The try and catch keywords come in pairs:
executed
error
Try and Catch
What happens to the program if try and catch, catches an error?
It will not shut down.
Try and Catch - Example of Catching an Exception
e.g.
try {
int myInt = Integer.parseInt(“pants”);
System.ou.println(myInt);
}
catch (NumberFormatException) {
System.out,println(“You can’t parse ‘pants’ as an integer!”)
}
Notice the ‘NumberFormatException’.
a) What type of exception will this catch?
b) Will it catch other types of exceptions?
C) What do we use to catch every type of exception?
a) A number format exception
b) No
c) Exception e
Try and Catch - Note
You only want to catch e____________, you don’t want to catch errors.
You will learn more about this later, but for now don’t ever:
catch (Exception t) XXXXXXXXXXXXXXXXXXXXXXX Wrong!!!!!
exceptions