Primitive Data Types Flashcards
Double
8 bytes, 10^308 range
Float
4 bytes, 10^38 range
Long
8 bytes, 10^18 range
Short
2 bytes, 10^4 range
Char
2 bytes
Automatic conversion
automatic: small -> big
Type Cast
big range -> small range
Variables
location in memory that stores data
Condition
A question with 2 answers: true or false
Break
When executed, inner most loop that contains the break statement will be exited immediately
Continue
When executed, remainder of current iteration will be skipped
String
a data type that stores a sequence if characters. OBJECT type NOT data
StringBuilder
Another type to represent String info but is mutable (can be changed)
Pre-Increment/Decrement
++var (increments, then returns var)
Post-Decrement/Increment
var++ (returns var, increments)
Stack
Variables that are created in the main or other methods. References are on the stack
Heap
New objects
Parameters
Variables that are part of the function being called
Arguments
Values that are passed in when a function call happens
Stack Frames
- Created with each method call
- local variables and formal parameters are stored
- then destroyed after return
Overloading
If two methods have the same name, but different signatures. Compiler selects proper method when calling overloaded method.
Scope of Variables
The region in your code that you can use this variable. Defined by the block it is declared in.
- objects exist in the heap
- method calls go from one stack frame to another
- variables may have the same name but exist in different stack frames
- instance variables and local variables may have the same name
Function Call Tracing
When a function is called, a stack frame is created and for all local vars. When done, it is destroyed
Arrays
Objects that are dynamically created. May be assigned to variables of type Object. In the HEAP
Are Arrays Static?
Yes, they remain the same size once created
ArrayLists
Like StringBuilder, AL allow to grow and shrink their size.
They are designed to store references to Objects
Formatted File Input
Most Important Steps:
1. Know the format (data type and layout)
2. How the data will be used (what kind if variables will be used)
3. Create objects to read file
Object Oriented Programming (OOP)
Encapsulates into objects:
- data/state
- methods
Provide info hiding by separating implementation and interface
Implementation
Details hidden within the object
Private Instance Variables/Methods
Part of implementation
Interfaces
Allow objects to know how to communicate with one another
Public Methods and Constructors
Part of interface
Class
Unit of defining types
- encapsulates data (instance variables) and behaviors (methods)
- object instantiation (keyword NEW) and initialized by a constructor
- class name is a new type
Instance Variables
Variables defined outside a method/ctor but within the class definition
- usually PRIVATE
Class Variables
Variables defines using keyword STATIC (variable shared among all the objects that type
- public static class variables can be accessed by an object
Local Vars
defined in a method body
- CANNOT be public, probate, protected or static
Encapsulation
Data and methods
Inheritance
Keyword IMPLEMENTS (interface) and EXTENDS (implementation)
Polymorphism
Allows values if different data types to be handled using a uniform interface
Abstraction
Factoring out details so an object can be easily used without knowledge of how it works
Composition of classes
The idea if having one class be a data member or instance variable if another. HAS-A relationship
Superclass
Inherits attributes and behaviors of an existing class
Subclass
embellish these with new/different capabilities in a new class
Subclass and Superclass
Subclass object is a superclass object relationship NOT THE OTHER WAY AROUND
- HAS-A relationship
- superclass members become members of the subclass
Composition vs Inheritance
Inheritance:
- IS-A relationship
- create nee classes by extending
What to do in Subclass
- inherits all public and private members
- can replace, hide, or supplement them with new members (override)
This
Used in class to indicate that calling object reference
Super
Used in a class to indicate that we call the super object’s method
Public
- Accessed by an Java code
- Define public interface of the class
Private
- Only accessed when it occurs within the class
- instance vars
- often utility or helper methods
Protected
Access is permitted
1. from within the same package
2. Or within a subclass
Constructors
Methods that are called automatically to initialize instance vars for objects
- same name as class
- no return type
- never inherited, no hiding/overriding
- public, private, protected
Abstract Classes
- IS-A relationship
- Cannot create instances of objects of abstract classes