Skip to content

lessons

Miguel Gamboa edited this page Mar 12, 2024 · 41 revisions

Lessons:


  • Bibliography and Lecturing methodology: github and slack.
  • Tools: javac, javap, kotlinc, JDK 17 and gradle.
  • Program outline in 3 parts:
    1. Java Type System and Reflection;
    2. Metaprogramming and Performance;
    3. Lazy processing.
  • Project in 3 parts according to program outline.
  • Managed Runtime or Execution Environment or informally virtual machine (VM) or runtime.
  • Execution Environment includes:
    • Compiler,
    • Programming languages,
    • Standard libraries,
    • Dependency manager (e.g. gradle, maven)
    • Central Repository (e.g. Maven Central Repository, Nuget, NPM, etc)
  • Examples of languages targeting JVM: Java, kotlin, Scala, Clojure.
  • Examples of languages targeting Node: JavaScript, TypeScript, Kotlin.
  • JVM runs .class files with bytecode
  • JVM translates bytecode to machine code (e.g. IA-32, AMD64, etc depending of the CPU)
  • In Javascript ecosystem modules are deployed in source code i.e. Javascript.
  • Distinguish between Programming Language <versus> VM
  • One file .class for each class definition
  • Metadata:
    • data that provides information about other data
    • In a .class the metadata provides a description and structure of a Type.
  • Using javap -c -p AppKt.class to inspect metadata and bytecode definition of class AppKt
  • CLASSPATH
    • e.g. -cp . - local folder
    • e.g. -cp '.:~/JetBrains/IntelliJIdea2022.2/plugins/Kotlin/lib/*'
    • (for windows use ; rather than :)

  • Type System - Set of rules and principles that specify how types are defined and behave.
  • Two kinds of types: Primitive and Reference types.
  • Classes have Members
  • Members may be: Fields or Methods.
  • There are NO properties in Java Type System.
  • Using javap -p Person.class to inspect metadata
  • The fully qualified name of a class includes its package name.
  • Constructor is a method with the name <init> returning void.
  • Member access syntax: Receiver.Member.
  • The Receiver is the target of the member access and it is a Type (for static members) or an Object (for non-static/instance members).
  • JOL - Java Object Layout:
    • java -cp .;jol-cli-0.17-full.jar org.openjdk.jol.Main estimates <classqualifiedname>
    • (linux replace ; by : on -cp (classpath))
  • Object header = mark word (used for hash, locks, GC, etc) + class word (class-specific metadata).
  • Fields alignment, reorder and padding gap.
  • Static initializer: initializes static fields.
  • Immutable values:
    • constant value calculated at compile time, e.g. Kotlin const
    • immutable, yet dynamically initializable
  • Boxing and Unboxing.
  • Boxing : <Wrapper>.valueOf(value)
    1. Heap allocation
    2. Object header initialization
    3. Copy value
  • Unboxing: <Wrapper Instance>.<primitive>Value(), e.g. nr.intValue()
  • Nested classes.
  • Inner classes: non-static in Java or inner in Kotlin.
  • Abstract classes cannot be directly instantiated.
  • Interfaces represent abstract types that cannot be instantiated too.
  • Override
  • Names collision and Member access ambiguity
  • Methods call resolution: Fields, Methods, and Virtual Methods.
  • Anonymous Classes in Java
  • Object Expressions in Kotlin
  • Resulting types from compilation
  • Homework 2 - virtual and non-virtual methods.
  • Kotlin Class Members
  • Analyzing Kotin properties in JVM.
  • There are NO properties in Java Type System.
  • A Kotlin property may generate:
    • Backing field
    • Getter, i.e. function get... -- called with invoke... bytecode.
    • Setter, i.e. function set... (if defined with var).
  • Top-level declarations
  • Extension functions
  • Singleton design pattern
  • object keyword:
    • private constructor
    • Singleton instance in static INSTANCE field;
  • companion object - specific type of object declaration associated with its owner class.
  • Reflection object oriented API for metadata
  • Kotlin Reflection API (kotlin.reflect): KClass, KCallable ----->* KFunction
  • KClass is representing a type in Kotlin.
  • KCallable base type of KFunction and KProperty
  • KProperty and KMutableProperty
  • KCallable ----->* KParameter
  • KFunction properties: name, type, parameters and instanceParameter.
  • KParameter property kind: INSTANCE versus EXTENSION_RECEIVER
  • KParameter property isOptional
  • KClass::createInstance()
  • KFunction::call()
Clone this wiki locally