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
What is the order of instance initialization?
- Fields and instance initializers ({}) are initialed in order they appear in class
- Constructor is initialized after them
When are static initializers being run?
When class is first loaded
When are instance initializers being run?
When new class instance is being defined
What are Java primitives?
boolean
byte
short
char
int
long
float
double
What two primitives are similar?
char and short, both 16 bit
How do we call numbers in Java?
Literals
What are signed and unsigned primitives?
Those primitives that go from negative number to positive number (as range)
How do we parse a primitive?
eg. parseInt() etc.
How do we return wrapping class from primitive?
with “valueOf()” method
How can primitives also be written?
- hexadecimal
- octal
- binary
How do we write binary literals?
0b0101
0B1010
How do we write hexadecimal literals?
0xF23
How do we write octal literals?
012
053
032
java.lang package
Doesnt need import, it is auto. imported