Class_1 Flashcards
How does a Java file execute?
1) Source code is WRITTEN in a .java file
2) Source code is COMPILED into a .class – Java Byte-code
3) Byte code executed just-in-time in an instance of JVM.
What is a Strongly Typed Language?
There are different data types, and each data types has specific behaviours.
For example, we can’t take the exponent of a string, but we can take the exponent of an integer.
What is a Statically Typed Language?
Once we’ve determined what data type a variable can hold, that variable CANNOT be assigned any other data type.
int aNumber = 3;
aNumber can ONLY contain integers.
What are the three ways Java can convert data?
1) Assignment
2) Promotion
3) Casting
What is ASSIGNMENT data conversion?
When a data type is stored in a wider data type – for example, from byte to integer – the narrower data type is automatically converted to the wider data type.
This will maintain magnitude but it can, in some instance, mean a loss of precision.
What is PROMOTION data conversion?
Occurs during an operation between two data types; the narrower data type will be automatically converted to a wider data type. For example, adding an integer to a double will result in a double.
What is CASTING data conversion?
When a programmer must explicitly cast a wider data type to a narrower data type. This requires the following syntax:
double number = 16.34;
int aNumber = (int) number / 6;
What are Java’s PRIMITIVE TYPES?
** boolean (N/A bytes / 1 bit)
** char (2 bytes / 16 bits)
Integers:
** byte (1 byte / 8 bits)
** short (2 bytes / 16 bits)
** int (4 bytes / 32 bits)
** long (8 bytes / 64 bits)
Decimals:
** float (4 bytes / 32 bits)
** double (8 bytes / 64 bits)
What is a HEAP?
The heap is where instantiated objects exist. They are pointed to by variables that exist in the stack.
What is the STACK?
The stack is where primitives live, which exist inside their variables, and where variables live that point to objects that exist in the heap. The stack is where a thread is executed, First In, Last Out (FILO).
What is a class?
A class is a blueprint that defines a type of object – its attributes, how its constructed, and its behaviours (methods). An object is an instantiation of a class.
What do we find in a .java file?
A .java file contains code for a single class. That class will contains these three things:
(1) The data it contains – its state, stored in variable.
(2) How to instantiate an object of the class type – the arguments we must pass into the constructor.
(3) The behaviours of the object – its methods
In Java, every class must have a main() method. What does the main method look like?
public static void main(String[] args) {}
What are the rules for creating variable names in Java?
- Variable names can include letters, numbers, underscores, and the $ sign.
- Variables names cannot start with a number.
What are the three main identifier types in Java?
- Class names must be TitleCase.
- variables and methods are camelCase.
- constants are ALL_CAPITALS_WITH_UNDERSCORES.