Anki Deck Changes

Commit: a213b3c8 - eprog instance of gotchas

Author: obrhubr <obrhubr@gmail.com>

Date: 2026-01-12T18:36:51+01:00

Changes: 12 note(s) changed (12 added, 0 modified, 0 deleted)

Note 1: ETH::EProg

Deck: ETH::EProg
Note Type: Horvath Cloze
GUID: Ap->IRX#;C
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::1._Instance_Of
If "obj = null" then "obj instanceof String" returns false (never an exception)

Back

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::1._Instance_Of
If "obj = null" then "obj instanceof String" returns false (never an exception)
Field-by-field Comparison
Field Before After
Text <div><code><span style="font-family: &quot;Liberation Sans&quot;;">If "</span>obj = null"</code> then "<code>obj instanceof String"</code> returns {{c1::false (never an exception)}}</div>
Tags: ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::1._Instance_Of

Note 2: ETH::EProg

Deck: ETH::EProg
Note Type: Horvath Cloze
GUID: D3~R~/O`**
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::1._Instance_Of
instanceof tests whether an instance has a same dynamic type or if it implements an interface.

Back

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::1._Instance_Of
instanceof tests whether an instance has a same dynamic type or if it implements an interface.
Field-by-field Comparison
Field Before After
Text <div><code>instanceof</code> tests whether {{c1::an instance has a same <b>dynamic type</b>}} or {{c1::if it implements an <b>interface</b>}}.</div>
Tags: ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::1._Instance_Of

Note 3: ETH::EProg

Deck: ETH::EProg
Note Type: Horvath Classic
GUID: G#$#7KW!b}
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::1._Instance_Of
Instance of can result in a Compile / Runtime / No error?

Back

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::1._Instance_Of
Instance of can result in a Compile / Runtime / No error?

instanceof never throws an exception, just compile errors.
Field-by-field Comparison
Field Before After
Front Instance of can result in a Compile / Runtime / No error?
Back <div><code>instanceof</code> never throws an exception, just <b>compile</b> errors.</div>
Tags: ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::1._Instance_Of

Note 4: ETH::EProg

Deck: ETH::EProg
Note Type: Horvath Classic
GUID: I0s;#,Wh%?
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::EProg::3._Control_Structures::4._Loops::1._For_Loops

Compile/Runtime/No Error

Back

ETH::1._Semester::EProg::3._Control_Structures::4._Loops::1._For_Loops

Compile/Runtime/No Error

No error, valid for loop.
Field-by-field Comparison
Field Before After
Front <img src="paste-f485e58a003acd0f29903efd63e9440b14068a5c.jpg"><br>Compile/Runtime/No Error
Back No error, valid for loop.
Tags: ETH::1._Semester::EProg::3._Control_Structures::4._Loops::1._For_Loops

Note 5: ETH::EProg

Deck: ETH::EProg
Note Type: Horvath Classic
GUID: IKMb!{98`
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::EProg::3._Control_Structures::4._Loops::1._For_Loops

Compile/Runtime/No Error?

Back

ETH::1._Semester::EProg::3._Control_Structures::4._Loops::1._For_Loops

Compile/Runtime/No Error?

Valid for loop.
Field-by-field Comparison
Field Before After
Front <img src="paste-e33a7d35e8694abacbdbd499304129858fb8fe03.jpg"><br>Compile/Runtime/No Error?
Back Valid for loop.
Tags: ETH::1._Semester::EProg::3._Control_Structures::4._Loops::1._For_Loops

Note 6: ETH::EProg

Deck: ETH::EProg
Note Type: Horvath Classic
GUID: LHfofYY0cF
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::EProg::2._First_Java_Programs::3._Simple_Calculations::2._Expressions_over_Basic_Types
Can we ust ++ and -- on floats and doubles?

Back

ETH::1._Semester::EProg::2._First_Java_Programs::3._Simple_Calculations::2._Expressions_over_Basic_Types
Can we ust ++ and -- on floats and doubles?

Yes, that is allowed and increments by 1.0.
Field-by-field Comparison
Field Before After
Front Can we ust <b>++</b>&nbsp;and&nbsp;<b>--</b>&nbsp;on floats and doubles?
Back Yes, that is allowed and increments by 1.0.
Tags: ETH::1._Semester::EProg::2._First_Java_Programs::3._Simple_Calculations::2._Expressions_over_Basic_Types

Note 7: ETH::EProg

Deck: ETH::EProg
Note Type: Horvath Cloze
GUID: MpWDjk%Tfz
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::1._Instance_Of
Instance of returns true if:
  • Implements the interface
  • Is of the same dynamic type
  • Is a subtype of the dynamic type

Back

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::1._Instance_Of
Instance of returns true if:
  • Implements the interface
  • Is of the same dynamic type
  • Is a subtype of the dynamic type
Field-by-field Comparison
Field Before After
Text Instance of returns true if:<br><ul><li>{{c1::Implements the interface}}</li><li>{{c2::Is of the same dynamic type}}</li><li>{{c3::Is a subtype of the dynamic type}}</li></ul>
Tags: ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::1._Instance_Of

Note 8: ETH::EProg

Deck: ETH::EProg
Note Type: Horvath Cloze
GUID: bxDOHVL#p]
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::1._Instance_Of
A compile error can result from an instance of check if:
  • Primitive types cannot be used with Instance Of
  • Cannot check for generics, type erasure prevents this.
        t instanceof List<String will not compile as it cannot check the parametrised type
  • Comparing siblings:
        Animal -> Dog and Animal -> Cat.
             Check for animal instanceof Dog/Cat allowed, but dog = new Dog(); dog instanceof Cat throws compile error.
  • Interface checks for final classes (that don't implement that interface).
             A final class cannot implement an interface in a subclass, thus error
             Animal a = getanimal() could get a Dog which
             might implement List thus a instanceof List is not a compile error.

Back

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::1._Instance_Of
A compile error can result from an instance of check if:
  • Primitive types cannot be used with Instance Of
  • Cannot check for generics, type erasure prevents this.
        t instanceof List<String will not compile as it cannot check the parametrised type
  • Comparing siblings:
        Animal -> Dog and Animal -> Cat.
             Check for animal instanceof Dog/Cat allowed, but dog = new Dog(); dog instanceof Cat throws compile error.
  • Interface checks for final classes (that don't implement that interface).
             A final class cannot implement an interface in a subclass, thus error
             Animal a = getanimal() could get a Dog which
             might implement List thus a instanceof List is not a compile error.
Field-by-field Comparison
Field Before After
Text A compile error can result from an <b>instance of&nbsp;</b>check if:<br><ul><li>{{c1::<i><b>Primitive</b></i> types cannot be used with Instance Of}}</li><li>{{c2::Cannot check for <b><em>generics</em></b>, type erasure prevents this.<br><code>&nbsp; &nbsp; t instanceof List&lt;String</code> will not compile as it cannot check the parametrised type}}</li><li>{{c3::Comparing <i><b>siblings</b></i>:<br><div><code>&nbsp; &nbsp; Animal -&gt; Dog</code> and <code>Animal -&gt; Cat</code>. <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Check for <code>animal instanceof Dog/Cat</code> allowed, but <code>dog = new Dog(); dog instanceof Cat</code> throws compile error.}}</div></li><li><div>{{c4::Interface checks for <i><code>final</code> classes</i>&nbsp;(that don't implement that interface).<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;A final class cannot implement an interface in a subclass, thus error<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<code>Animal a = getanimal()</code> could get a <code>Dog</code> which <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;might <code>implement List</code> thus <code>a instanceof List</code> is not a compile error.}}</div></li></ul>
Tags: ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::1._Instance_Of

Note 9: ETH::EProg

Deck: ETH::EProg
Note Type: Horvath Classic
GUID: fJL&tF*QW&
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::EProg::3._Control_Structures::4._Loops::1._For_Loops

Compile/Runtime/no Error

Back

ETH::1._Semester::EProg::3._Control_Structures::4._Loops::1._For_Loops

Compile/Runtime/no Error

No error, valid for loop
Field-by-field Comparison
Field Before After
Front <img src="paste-e0cbcc8d646d0785d63ce579c103d7fcfead5a58.jpg"><br>Compile/Runtime/no Error
Back No error, valid for loop
Tags: ETH::1._Semester::EProg::3._Control_Structures::4._Loops::1._For_Loops

Note 10: ETH::EProg

Deck: ETH::EProg
Note Type: Horvath Cloze
GUID: i2g|!nNV|m
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::EProg::3._Control_Structures::4._Loops::1._For_Loops
We can omit everything but the semicolons in the for loop for(...)

Back

ETH::1._Semester::EProg::3._Control_Structures::4._Loops::1._For_Loops
We can omit everything but the semicolons in the for loop for(...)
Field-by-field Comparison
Field Before After
Text We can omit everything but {{c1::the semicolons}} in the for loop <b>for(...)</b>
Tags: ETH::1._Semester::EProg::3._Control_Structures::4._Loops::1._For_Loops

Note 11: ETH::EProg

Deck: ETH::EProg
Note Type: Horvath Classic
GUID: osPOmm:i4.
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::EProg::3._Control_Structures::4._Loops::1._For_Loops

Compile/Runtime/No Error

Back

ETH::1._Semester::EProg::3._Control_Structures::4._Loops::1._For_Loops

Compile/Runtime/No Error

No error, valid for loop.
Field-by-field Comparison
Field Before After
Front <img src="paste-6451454cfb845d5c319df053e0bf4d13f446b8b5.jpg"><br>Compile/Runtime/No Error
Back No error, valid for loop.
Tags: ETH::1._Semester::EProg::3._Control_Structures::4._Loops::1._For_Loops

Note 12: ETH::EProg

Deck: ETH::EProg
Note Type: Horvath Classic
GUID: pycoxP)lJk
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::EProg::2._First_Java_Programs::3._Simple_Calculations::2._Expressions_over_Basic_Types
10 / -2 in Java gives the result or -5?

Back

ETH::1._Semester::EProg::2._First_Java_Programs::3._Simple_Calculations::2._Expressions_over_Basic_Types
10 / -2 in Java gives the result or -5?

-5 as integer division also supports negatives.
Field-by-field Comparison
Field Before After
Front <b>10 / -2</b>&nbsp;in Java gives the result&nbsp;<b>5&nbsp;</b>or&nbsp;<b>-5</b>?
Back <b>-5</b>&nbsp;as integer division also supports negatives.
Tags: ETH::1._Semester::EProg::2._First_Java_Programs::3._Simple_Calculations::2._Expressions_over_Basic_Types
↑ Top