Bookmark and Share

Front Back
What is the basic structure of a command line call to the java compiler
javac [options] [source files] Both ""options"" and ""source files"" are optional and allow many entries
What is the -d option when compiling?
javac -d classes -d lets you tell compiler in which directory to put .class files. By default .class files are put in same directory as the .java files.
What happens if the destination directory used with the compiler's -d flag doesn't exist?
Compiler error. Only directories referenced in the package statement will be automatically built.
What is the basic structure of a command line call to the java application launcher?
java [options] class [args] Many options and args are allowed. There must be 1 and only 1 class file. Java assumes you're talking about .class file so don't include extension
How do you specify multiple class files to the application launcher?
You don't. Java app launcher requires exactly 1 class file
How do you alert the java application launcher to required classes in other libraries?
-cp -classpath (both these flags are the same)
How do you set and send a java applcation a system propery (not a mere argument)?
-DmyProp=""this is my value"" NOTE: NO SPACE AFTER -D NOTE: Quotes are required if the value of the property has spaces. Otherwise quotes not needed. These quotes are not part of the value. The value is interpreted as a String Example of how an app would then access: Properties p = System.getProperties(); p.list(System.out); You'd see all system properties including the following: myProp=this is my value
How do you manipulate system properties inside an application?
Properties p = System.getProperties(); getProperty(String key) getProperty(String key String defaulValueIfDoesntExist); setProperty(String key String newValue) p.list(stream)
What's the difference? static public void main (String[] args) static public void main (String... args)
No difference.
What are the 2 ways a classpath can be declared?
1) As an operating system environmental variable. This becomes the DEFAULT classpath value -- it will be overridder by any command line declaration of a classpath 2) On the command line. This overrides any os environmental classpath variable declared.
What does the java virtual machine need to be able to do that the java compiler did?
Find all of the same classes.
How does java & javac look for directories?
They use the same algorithm: * Look through a list of directories for class * Stop after first one you find * Place #1 - look in directories that contain the classes that come standard with J2SE * Place #2 - look in directories defined in classpaths
How do you include multiple directories in a -classpath option?
Use colon (:) (Windows uses semicolon separators and it's directories use backslaches rather than forward slashes)
Is -cp a guaranteed alias for -classpath?
No. Most allow but some systems may only allow -classpath.
What does ""jar"" stand for in a java jar file?
Java ARchive (java's version of zip - it compresses and archives)
What 2 kinds of things can you include in a -classpath?
Dirtories and jar files.
Are you allowed to add your own class files and jar files to the directory where java keeps it's classes for J2SE? Will compiler see these classes?
Yes and yes. Both the virtual machine and compiler will find in the directory below: jre/lib/ext
What are static imports?
Use when you want to use a class's static members. import static java.lang.Integer.* NOTE: Use keyword static immediately after import NOTE: Idea is that you're not bringing in shortcut for a class but for a class's static members. EXAMPLES: (Create alias for just a class - programmer can now just type Integer instead of java.lang.Integer) import java.lang.*; import java.lang.Integer; (Create alias for static members inside a class - programmer can now just type MAX_VALUE instead of Integer.MAX_VALUE or java.lang.Integer.MAX_VALUE) import java.lang.Integer.*; import java.lang.Integer.MAX_VALUE;
What's the difference? static import ... import static ...
Big difference. import static creates alias for static members of a class static import causes an compiler error.
x of y cards