Building Blocks Flashcards
Java compile command?
javac
What is compiler command for setting the compile output directory?
-d
How does typical compile command look like? What are its parts?
- -d for output directory
- name of class we compile or package path to class or package path with * for all classes in that package
- -cp or -classpath or –class-path for dependency folder or folder where is application built
How to set classpath location while using compiler command and all its variants?
-cp
-classpath
–class-path
How to run Java application using CLI?
java
What do you need to provide “java” command to run Java application?
Package path to class that has main method we want to run, and complete classpath
How do text block look like?
”””
text block”””
Note: it needs to have first line below opening quotes!
In text blocks, how do we request a new line in output?
\n
In text blocks, how do we request not to add a new line?
\
In text blocks, how do we escape characters?
\ and some character
eg. "
In text blocks, how do we request two spaces in output?
\s
What is command to JAR a Java application?
jar
How do we choose dependency folder while using “jar” command?
-c
How do we JAR a Java application?
jar -cvf JarName.jar -c dependency/folder .
What is alternative to “-cvf”
–create –verbose –file
What do we need to watch out when using imports?
We need to look for imports with the same name
What are rules when using wildcard * in imports?
- can only import classes, not subpackages.
When specific import is defined, it trumps wildcard.
What are rules when naming identifiers?
- Name cannot start with numbers
- Symbols at start can only be $ or _
- _ cannot be used as name
- Reserved keyword cannot be used as name
What are rules for local variables?
They must be initiated before use
Where can “var” be used?
Only with local variables
What is rule when using “var”?
Its value must be set in the same line as var, not later
Is “var” reserved keyword?
No, it can be used as identifier - var var = new Var();
public int addition(var a, var b)?
var cannot be used as parameter as parameters are not local variables
What is rule for initialization of variables in same line?
Only one variable type can be defined per line - int a, b, c = 5