-
Notifications
You must be signed in to change notification settings - Fork 0
lessons
Miguel Gamboa edited this page Mar 2, 2023
·
28 revisions
Lessons:
- 01-03-2022 - Lesson 01 - Introduction and Modern VMs, e.g. JVM, Node
- ..-03-2022 - Lesson 02 - Kotlin and the Java Type System
- ..-03-2022 - Lesson 03 - Components and Metadata
- ..-03-2022 - Lesson 04 - Programming with Metadata
- Bibliography and Lecturing methodology: github and slack.
- Tools:
javac
,javap
,kotlinc
, JDK 17 and gradle. - Program outline in 3 parts:
- Java Type System and Reflection;
- Metaprogramming and Performance;
- Iterators versus Sequences (
yield
). Generics and Reified type parameters.
- Project in 3 parts according to program outline.
- Managed Runtime or Execution Environment.
- Informally virtual machine (VM) or runtime
- Historic evolution since Java to nowadays
- Examples of languages targeting JVM: Java, kotlin, Scala, Clojure.
- Examples of languages targeting Node: JavaScript, TypeScript, Kotlin.
- Java syntax similar to C and C++.
- Distinguish between Programming Language
<versus>
VM
- Managed Runtime:
- Software components = Metadata + IR (intermediate representation) (e.g. bytecodes)
- Portability - Compile once and run everywhere.
- Jitter - Just-in-time compiler
- Safety - NO invalid memory accesses
- GC - Garbage Collector.
- ClassLoader and CLASSPATH - dynamic and lazy load.
- CLASSPATH
- Interoperability Java <> Kotlin supported by JVM.
- Using
javap -c -p Point.class
to inspect metadata and bytecodes definition of data classPoint
- Kotlin properties
x
,y
andmodule
map to methodsgetX()
,getY()
andgetModule()
.
- Kotlin properties
- Type System - Set of rules and principles that specify how types are defined and behave.
-
Types are defined through Classes or Interfaces
- On JVM types are defined through Classes.
- Classes have Members.
- Members in JVM may be Fields or Functions (aka as methods).
- Members in Kotlin may be Properties or Functions.
- There are NO Properties at JVM level.
- A Kotlin property may generate:
- Backing field -- accessed with
getfield
bytecode. - Getter, i.e. function
get...
-- called withinvoke...
bytecode. - Setter, i.e. function
set...
(if defined withvar
).
- Backing field -- accessed with
- Kotlin
val
<=>
Javafinal
. -
Any
<=>
JavaObject
, which is the base class of all classes. - Implicit call to base constructor
...: Any()
:- bytecodes:
invokespecial Object.<init>()
- bytecodes:
-
new
in Java andnew
in bytecodes. -
new
is implicit in Kotlin.
-
Component - Reusable software unit, with:
- IR - code in intermediate representation (e.g. bytecodes, IL, other)
- Metadata - auto description
- Ready to use
=>
does not require static compilation. - API
=>
conforms to a public interface. - Indivisible
=>
1 module (file)
-
Software development by Components:
- Reduce Complexity;
- Promote Reuse.
- Developer roles:
- Provider - provides a component with a well-known API (e.g.
Point
) - Client - uses the component from a provider to build an Application, or another component (e.g.
App
).
- Provider - provides a component with a well-known API (e.g.
-
Unmanaged
<versus>
Managed - Static
<versus>
Dynamic link
- Building unmanaged components with static link:
- NOT a unit, but two parts instead: header + obj
- Need of a header file that describes the component content
- Different builds for different architectures
-
Structural modifications (new header)
=>
compilation + link -
Behavioral modifications
=>
link
- Demo with an unmanaged
App
using aPoint
. - Demo with a managed
App
using aPoint
.- Jitter (just-in-time compiler) - compiles IR to native code (e.g. x86, amd64, ppc) at runtime
-
Dynamic link -
Point.class
onApp
compilation + link at runtime. -
Lazy Load -
Point.class
is loaded only when needed
- Reflection object oriented API for metadata
- Java Reflection API (
java.lang.reflect
):Class
,Member
,Method
andField
.
-
KClass
is representing a type in Kotlin, whereasClass
is representing a type in JVM. -
KClass
--- .java --->
Class
-
Class
---- .kotlin --->
KClass
-
ClassLoader
andURLClassLoader
loadClass(): Class
-
Closeable
interface and Kotlin extensionuse()