Week 1 Flashcards
What are the fundamentals of object oriented programming (OOP)?
- Encapsulation and information hiding
- Inheritance and polymorphism
- Decomposition and abstraction
- Dependency inversion
What does write once run everywhere refer to?
The java bytecode (.class) file that is generated from the JVM allows any operating system to run any .java file because the JVM accommodates for the OS when compiling the bytecode file.
What is a class in Java?
The fundamental programming unit of Java. It is a “blueprint” that defines a type, nothing in Java exists outside the class.
In general, what is contained in a class file?
- What data it contains (state stored in variables)
- How to instantiate it (parameters we must pass to the constructor)
- How we interact with it (public methods aka behaviours)
What makes an instance of a class unique?
The attributes in the objects fields at a given moment.
What are the different letter cases of class names, variables and methods, and constants?
Class names: TitleCase
Variables and methods: camelCase
Constants: UPPER_SNAKE_CASE
What does it mean when a programming language is “strongly typed”?
Strongly typed means every “thing” has a type and only certain actions can be performed on certain types.
What does it mean when a program is “statically typed”?
Statically typed means variables need their data type to be declared before assigning anything to it, it also only allows variables to refer/store things of a single data type.
What are the two mandatory components of declaring and initializing variables?
- Data type
- Identifier
What are local variables? When do we assign their values?
Variables that are inside methods. Local variables must be assigned compatible values before they are used.
What are instance variables? Where do we assign their values?
Variables that are inside a class but outside of methods. Instance variables must be assigned values inside the constructor.
What happens if instance variables are not assigned in the constructor?
They will assigned default values depending on their data type.
What are primitive data types in Java?
Primitives are a data type in Java that do not require an object in the heap to be created for them. They are stored wherever they are used.
What are some important properties of primitive data types?
- They can only store data in a specified range
- The size and nature of primitive data types are immutable over all platforms
Briefly described underflow and overflow.
Underflow occurs when you go out of bounds of the range from the smaller “end” and loop back around to the higher end of the range. Overflow is the exact opposite of underflow.
What are the 3 ways to convert data in Java?
- Assignment
- Promotion
- Casting
What keyword is used to instantiate a class?
new
What is the difference between identity and equality?
Identity refers to the address of an object while equality refers to the state of the object.
Where are interned strings stored?
String constant pool
What are the four “integer” primitives (from smallest to biggest)?
- byte
- short
- int
- long
What are the four primitive data types that aren’t “integers”?
- float
- double
- boolean
- char
What are the three ways data is converted in Java?
- Assignment
- Promotion
- Casting (most dangerous)
Why can precision potentially be lost when converting from a long to float? What does it mean for widening conversion to always preserve magnitude? Are widening conversion automatic?
Magnitude is preserved in widening because we are converting to a data type that allows for a larger range of numbers. Precision may be lost when converting from a long to a float because of the way floats are represented with a mantissa in computers, if the long is large enough some precision may be lost. Yes widening conversion are automatic.
Are narrowing conversion automatic? What can potentially be lost in narrowing conversions?
No, narrowing conversions are not automatic and both magnitude and precision may be lost.