-
Notifications
You must be signed in to change notification settings - Fork 0
lessons
Lessons:
- 23-02-2024 - Lesson 01 - Introduction and Modern VMs, e.g. JVM, Node
- 26-02-2024 - Lesson 02 - Types of Programming Languages. JVM Metadata, Classpath and Java Type System introduction
- 28-02-2024 - Lesson 03 - JVM programs distribution and running
23-02-2024 (G0.08)
- Bibliography and Lecturing methodology: github and slack.
- Tools:
javac
,javap
,kotlinc
, JDK 17 andgradle
. - Program outline in 3 parts:
- Java Type System and Reflection;
- Metaprogramming and Performance;
- 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
Lesson 02 - Types of Programming Languages. JVM Metadata, Classpath and Java Type System introduction
26-02-2024 (G0.08)
- 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
- Compilation -> Transalation in compile time.
- The need for Virtual Machines
- Reduce the number of needed compilers
- Code portability
- 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 :)
- e.g.
- 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
-
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 -classpath ./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.
12-03-2024 (E1.09)
- Static initializer: initializes static fields.
- Boxing and Unboxing.
- Interfaces represent abstract types that cannot be instantiated too.
- Abstract classes cannot be directly instantiated.
- Nested classes.
- Inner classes: non-static in Java or inner in Kotlin.
- Override
- Names collision and Member access ambiguity
- Methods call resolution
- Anonymous classes.
- 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:
- Java: always includes a field
this$0
to the outer class (i.e. inner) - Kotlin: only includes a field
this$0
if it uses the outer class scope.
- Java: always includes a field