Lecture 5 Flashcards
Java and Python difference in storing objects.
Java stores some values on the heap as objects.
Python stores everything.
Java and Python difference in values not stored on the heap.
Java stores them at bit-sequences.
Python does not do this.
Java and Python difference in Type information.
Java has type information specified in the program (at compile time).
Python stores type information in the object itself (at run time).
Numeric types, Java vs. Python.
Java: Bit sequences.
Python: Objects.
Integer range. Java vs. Python.
Java: Limited range.
Python: Not limited.
Types of integers. Java vs. Python.
Java: Multiple types.
Python: One type.
Types of floats. Java vs. Python.
Java: Multiple types.
Python: One type.
Float ranges. Java vs. Python.
Java: Different types, different ranges.
Python: One type, one limited range.
Numeric types in Java.
int
byte (8 bits)
short, a kind of int
long, a kind of int
double, double* precision float.
float
char, represents code units in Unicode
Usage advice of number types for CMPT270.
Int for counted quantities.
Double for measured.
Others for special purposes only. Don’t worry about them too much.
Note: Java’s numeric types are very similar to C/C++.
Java arithmetic operators.
Same as Python. +,-,*,/,%
int operated with int leads to int
float operated with float leads to float
mixed types operated on leads to implicit conversion to a floating point
% is restricted to integers only
Numeric expressions. Java vs. Python.
Java: Results in bit sequences that can be copied somewhere.
Python: Makes a new object.
Python’s way results in extra overhead and takes a bit longer.
Booleans in java.
boolean: true, false
char in Java.
Literals written with single quotes. Any single letter, number, keyboard symbol.
Strings in Java.
Any sequence of characters. 0 or more.
Written with double quotes.
Strings are a class*, not a primitive.