-
Notifications
You must be signed in to change notification settings - Fork 48
Compile time vs Run time Summary
Compile-time | Run-time | |
---|---|---|
Type | Left hand side of the assignment, fixed upon declaration |
Right hand side of the assignment, vary as program runs |
Binding | Static | Dynamic |
Control | Restricts methods that can be called based on compile-time type | Methods to invoke are determined during run-time |
Check for | Method overloading, more specific method will be invoked |
Method overriding, overridden method will never be invoked |
What happens during Compilation Time in Java?
- Type Inference
- Inferring the type of a variable whose types are not defined.
- Type Erasure
- Replacing a type parameter of generics with either Object or its Bound.
What happens during Run Time in Java?
- Type Checking
- Checking if the value matches the type of the variable it is assigned to. It happens during run-time since the value is not always available at compile time.
- Late Binding
- Determines which instance method to call depending on the type of a reference object.
Exceptions
- Type Casting
- Converting the type of one variable to another.
-
Happens during Compile time but checked during run time.
- There are 2 types of casting: Widening Casting & Narrowing Casting
- Widening Casting: assigning a smaller data type to a larger relevant data type. eg: int -> float
jshell> int i = 10;
i ==> 10
jshell> float change = i;
change ==> 10.0
The above illustrates the implicit casting which differs from narrowing casting. There is no need to wrap () to change the type for objects.
- Narrowing Casting: [we saw this alot in class] Converts a bigger datatype to a smaller type. eg: equals method we witnessed in class
@Override
public boolean equals(Object obj){
if(this == obj){
return true;
}else if(obj instanceof Instructor){
Instructor n = (Instructor) obj;
return n.name.equals(this.name);
}else{
return false;
}
}
If you noticed, there is a line which says Instructor 'n = (Instructor) obj;'. When the equals method is taking in an Object, an Object is like the mother class. Instructor here is a smaller size type than Object so, in order to change the type of Instructor, manual casting is needed to cast the obj taken in into an Instructor class object.
- Accessibility Checking
- Checks if a class has access to a field in another class.
- Happens in both Compile and Run Time.
Peer Learning
Codecrunch Contributions
Piazza Contributions
Wiki Contributions
Guides
Setting Up Checkstyle
Setting Up Java
Setting Up MacVim
Setting Up Sunfire
Setting Up Unix For Mac
Setting Up Unix For Windows
Setting Up Vim
Setting up SSH Config
CS2030 Contents
Lecture 1 SummaryCompile-run vs Run-time Summary
Quick Guide To Abstraction
Generics and Variance of Types
Comparable vs Comparator
Summary of completable future
CS2030S Notes
ELI5 Optional.map vs Optional.flatMap
PECS Example Code
Java Collection Framework (Iterator)
Generic
Generic Type Parameter and Generic Wildcard
Calculator
Lambda-Expression
Single Abstract Method (SAM)
Method Reference
Functional Interfaces 2
Simple Usage of Sandbox
Associative-but-not-commutative
Higher Order function
Functional Programming
Calculator With Functor
Eager Evaluation VS Lazy Evaluation
Simple Usage of Lazy Evaluation
Lazy Evaluation for LazyList
Lazy Evaluation for BinaryTree
Stream
Parallel Stream
Optional
Simple Usage of Stream
Asynchronous Programming
Notes on CompletableFuture
Notes on CompletableFuture 2
Simple Usage of CompletableFuture
Mind Map
Exception Handling
Links
CS2030 Java Style Guide
CS2030 Javadoc Specification
JDK 11 Download Link
JDK 11 API Docs
Codecrunch
Piazza Forum