Skip to content

lessons

Luís Falcão edited this page Mar 11, 2024 · 6 revisions

Lessons:

23-02-2024 (G0.08)

  • 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

26-02-2024 (G0.08)

Programming Languages

  • Compiled vs non compiles programming languages
    • Compilation -> Transalation in compile time.
      • Translation occurs only once
    • Interpretation -> Translation/Interpretation at runtime
      • Translation occurs each time the program runs
  • The need for Virtual Machines
    • Reduce the number of needed compilers
    • Code portability

Java Virtual Machine

  • 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 :)

01-03-2024 (G0.08)

  • The fully qualified name of a class includes its package name.
  • In the JVM the types are always used with its full qualified name.
  • Distributing Java Programs
    • Jar file creation
    • Executable jar file creation including the main class fully qualified name in META-INF\MANIFEST.MF

04-03-2024 (G0.08)

  • 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 StudentPerson.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 -jar jol-cli.jar internals -cp ./build/classes pt.isel.SavingsAccount
    • (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.

  • Immutable values:

    • constant value calculated at compile time, e.g. Kotlin const
    • immutable, yet dynamically initializable

08-03-2024 (G0.08)

  • Class inheritance and interface implementation
  • Polymorphism / dynamic method dispatch
  • At runtime there are always to types to consider in a variable
    • The variable type - Can be any, including non-concrete types (e.g abstract classes and interfaces)
    • The underlying object type: must be of a compatible type
  • A type D is compatible with type B if:
    • D and B are the same type
    • D is a derived type from B
    • B is an interface and D is a type that extends or implements B
Clone this wiki locally