1/12
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
JDK components
Java development kit - javac - compiler, java - runs bytecode on JVM, javadoc - generates documentation, jar - packages Java applications.
method signiture
A method signature consists of the method's name and its parameter list(only the parameter types count, not the parameter names), which defines how the method can be called.
classpath
Tells the JVM where to look for classes and packages. The paths are on the local machine.
Instance initializer
Code block without method name, runs before constructor.
Object vs reference
Object - the actual values stored in the heap, can be accessed only through the reference. Reference - the variable that can be used to access the object - stores the address of the object
inboxing vs unboxing
inboxing: primitive → object, can parse string; unboxing: obj → primitive; e. g. Double obj = Double.valueOf(“2”); double primitive = obj.doubleValue(); // now java can make the cast implicitly: autoboxing, autounboxing
What kind of variables are initialized automatically?
Instance and class variables are initialized by default value.
Numeric promotion rule
When we use binary arithmetic operators(+,-, *, /, %) → smaller data types will be promoted to lager data types (short→ int)
Switch case classic syntax vs new syntax
switch(value) {
case v1:
//code
break;
default:
//code
}
String dayName = switch (day) {
case 1 -> "Monday"; // simple expression
case 2 -> { // block with multiple statements
System.out.println("It's Tuesday!");
yield "Tuesday"; // yield returns the value for this case
}
case 3 -> "Wednesday";
default -> "Other day";
};
for each enhanced loop syntax
for (ElementType element : collection) {
// use element, but cannot modify collection, element is a copy;
}
varargs
variable arguments; notation: arg…; It must be only one vararg parameter, and it must be the last parameter in the param. list. - the function can be called with empty paranthesis or with null: func(), func(null);
Maven project structure, what happens after compilation, how to reach a resource?
the compiled java files go to target/build, with the package structure(after the java package);
the resource folders contents go directly into target/build
reach resource(from compiled code): var stream = CurrentClass.class.getClassLoader().getResourceAsStream(‘filename‘);
classloader always looks for absolute path from the target/build
CurrentClass.class.getResourceAsStream(‘/filename‘); - i need to add the ‘/’ to look from target/build, or else it will search inside the package the class is
What is classloader?
locates classes/resources
gives back stream to process resource
loads class by reading it and creating a class object in memory.
the class object contains data about the class structure itself
Class <MyClass> clazz = Myclass.class; → reflection